cyclic-nodes-through-fanout-map.ts 1.3 KB

1234567891011121314151617181920212223
  1. // Cyclic linked-list nodes iterated by .map; the callback writes a tainted field and
  2. // asks. Exercises cycle-safety THROUGH a promoted fan-out (distinct from circular-ref,
  3. // which never iterates the cycle). Must terminate and emit the fan-out + all edges.
  4. // Note: the callback mutates the iterated element (`n.f = secret`), and the element-
  5. // mutation write-back merges that field into the `nodes` collection place. Since the
  6. // fan-out INPUT is collapse(nodes), secret reaches it — so the fan-out gains a real
  7. // `ask#1 -> fan-out#1` data edge, which DISPLACES the synthetic `source -> fan-out#1`
  8. // graph-completion edge (source→X is auto-added only when X has no incoming data edge).
  9. // source still reaches the fan-out transitively (source -> ask#1 -> fan-out#1); no
  10. // connectivity or soundness is lost. Restricting write-back away from .map would reopen a
  11. // real soundness hole (a map that mutates then re-reads the source array).
  12. type N = { next?: N; f?: string };
  13. const n1: N = {};
  14. const n2: N = {};
  15. n1.next = n2;
  16. n2.next = n1;
  17. const nodes: N[] = [n1, n2];
  18. const secret = await agent("writer").ask<string>("secret");
  19. const outs = nodes.map((n) => {
  20. n.f = secret;
  21. return agent("judge").ask<string>(`check ${n.f}`);
  22. });
  23. return (await Promise.all(outs)).join();