Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugins/goal-guard/guard.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ export function createGuard(input = {}, options = {}, overrides = {}) {
/* ignore corrupt state */
}

// Opportunistically prune orphaned snapshot files left by worktrees that no
// longer run (issue #218): without this the persistence dir grows forever.
// Best-effort — a cleanup failure must never break guard startup, and the
// optional call keeps injected test doubles (which omit cleanup) working.
try {
persistence.cleanup?.();
} catch {
/* best-effort */
}

// Persist the resolved config alongside the sessions so the TUI sidebar (which reads
// only the on-disk snapshot) evaluates completion with the SAME config the server
// used — otherwise a non-default `contextualGates` would make the sidebar disagree
Expand Down
12 changes: 12 additions & 0 deletions tests/integration.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ function makeGuard(options = {}) {
);
}

test("integration: guard startup prunes orphaned persistence files (#218 wiring)", () => {
let cleaned = 0;
const persistence = { ...noopPersistence, cleanup: () => { cleaned += 1; } };
let t = 0;
createGuard(
{ client: { app: { log: async () => undefined }, tui: { showToast: async () => undefined } } },
{},
{ persistence, clock: () => (t += 1), syncIdle: true },
);
assert.equal(cleaned, 1, "createGuard must invoke persistence.cleanup() once at startup");
});

/**
* End-to-end simulation of a realistic goal lifecycle driven entirely through
* the plugin hooks, asserting the guard blocks completion until the full
Expand Down
Loading