Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

test: make presence expiry controls deterministic

haelyra33372e99703e
diff --git a/tests/scripts/plan-canvas.test.js b/tests/scripts/plan-canvas.test.js
index 1ee9036a2..c214ee150 100644
--- a/tests/scripts/plan-canvas.test.js
+++ b/tests/scripts/plan-canvas.test.js
@@ -1267,20 +1267,33 @@ async function main(suite = createTestRunner()) {
const bound = await staleCanvas.listen(0);
const opened = jsonBody(await request(bound.port, 'POST', '/api/sessions', { body: { file: staleArtifact } }));
- await request(bound.port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'typing' } });
- assert.strictEqual(staleCanvas.presenceFor(opened.key), 'typing');
- await new Promise(resolve => setTimeout(resolve, 60));
- assert.strictEqual(staleCanvas.presenceFor(opened.key), 'waiting');
-
- // An abandoned agent decays to queued so the human is never told a
- // stalled session is still being worked on.
- await request(bound.port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'thinking' } });
- await request(bound.port, 'POST', `/api/session/${opened.key}/feedback`, {
- body: { items: [{ kind: 'chat', text: 'still there?' }] }
- });
- assert.strictEqual(staleCanvas.presenceFor(opened.key), 'thinking');
- await new Promise(resolve => setTimeout(resolve, 60));
- assert.strictEqual(staleCanvas.presenceFor(opened.key), 'queued');
+ // Keep real HTTP transitions, but advance their activity clock explicitly:
+ // loaded runners can exceed the expiry between two HTTP round trips.
+ const originalNow = Date.now;
+ let now = originalNow();
+ Date.now = () => now;
+ try {
+ await request(bound.port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'typing' } });
+ assert.strictEqual(staleCanvas.presenceFor(opened.key), 'typing');
+ now += 19;
+ assert.strictEqual(staleCanvas.presenceFor(opened.key), 'typing');
+ now += 1;
+ assert.strictEqual(staleCanvas.presenceFor(opened.key), 'waiting');
+
+ // An abandoned agent decays to queued so the human is never told a
+ // stalled session is still being worked on.
+ await request(bound.port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'thinking' } });
+ await request(bound.port, 'POST', `/api/session/${opened.key}/feedback`, {
+ body: { items: [{ kind: 'chat', text: 'still there?' }] }
+ });
+ assert.strictEqual(staleCanvas.presenceFor(opened.key), 'thinking');
+ now += 39;
+ assert.strictEqual(staleCanvas.presenceFor(opened.key), 'thinking');
+ now += 1;
+ assert.strictEqual(staleCanvas.presenceFor(opened.key), 'queued');
+ } finally {
+ Date.now = originalNow;
+ }
await closeStaleCanvas();
});