Something went wrong. Try again.
watches turns and automatically creates and resolves tasks that get pinned into main agent context
Something went wrong. Try again.
1.7 kB · 50 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import assert from "node:assert/strict";import test from "node:test";import { buildContextBlock, CLEARED_CONTEXT, nextContextRevision, REFRESHING_CONTEXT,} from "../src/inject.ts";import { replay } from "../src/state.ts";
const open = replay([ { kind: "observation", reconciled: [], output: { existing: [], additions: [{ canonicalRequest: "finish the report", status: "active" }] }, at: 1, },]);const done = replay([ { kind: "observation", reconciled: [], output: { existing: [], additions: [{ canonicalRequest: "finish the report", status: "active" }] }, at: 1, }, { kind: "user_action", threadId: "t1", action: "accept", at: 2 },]);
test("internal wakes never inject pending-request context", () => { assert.equal(nextContextRevision("internal", open, undefined), undefined);});
test("user turns inject only changed pending-request state", () => { const first = nextContextRevision("interactive", open, undefined)!; assert.match(first, /finish the report/); assert.equal(first, buildContextBlock(open)); assert.equal(nextContextRevision("rpc", open, first), undefined);});
test("a pending reconciliation invalidates stale context without blocking", () => { const previous = buildContextBlock(open)!; assert.equal(nextContextRevision("interactive", open, previous, true), REFRESHING_CONTEXT); assert.equal(nextContextRevision("interactive", open, REFRESHING_CONTEXT, true), undefined);});
test("closing the final request emits one clear revision", () => { const previous = buildContextBlock(open)!; assert.equal(nextContextRevision("interactive", done, previous), CLEARED_CONTEXT); assert.equal(nextContextRevision("interactive", done, CLEARED_CONTEXT), undefined);});