Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: lock the throwaway-worktree safety guarantee for reasoning agents

[._.]/ Adam Eivya8b592b037e7
diff --git a/server/services/cleanupAgentWorktree.test.js b/server/services/cleanupAgentWorktree.test.js
index 89d365a8ec..0a1d892334 100644
--- a/server/services/cleanupAgentWorktree.test.js
+++ b/server/services/cleanupAgentWorktree.test.js
@@ -836,3 +836,55 @@ describe('spawnMergeRecoveryTask', () => {
expect(call.context).not.toContain('gh pr ');
});
});
+
+// The throwaway-worktree posture (programmatic-I/O reasoning agents, e.g.
+// layered-intelligence) is the "reasoner can't land code" safety guarantee:
+// the worktree is discarded with NO merge and NO PR even when openPR is set, so
+// a reasoning agent that touched code can never push it. Derived inside the sink
+// from originalTask.metadata.discardWorktree. These lock the behavior, not just
+// the config default (taskSchedule.test.js pins the default).
+describe('cleanupAgentWorktree - discardWorktree (throwaway reasoning worktree)', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ getAgent.mockResolvedValue(mockWorktreeAgent());
+ git.getRepoBranches.mockResolvedValue({ baseBranch: 'main', devBranch: null });
+ });
+
+ it('removes the worktree with merge:false and never pushes/opens a PR — even with openPR:true', async () => {
+ await cleanupAgentWorktree('agent-1', true, {
+ openPR: true,
+ originalTask: { metadata: { discardWorktree: true } }
+ });
+
+ expect(removeWorktree).toHaveBeenCalledTimes(1);
+ expect(removeWorktree).toHaveBeenCalledWith('agent-1', '/mock/workspace', 'cos/task-abc123', { merge: false });
+ // Discard wins over openPR — no code is ever pushed or PR'd.
+ expect(git.push).not.toHaveBeenCalled();
+ expect(git.createPR).not.toHaveBeenCalled();
+ });
+
+ it('treats the re-parsed string "true" as discard (metadata round-trips through the task store)', async () => {
+ await cleanupAgentWorktree('agent-1', true, {
+ openPR: true,
+ originalTask: { metadata: { discardWorktree: 'true' } }
+ });
+
+ expect(removeWorktree).toHaveBeenCalledWith('agent-1', '/mock/workspace', 'cos/task-abc123', { merge: false });
+ expect(git.push).not.toHaveBeenCalled();
+ expect(git.createPR).not.toHaveBeenCalled();
+ });
+
+ it('does NOT discard when the flag is absent — the normal openPR path still runs', async () => {
+ git.push.mockResolvedValue(undefined);
+ git.createPR.mockResolvedValue({ success: true, url: 'https://github.com/test/repo/pull/9' });
+
+ await cleanupAgentWorktree('agent-1', true, {
+ openPR: true,
+ originalTask: { metadata: {} }
+ });
+
+ // No discard → the standard openPR flow pushes + creates a PR.
+ expect(git.push).toHaveBeenCalled();
+ expect(git.createPR).toHaveBeenCalled();
+ });
+});