patchwarden 0.6.4 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +54 -20
- package/README.md +48 -21
- package/dist/agents/agentRouter.d.ts +40 -0
- package/dist/agents/agentRouter.js +95 -0
- package/dist/config.d.ts +1 -1
- package/dist/config.js +6 -2
- package/dist/controlCenter.js +212 -3
- package/dist/direct/directSessionStore.d.ts +2 -0
- package/dist/direct/directVerification.js +7 -0
- package/dist/doctor.js +32 -1
- package/dist/goal/acceptanceEngine.d.ts +62 -0
- package/dist/goal/acceptanceEngine.js +103 -0
- package/dist/goal/acceptanceTemplate.d.ts +10 -0
- package/dist/goal/acceptanceTemplate.js +104 -0
- package/dist/goal/goalGraph.d.ts +58 -0
- package/dist/goal/goalGraph.js +189 -0
- package/dist/goal/goalProgress.d.ts +81 -0
- package/dist/goal/goalProgress.js +216 -0
- package/dist/goal/goalStatus.d.ts +60 -0
- package/dist/goal/goalStatus.js +137 -0
- package/dist/goal/goalStore.d.ts +79 -0
- package/dist/goal/goalStore.js +211 -0
- package/dist/goal/handoffExport.d.ts +34 -0
- package/dist/goal/handoffExport.js +183 -0
- package/dist/goal/subgoalSync.d.ts +40 -0
- package/dist/goal/subgoalSync.js +72 -0
- package/dist/goal/worktreeManager.d.ts +96 -0
- package/dist/goal/worktreeManager.js +292 -0
- package/dist/logging.d.ts +44 -0
- package/dist/logging.js +68 -0
- package/dist/policy/projectPolicy.d.ts +55 -0
- package/dist/policy/projectPolicy.js +286 -0
- package/dist/release/releaseGate.d.ts +99 -0
- package/dist/release/releaseGate.js +475 -0
- package/dist/runner/postTaskCleanup.d.ts +13 -0
- package/dist/runner/postTaskCleanup.js +147 -0
- package/dist/runner/runTask.js +50 -10
- package/dist/security/discoveryTokenStore.d.ts +62 -0
- package/dist/security/discoveryTokenStore.js +100 -0
- package/dist/security/toolInvocationGuard.d.ts +35 -0
- package/dist/security/toolInvocationGuard.js +153 -0
- package/dist/smoke-test.js +18 -10
- package/dist/taskRuntime.d.ts +17 -0
- package/dist/test/unit/acceptance-engine.test.d.ts +1 -0
- package/dist/test/unit/acceptance-engine.test.js +228 -0
- package/dist/test/unit/agent-router.test.d.ts +1 -0
- package/dist/test/unit/agent-router.test.js +287 -0
- package/dist/test/unit/audit-checks.test.d.ts +1 -0
- package/dist/test/unit/audit-checks.test.js +350 -0
- package/dist/test/unit/diagnose-task.test.d.ts +1 -0
- package/dist/test/unit/diagnose-task.test.js +457 -0
- package/dist/test/unit/discovery-token-store.test.d.ts +1 -0
- package/dist/test/unit/discovery-token-store.test.js +139 -0
- package/dist/test/unit/evidence-pack.test.d.ts +1 -0
- package/dist/test/unit/evidence-pack.test.js +130 -0
- package/dist/test/unit/goal-graph.test.d.ts +1 -0
- package/dist/test/unit/goal-graph.test.js +298 -0
- package/dist/test/unit/goal-progress.test.d.ts +1 -0
- package/dist/test/unit/goal-progress.test.js +381 -0
- package/dist/test/unit/goal-status.test.d.ts +1 -0
- package/dist/test/unit/goal-status.test.js +215 -0
- package/dist/test/unit/goal-store.test.d.ts +1 -0
- package/dist/test/unit/goal-store.test.js +253 -0
- package/dist/test/unit/goal-subgoal-task.test.d.ts +1 -0
- package/dist/test/unit/goal-subgoal-task.test.js +55 -0
- package/dist/test/unit/goal-tools-registry.test.d.ts +1 -0
- package/dist/test/unit/goal-tools-registry.test.js +190 -0
- package/dist/test/unit/handoff-export.test.d.ts +1 -0
- package/dist/test/unit/handoff-export.test.js +263 -0
- package/dist/test/unit/invoke-discovered-tool.test.d.ts +1 -0
- package/dist/test/unit/invoke-discovered-tool.test.js +167 -0
- package/dist/test/unit/logging.test.js +127 -5
- package/dist/test/unit/post-task-cleanup.test.d.ts +1 -0
- package/dist/test/unit/post-task-cleanup.test.js +48 -0
- package/dist/test/unit/project-policy-release-mode.test.d.ts +1 -0
- package/dist/test/unit/project-policy-release-mode.test.js +125 -0
- package/dist/test/unit/reconcile-tasks.test.d.ts +1 -0
- package/dist/test/unit/reconcile-tasks.test.js +456 -0
- package/dist/test/unit/release-gate.test.d.ts +1 -0
- package/dist/test/unit/release-gate.test.js +242 -0
- package/dist/test/unit/run-task-loop.test.d.ts +1 -0
- package/dist/test/unit/run-task-loop.test.js +380 -0
- package/dist/test/unit/safe-views.test.d.ts +1 -0
- package/dist/test/unit/safe-views.test.js +171 -0
- package/dist/test/unit/schema-drift-check.test.d.ts +1 -0
- package/dist/test/unit/schema-drift-check.test.js +176 -0
- package/dist/test/unit/subgoal-sync.test.d.ts +1 -0
- package/dist/test/unit/subgoal-sync.test.js +183 -0
- package/dist/test/unit/tool-invocation-guard.test.d.ts +1 -0
- package/dist/test/unit/tool-invocation-guard.test.js +432 -0
- package/dist/test/unit/tool-usage-stats.test.d.ts +1 -0
- package/dist/test/unit/tool-usage-stats.test.js +300 -0
- package/dist/test/unit/toolSearch.test.d.ts +1 -0
- package/dist/test/unit/toolSearch.test.js +571 -0
- package/dist/test/unit/worktree-manager.test.d.ts +1 -0
- package/dist/test/unit/worktree-manager.test.js +176 -0
- package/dist/tools/auditTask.d.ts +103 -1
- package/dist/tools/auditTask.js +461 -8
- package/dist/tools/cancelTask.js +1 -1
- package/dist/tools/checkReleaseGate.d.ts +21 -0
- package/dist/tools/checkReleaseGate.js +22 -0
- package/dist/tools/createTask.d.ts +18 -2
- package/dist/tools/createTask.js +29 -1
- package/dist/tools/diagnoseTask.d.ts +45 -0
- package/dist/tools/diagnoseTask.js +347 -0
- package/dist/tools/discardWorktree.d.ts +24 -0
- package/dist/tools/discardWorktree.js +27 -0
- package/dist/tools/discoverTools.d.ts +11 -0
- package/dist/tools/discoverTools.js +39 -0
- package/dist/tools/evidencePack.d.ts +39 -0
- package/dist/tools/evidencePack.js +168 -0
- package/dist/tools/explainTool.d.ts +11 -0
- package/dist/tools/explainTool.js +21 -0
- package/dist/tools/getTaskSummary.js +2 -1
- package/dist/tools/goalSubgoalTask.d.ts +51 -0
- package/dist/tools/goalSubgoalTask.js +110 -0
- package/dist/tools/healthCheck.d.ts +1 -0
- package/dist/tools/healthCheck.js +5 -1
- package/dist/tools/invokeDiscoveredTool.d.ts +37 -0
- package/dist/tools/invokeDiscoveredTool.js +112 -0
- package/dist/tools/listTasks.d.ts +3 -1
- package/dist/tools/listTasks.js +14 -1
- package/dist/tools/mergeWorktree.d.ts +24 -0
- package/dist/tools/mergeWorktree.js +27 -0
- package/dist/tools/recommendAgentForTask.d.ts +19 -0
- package/dist/tools/recommendAgentForTask.js +56 -0
- package/dist/tools/reconcileTasks.d.ts +41 -0
- package/dist/tools/reconcileTasks.js +352 -0
- package/dist/tools/registry.js +926 -2
- package/dist/tools/releaseMode.d.ts +50 -0
- package/dist/tools/releaseMode.js +370 -0
- package/dist/tools/runDirectVerificationBundle.d.ts +26 -0
- package/dist/tools/runDirectVerificationBundle.js +64 -0
- package/dist/tools/runTaskLoop.d.ts +57 -0
- package/dist/tools/runTaskLoop.js +417 -0
- package/dist/tools/runVerification.d.ts +4 -0
- package/dist/tools/runVerification.js +4 -0
- package/dist/tools/safeStatus.d.ts +31 -1
- package/dist/tools/safeStatus.js +43 -1
- package/dist/tools/safeViews.d.ts +262 -0
- package/dist/tools/safeViews.js +252 -0
- package/dist/tools/schemaDriftCheck.d.ts +46 -0
- package/dist/tools/schemaDriftCheck.js +80 -0
- package/dist/tools/taskLineage.d.ts +91 -0
- package/dist/tools/taskLineage.js +175 -0
- package/dist/tools/toolCatalog.d.ts +4 -3
- package/dist/tools/toolCatalog.js +39 -11
- package/dist/tools/toolRegistry.d.ts +61 -0
- package/dist/tools/toolRegistry.js +834 -0
- package/dist/tools/toolSearch.d.ts +110 -0
- package/dist/tools/toolSearch.js +331 -0
- package/dist/tools/toolUsageStats.d.ts +41 -0
- package/dist/tools/toolUsageStats.js +116 -0
- package/dist/tools/waitForTask.js +1 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/dist/watcherStatus.d.ts +29 -0
- package/dist/watcherStatus.js +92 -1
- package/docs/chatgpt-usage.md +31 -0
- package/docs/control-center/README.md +9 -0
- package/package.json +3 -2
- package/scripts/checks/control-center-smoke.js +87 -0
- package/scripts/checks/control-smoke.js +2 -2
- package/scripts/checks/doctor-smoke.js +1 -0
- package/scripts/checks/lifecycle-smoke.js +13 -9
- package/scripts/checks/mcp-manifest-check.js +65 -6
- package/scripts/checks/mcp-smoke.js +60 -9
- package/scripts/checks/watcher-supervisor-smoke.js +2 -2
- package/src/agents/agentRouter.ts +149 -0
- package/src/config.ts +9 -3
- package/src/controlCenter.ts +215 -4
- package/src/direct/directSessionStore.ts +2 -0
- package/src/direct/directVerification.ts +7 -0
- package/src/doctor.ts +36 -1
- package/src/goal/acceptanceEngine.ts +160 -0
- package/src/goal/acceptanceTemplate.ts +121 -0
- package/src/goal/goalGraph.ts +225 -0
- package/src/goal/goalProgress.ts +301 -0
- package/src/goal/goalStatus.ts +234 -0
- package/src/goal/goalStore.ts +306 -0
- package/src/goal/handoffExport.ts +211 -0
- package/src/goal/subgoalSync.ts +82 -0
- package/src/goal/worktreeManager.ts +404 -0
- package/src/logging.ts +91 -0
- package/src/policy/projectPolicy.ts +344 -0
- package/src/release/releaseGate.ts +567 -0
- package/src/runner/postTaskCleanup.ts +154 -0
- package/src/runner/runTask.ts +49 -10
- package/src/security/discoveryTokenStore.ts +157 -0
- package/src/security/toolInvocationGuard.ts +251 -0
- package/src/smoke-test.ts +15 -7
- package/src/taskRuntime.ts +17 -0
- package/src/test/unit/acceptance-engine.test.ts +261 -0
- package/src/test/unit/agent-router.test.ts +342 -0
- package/src/test/unit/audit-checks.test.ts +567 -0
- package/src/test/unit/diagnose-task.test.ts +544 -0
- package/src/test/unit/discovery-token-store.test.ts +181 -0
- package/src/test/unit/evidence-pack.test.ts +142 -0
- package/src/test/unit/goal-graph.test.ts +347 -0
- package/src/test/unit/goal-progress.test.ts +538 -0
- package/src/test/unit/goal-status.test.ts +270 -0
- package/src/test/unit/goal-store.test.ts +318 -0
- package/src/test/unit/goal-subgoal-task.test.ts +72 -0
- package/src/test/unit/goal-tools-registry.test.ts +243 -0
- package/src/test/unit/handoff-export.test.ts +295 -0
- package/src/test/unit/invoke-discovered-tool.test.ts +216 -0
- package/src/test/unit/logging.test.ts +177 -5
- package/src/test/unit/post-task-cleanup.test.ts +53 -0
- package/src/test/unit/project-policy-release-mode.test.ts +156 -0
- package/src/test/unit/reconcile-tasks.test.ts +551 -0
- package/src/test/unit/release-gate.test.ts +314 -0
- package/src/test/unit/run-task-loop.test.ts +425 -0
- package/src/test/unit/safe-views.test.ts +184 -0
- package/src/test/unit/schema-drift-check.test.ts +260 -0
- package/src/test/unit/subgoal-sync.test.ts +236 -0
- package/src/test/unit/tool-invocation-guard.test.ts +542 -0
- package/src/test/unit/tool-usage-stats.test.ts +384 -0
- package/src/test/unit/toolSearch.test.ts +756 -0
- package/src/test/unit/worktree-manager.test.ts +247 -0
- package/src/tools/auditTask.ts +831 -402
- package/src/tools/cancelTask.ts +1 -1
- package/src/tools/checkReleaseGate.ts +45 -0
- package/src/tools/createTask.ts +64 -6
- package/src/tools/diagnoseTask.ts +460 -0
- package/src/tools/discardWorktree.ts +42 -0
- package/src/tools/discoverTools.ts +51 -0
- package/src/tools/evidencePack.ts +205 -0
- package/src/tools/explainTool.ts +26 -0
- package/src/tools/getTaskSummary.ts +2 -1
- package/src/tools/goalSubgoalTask.ts +170 -0
- package/src/tools/healthCheck.ts +4 -1
- package/src/tools/invokeDiscoveredTool.ts +163 -0
- package/src/tools/listTasks.ts +16 -2
- package/src/tools/listWorkspace.ts +71 -71
- package/src/tools/mergeWorktree.ts +42 -0
- package/src/tools/recommendAgentForTask.ts +79 -0
- package/src/tools/reconcileTasks.ts +464 -0
- package/src/tools/registry.ts +1093 -73
- package/src/tools/releaseMode.ts +450 -0
- package/src/tools/runDirectVerificationBundle.ts +98 -0
- package/src/tools/runTaskLoop.ts +526 -0
- package/src/tools/runVerification.ts +8 -0
- package/src/tools/safeStatus.ts +73 -2
- package/src/tools/safeViews.ts +273 -0
- package/src/tools/schemaDriftCheck.ts +120 -0
- package/src/tools/taskLineage.ts +300 -0
- package/src/tools/toolCatalog.ts +40 -11
- package/src/tools/toolRegistry.ts +896 -0
- package/src/tools/toolSearch.ts +464 -0
- package/src/tools/toolUsageStats.ts +151 -0
- package/src/tools/waitForTask.ts +1 -0
- package/src/version.ts +2 -2
- package/src/watcherStatus.ts +97 -1
- package/ui/pages/dashboard.html +143 -2
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { describe, it } from "node:test";
|
|
2
|
+
import { strict as assert } from "node:assert";
|
|
3
|
+
import { runReleaseGateCheck, checkPublishedVerified, checkGitHubReleaseVerified, checkCiVerified, computeTokenDigest, } from "../../release/releaseGate.js";
|
|
4
|
+
// ── Mock helpers ───────────────────────────────────────────────────
|
|
5
|
+
/**
|
|
6
|
+
* Build a mock httpGet that responds based on the URL.
|
|
7
|
+
* Each responder returns an HttpResponse synchronously (wrapped in a Promise).
|
|
8
|
+
*/
|
|
9
|
+
function mockHttpGet(responder) {
|
|
10
|
+
return async (url) => responder(url);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Build a mock httpGet that captures headers (for token-leak assertions).
|
|
14
|
+
*/
|
|
15
|
+
function mockHttpGetCapture(responder, capture) {
|
|
16
|
+
return async (url, headers) => {
|
|
17
|
+
capture.headers = { ...(headers || {}) };
|
|
18
|
+
return responder(url);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build a mock httpGet that always throws (simulates network error).
|
|
23
|
+
*/
|
|
24
|
+
function mockHttpGetError(error) {
|
|
25
|
+
return async () => {
|
|
26
|
+
throw error;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// ── 1. checkPublishedVerified ──────────────────────────────────────
|
|
30
|
+
describe("checkPublishedVerified", () => {
|
|
31
|
+
it("version exists → passed", async () => {
|
|
32
|
+
const httpGet = mockHttpGet(() => ({
|
|
33
|
+
statusCode: 200,
|
|
34
|
+
data: { versions: { "1.0.0": {}, "0.9.0": {} } },
|
|
35
|
+
}));
|
|
36
|
+
const result = await checkPublishedVerified("patchwarden", "1.0.0", httpGet);
|
|
37
|
+
assert.equal(result.status, "passed");
|
|
38
|
+
});
|
|
39
|
+
it("version does not exist → failed", async () => {
|
|
40
|
+
const httpGet = mockHttpGet(() => ({
|
|
41
|
+
statusCode: 200,
|
|
42
|
+
data: { versions: { "0.9.0": {} } },
|
|
43
|
+
}));
|
|
44
|
+
const result = await checkPublishedVerified("patchwarden", "9.9.9", httpGet);
|
|
45
|
+
assert.equal(result.status, "failed");
|
|
46
|
+
assert.ok(result.reason?.includes("9.9.9"));
|
|
47
|
+
});
|
|
48
|
+
it("network error → not_checked", async () => {
|
|
49
|
+
const httpGet = mockHttpGetError(new Error("connect ECONNREFUSED"));
|
|
50
|
+
const result = await checkPublishedVerified("patchwarden", "1.0.0", httpGet);
|
|
51
|
+
assert.equal(result.status, "not_checked");
|
|
52
|
+
assert.ok(result.reason?.includes("Network error"));
|
|
53
|
+
});
|
|
54
|
+
it("package 404 → failed", async () => {
|
|
55
|
+
const httpGet = mockHttpGet(() => ({
|
|
56
|
+
statusCode: 404,
|
|
57
|
+
data: { error: "Not found" },
|
|
58
|
+
}));
|
|
59
|
+
const result = await checkPublishedVerified("nonexistent-pkg", "1.0.0", httpGet);
|
|
60
|
+
assert.equal(result.status, "failed");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
// ── 2. checkGitHubReleaseVerified ──────────────────────────────────
|
|
64
|
+
describe("checkGitHubReleaseVerified", () => {
|
|
65
|
+
it("200 → passed", async () => {
|
|
66
|
+
const httpGet = mockHttpGet(() => ({
|
|
67
|
+
statusCode: 200,
|
|
68
|
+
data: { tag_name: "v1.0.0" },
|
|
69
|
+
}));
|
|
70
|
+
const result = await checkGitHubReleaseVerified("user/repo", "v1.0.0", httpGet);
|
|
71
|
+
assert.equal(result.status, "passed");
|
|
72
|
+
});
|
|
73
|
+
it("404 → failed", async () => {
|
|
74
|
+
const httpGet = mockHttpGet(() => ({
|
|
75
|
+
statusCode: 404,
|
|
76
|
+
data: { message: "Not Found" },
|
|
77
|
+
}));
|
|
78
|
+
const result = await checkGitHubReleaseVerified("user/repo", "v1.0.0", httpGet);
|
|
79
|
+
assert.equal(result.status, "failed");
|
|
80
|
+
assert.ok(result.reason?.includes("v1.0.0"));
|
|
81
|
+
});
|
|
82
|
+
it("network error → not_checked", async () => {
|
|
83
|
+
const httpGet = mockHttpGetError(new Error("connect ETIMEDOUT"));
|
|
84
|
+
const result = await checkGitHubReleaseVerified("user/repo", "v1.0.0", httpGet);
|
|
85
|
+
assert.equal(result.status, "not_checked");
|
|
86
|
+
});
|
|
87
|
+
it("token is used as Bearer but never appears in result", async () => {
|
|
88
|
+
const TOKEN = "test-token";
|
|
89
|
+
process.env.GITHUB_TOKEN = TOKEN;
|
|
90
|
+
const capture = {};
|
|
91
|
+
const httpGet = mockHttpGetCapture(() => ({ statusCode: 200, data: { tag_name: "v1.0.0" } }), capture);
|
|
92
|
+
try {
|
|
93
|
+
const result = await checkGitHubReleaseVerified("user/repo", "v1.0.0", httpGet);
|
|
94
|
+
assert.equal(result.status, "passed");
|
|
95
|
+
// Authorization header was set correctly (token used internally)
|
|
96
|
+
assert.equal(capture.headers?.["Authorization"], `Bearer ${TOKEN}`);
|
|
97
|
+
// Raw token must NOT appear anywhere in the serialized result
|
|
98
|
+
const resultStr = JSON.stringify(result);
|
|
99
|
+
assert.ok(!resultStr.includes(TOKEN), "raw GITHUB_TOKEN must not leak into the result object");
|
|
100
|
+
// The token digest is different from the raw token
|
|
101
|
+
const digest = computeTokenDigest(TOKEN);
|
|
102
|
+
assert.ok(digest !== TOKEN, "digest must differ from raw token");
|
|
103
|
+
assert.ok(digest.startsWith("sha256:"));
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
delete process.env.GITHUB_TOKEN;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
// ── 3. checkCiVerified ─────────────────────────────────────────────
|
|
111
|
+
describe("checkCiVerified", () => {
|
|
112
|
+
it("conclusion=success → passed", async () => {
|
|
113
|
+
const httpGet = mockHttpGet(() => ({
|
|
114
|
+
statusCode: 200,
|
|
115
|
+
data: { workflow_runs: [{ conclusion: "success" }] },
|
|
116
|
+
}));
|
|
117
|
+
const result = await checkCiVerified("user/repo", "main", httpGet);
|
|
118
|
+
assert.equal(result.status, "passed");
|
|
119
|
+
});
|
|
120
|
+
it("conclusion=failure → failed", async () => {
|
|
121
|
+
const httpGet = mockHttpGet(() => ({
|
|
122
|
+
statusCode: 200,
|
|
123
|
+
data: { workflow_runs: [{ conclusion: "failure" }] },
|
|
124
|
+
}));
|
|
125
|
+
const result = await checkCiVerified("user/repo", "main", httpGet);
|
|
126
|
+
assert.equal(result.status, "failed");
|
|
127
|
+
});
|
|
128
|
+
it("conclusion=null → not_checked", async () => {
|
|
129
|
+
const httpGet = mockHttpGet(() => ({
|
|
130
|
+
statusCode: 200,
|
|
131
|
+
data: { workflow_runs: [{ conclusion: null }] },
|
|
132
|
+
}));
|
|
133
|
+
const result = await checkCiVerified("user/repo", "main", httpGet);
|
|
134
|
+
assert.equal(result.status, "not_checked");
|
|
135
|
+
});
|
|
136
|
+
it("network error → not_checked", async () => {
|
|
137
|
+
const httpGet = mockHttpGetError(new Error("connect ECONNREFUSED"));
|
|
138
|
+
const result = await checkCiVerified("user/repo", "main", httpGet);
|
|
139
|
+
assert.equal(result.status, "not_checked");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
// ── 4. runReleaseGateCheck orchestration ───────────────────────────
|
|
143
|
+
describe("runReleaseGateCheck", () => {
|
|
144
|
+
it("target=local_ready passed → local_ready=passed, rest not_checked, no blocked_reason", async () => {
|
|
145
|
+
const deps = {
|
|
146
|
+
checkLocalReady: () => ({ status: "passed" }),
|
|
147
|
+
};
|
|
148
|
+
const result = await runReleaseGateCheck("/fake/repo", "local_ready", {}, deps);
|
|
149
|
+
assert.equal(result.target_stage, "local_ready");
|
|
150
|
+
assert.equal(result.stages.local_ready, "passed");
|
|
151
|
+
assert.equal(result.stages.packed_ready, "not_checked");
|
|
152
|
+
assert.equal(result.stages.published_verified, "not_checked");
|
|
153
|
+
assert.equal(result.stages.github_release_verified, "not_checked");
|
|
154
|
+
assert.equal(result.stages.ci_verified, "not_checked");
|
|
155
|
+
assert.equal(result.blocked_reason, undefined);
|
|
156
|
+
});
|
|
157
|
+
it("local_ready failed → subsequent stages all not_checked, blocked_reason non-empty", async () => {
|
|
158
|
+
const deps = {
|
|
159
|
+
checkLocalReady: () => ({ status: "failed", reason: "build exited with code 1" }),
|
|
160
|
+
};
|
|
161
|
+
const result = await runReleaseGateCheck("/fake/repo", "ci_verified", {
|
|
162
|
+
packageName: "patchwarden",
|
|
163
|
+
version: "1.0.0",
|
|
164
|
+
githubRepo: "user/repo",
|
|
165
|
+
branch: "main",
|
|
166
|
+
}, deps);
|
|
167
|
+
assert.equal(result.stages.local_ready, "failed");
|
|
168
|
+
assert.equal(result.stages.packed_ready, "not_checked");
|
|
169
|
+
assert.equal(result.stages.published_verified, "not_checked");
|
|
170
|
+
assert.equal(result.stages.github_release_verified, "not_checked");
|
|
171
|
+
assert.equal(result.stages.ci_verified, "not_checked");
|
|
172
|
+
assert.ok(result.blocked_reason, "blocked_reason should be non-empty");
|
|
173
|
+
assert.ok(result.blocked_reason.includes("local_ready"), "blocked_reason should mention the failed stage");
|
|
174
|
+
});
|
|
175
|
+
it("full pass-through: all stages passed up to ci_verified", async () => {
|
|
176
|
+
const deps = {
|
|
177
|
+
checkLocalReady: () => ({ status: "passed" }),
|
|
178
|
+
checkPackedReady: () => ({ status: "passed", manifestPath: "/fake/release-artifact-manifest.json" }),
|
|
179
|
+
checkPublishedVerified: async () => ({ status: "passed" }),
|
|
180
|
+
checkGitHubReleaseVerified: async () => ({ status: "passed" }),
|
|
181
|
+
checkCiVerified: async () => ({ status: "passed" }),
|
|
182
|
+
};
|
|
183
|
+
const result = await runReleaseGateCheck("/fake/repo", "ci_verified", {
|
|
184
|
+
packageName: "patchwarden",
|
|
185
|
+
version: "1.0.0",
|
|
186
|
+
githubRepo: "user/repo",
|
|
187
|
+
branch: "main",
|
|
188
|
+
}, deps);
|
|
189
|
+
assert.equal(result.stages.local_ready, "passed");
|
|
190
|
+
assert.equal(result.stages.packed_ready, "passed");
|
|
191
|
+
assert.equal(result.stages.published_verified, "passed");
|
|
192
|
+
assert.equal(result.stages.github_release_verified, "passed");
|
|
193
|
+
assert.equal(result.stages.ci_verified, "passed");
|
|
194
|
+
assert.equal(result.blocked_reason, undefined);
|
|
195
|
+
});
|
|
196
|
+
it("missing options for a required stage → failed with clear reason", async () => {
|
|
197
|
+
const deps = {
|
|
198
|
+
checkLocalReady: () => ({ status: "passed" }),
|
|
199
|
+
checkPackedReady: () => ({ status: "passed" }),
|
|
200
|
+
};
|
|
201
|
+
// published_verified needs packageName + version, neither provided
|
|
202
|
+
const result = await runReleaseGateCheck("/fake/repo", "published_verified", {}, deps);
|
|
203
|
+
assert.equal(result.stages.local_ready, "passed");
|
|
204
|
+
assert.equal(result.stages.packed_ready, "passed");
|
|
205
|
+
assert.equal(result.stages.published_verified, "failed");
|
|
206
|
+
assert.ok(result.blocked_reason?.includes("published_verified"));
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
// ── 5. Function name spelling (Verified, not Verfied) ─────────────
|
|
210
|
+
describe("function name spelling", () => {
|
|
211
|
+
it("checkPublishedVerified is a function (not Verfied)", () => {
|
|
212
|
+
assert.equal(typeof checkPublishedVerified, "function");
|
|
213
|
+
});
|
|
214
|
+
it("checkGitHubReleaseVerified is a function", () => {
|
|
215
|
+
assert.equal(typeof checkGitHubReleaseVerified, "function");
|
|
216
|
+
});
|
|
217
|
+
it("checkCiVerified is a function", () => {
|
|
218
|
+
assert.equal(typeof checkCiVerified, "function");
|
|
219
|
+
});
|
|
220
|
+
it("runReleaseGateCheck is a function", () => {
|
|
221
|
+
assert.equal(typeof runReleaseGateCheck, "function");
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
// ── 6. computeTokenDigest ──────────────────────────────────────────
|
|
225
|
+
describe("computeTokenDigest", () => {
|
|
226
|
+
it("returns sha256: prefix with hex digest", () => {
|
|
227
|
+
const digest = computeTokenDigest("test-token");
|
|
228
|
+
assert.ok(digest.startsWith("sha256:"));
|
|
229
|
+
// sha256 hex is 64 chars + "sha256:" prefix = 71 chars
|
|
230
|
+
assert.equal(digest.length, 71);
|
|
231
|
+
});
|
|
232
|
+
it("does not contain the raw token", () => {
|
|
233
|
+
const TOKEN = "test-token";
|
|
234
|
+
const digest = computeTokenDigest(TOKEN);
|
|
235
|
+
assert.ok(!digest.includes(TOKEN), "digest must not contain the raw token");
|
|
236
|
+
});
|
|
237
|
+
it("is deterministic for the same input", () => {
|
|
238
|
+
const d1 = computeTokenDigest("abc");
|
|
239
|
+
const d2 = computeTokenDigest("abc");
|
|
240
|
+
assert.equal(d1, d2);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
2
|
+
import { strict as assert } from "node:assert";
|
|
3
|
+
import { mkdtempSync, rmSync, writeFileSync, readFileSync } from "node:fs";
|
|
4
|
+
import { join, normalize } from "node:path";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { reloadConfig } from "../../config.js";
|
|
7
|
+
import { runTaskLoopWithDeps } from "../../tools/runTaskLoop.js";
|
|
8
|
+
import { getTaskLineage, writeTaskLineage } from "../../tools/taskLineage.js";
|
|
9
|
+
let tempDir;
|
|
10
|
+
let prevConfigEnv;
|
|
11
|
+
function writeConfig() {
|
|
12
|
+
const configPath = join(tempDir, "patchwarden.config.json");
|
|
13
|
+
writeFileSync(configPath, JSON.stringify({
|
|
14
|
+
workspaceRoot: tempDir,
|
|
15
|
+
tasksDir: ".patchwarden/tasks",
|
|
16
|
+
plansDir: ".patchwarden/plans",
|
|
17
|
+
assessmentsDir: ".patchwarden/assessments",
|
|
18
|
+
agents: {
|
|
19
|
+
fake: { command: "fake-agent", args: [] },
|
|
20
|
+
},
|
|
21
|
+
allowedTestCommands: ["npm test", "npm run build"],
|
|
22
|
+
directAllowedCommands: ["npm test", "npm run build"],
|
|
23
|
+
defaultTaskTimeoutSeconds: 30,
|
|
24
|
+
maxTaskTimeoutSeconds: 120,
|
|
25
|
+
enableDirectProfile: true,
|
|
26
|
+
}), "utf-8");
|
|
27
|
+
prevConfigEnv = process.env.PATCHWARDEN_CONFIG;
|
|
28
|
+
process.env.PATCHWARDEN_CONFIG = configPath;
|
|
29
|
+
reloadConfig();
|
|
30
|
+
}
|
|
31
|
+
function depsFor(options) {
|
|
32
|
+
const decisions = [...(options.decisions || ["allow"])];
|
|
33
|
+
const tasks = [...(options.tasks || ["task-main"])];
|
|
34
|
+
const calls = [];
|
|
35
|
+
const deps = {
|
|
36
|
+
createTask: ((input) => {
|
|
37
|
+
calls.push(input.execution_mode === "assess_only" ? "assess" : "execute");
|
|
38
|
+
if (input.execution_mode === "assess_only") {
|
|
39
|
+
const decision = decisions.shift() || "allow";
|
|
40
|
+
return {
|
|
41
|
+
assessment_id: `assessment-${calls.length}`,
|
|
42
|
+
decision,
|
|
43
|
+
reason_codes: decision === "allow" ? ["repo_scoped"] : ["release_template_needs_confirm"],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return { task_id: tasks.shift() || `task-${calls.length}`, status: "pending" };
|
|
47
|
+
}),
|
|
48
|
+
waitForTask: (async (taskId) => ({
|
|
49
|
+
task_id: taskId,
|
|
50
|
+
status: options.statuses?.[taskId] || "done_by_agent",
|
|
51
|
+
phase: options.statuses?.[taskId] || "done_by_agent",
|
|
52
|
+
terminal: true,
|
|
53
|
+
continuation_required: false,
|
|
54
|
+
next_action: "safe_audit",
|
|
55
|
+
})),
|
|
56
|
+
safeResult: ((taskId) => ({
|
|
57
|
+
task_id: taskId,
|
|
58
|
+
status: options.statuses?.[taskId] || "done_by_agent",
|
|
59
|
+
terminal: true,
|
|
60
|
+
verification: { status: options.verifications?.[taskId] || "passed" },
|
|
61
|
+
next_action: "audit_or_accept",
|
|
62
|
+
})),
|
|
63
|
+
safeTestSummary: ((taskId) => ({
|
|
64
|
+
task_id: taskId,
|
|
65
|
+
status: options.verifications?.[taskId] || "passed",
|
|
66
|
+
commands: [{ command: "npm test", status: options.verifications?.[taskId] || "passed", exit_code: 0 }],
|
|
67
|
+
})),
|
|
68
|
+
safeAudit: ((taskId) => {
|
|
69
|
+
const audit = options.audits?.[taskId] || { verdict: "pass" };
|
|
70
|
+
return {
|
|
71
|
+
task_id: taskId,
|
|
72
|
+
verdict: audit.verdict,
|
|
73
|
+
fail_checks: (audit.fail || []).map((name) => ({ name, result: "fail" })),
|
|
74
|
+
warn_checks: (audit.warn || []).map((name) => ({ name, result: "warn" })),
|
|
75
|
+
recommended_next_actions: ["accept"],
|
|
76
|
+
};
|
|
77
|
+
}),
|
|
78
|
+
createDirectSession: ((input) => ({
|
|
79
|
+
session_id: "direct-test",
|
|
80
|
+
repo_path: input.repo_path,
|
|
81
|
+
resolved_repo_path: tempDir,
|
|
82
|
+
workspace_clean: true,
|
|
83
|
+
allowed_commands: ["npm test", "npm run build"],
|
|
84
|
+
expires_at: "2026-07-04T13:00:00.000Z",
|
|
85
|
+
next_action: "run_verification",
|
|
86
|
+
})),
|
|
87
|
+
runDirectVerificationBundle: (async () => ({
|
|
88
|
+
session_id: "direct-test",
|
|
89
|
+
status: options.directBundleStatus || "passed",
|
|
90
|
+
command_count: 1,
|
|
91
|
+
passed_commands: (options.directBundleStatus || "passed") === "passed" ? 1 : 0,
|
|
92
|
+
failed_commands: (options.directBundleStatus || "passed") === "passed" ? 0 : 1,
|
|
93
|
+
timed_out_commands: 0,
|
|
94
|
+
commands: [{
|
|
95
|
+
command: "npm test",
|
|
96
|
+
passed: (options.directBundleStatus || "passed") === "passed",
|
|
97
|
+
exit_code: (options.directBundleStatus || "passed") === "passed" ? 0 : 1,
|
|
98
|
+
timed_out: false,
|
|
99
|
+
redacted: false,
|
|
100
|
+
redaction_categories: [],
|
|
101
|
+
started_at: "2026-07-04T12:00:00.000Z",
|
|
102
|
+
finished_at: "2026-07-04T12:00:01.000Z",
|
|
103
|
+
}],
|
|
104
|
+
large_logs_omitted: true,
|
|
105
|
+
next_action: "safe_finalize_direct_session",
|
|
106
|
+
})),
|
|
107
|
+
safeFinalizeDirectSession: (() => ({
|
|
108
|
+
session_id: "direct-test",
|
|
109
|
+
finalized: true,
|
|
110
|
+
changed_files_total: 0,
|
|
111
|
+
next_action: "safe_audit_direct_session",
|
|
112
|
+
})),
|
|
113
|
+
safeAuditDirectSession: (() => ({
|
|
114
|
+
session_id: "direct-test",
|
|
115
|
+
decision: options.directAuditDecision || "pass",
|
|
116
|
+
reason_codes: [],
|
|
117
|
+
blocking_findings: [],
|
|
118
|
+
warnings: [],
|
|
119
|
+
evidence: { changed_files_total: 0, verification_runs: [] },
|
|
120
|
+
next_action: "accept",
|
|
121
|
+
})),
|
|
122
|
+
writeTaskLineage,
|
|
123
|
+
createLineageId: (() => "lineage_20260704_test"),
|
|
124
|
+
recommendAgentForTask: ((input) => ({
|
|
125
|
+
repo_path: input.repo_path,
|
|
126
|
+
resolved_repo_path: tempDir,
|
|
127
|
+
recommended_agent: "fake",
|
|
128
|
+
fallback_agent: null,
|
|
129
|
+
fallback: false,
|
|
130
|
+
reason: "test route",
|
|
131
|
+
risk_notes: [],
|
|
132
|
+
suggested_verify_commands: ["npm test"],
|
|
133
|
+
bounded: true,
|
|
134
|
+
})),
|
|
135
|
+
createWorktree: ((goalId, subgoalId, workspaceRoot) => {
|
|
136
|
+
calls.push(`worktree:${workspaceRoot}`);
|
|
137
|
+
return {
|
|
138
|
+
worktreeId: "wt-test",
|
|
139
|
+
worktreePath: tempDir,
|
|
140
|
+
branch: "pw-test",
|
|
141
|
+
};
|
|
142
|
+
}),
|
|
143
|
+
now: () => new Date("2026-07-04T12:00:00.000Z"),
|
|
144
|
+
sleep: async () => { },
|
|
145
|
+
};
|
|
146
|
+
return { deps, calls };
|
|
147
|
+
}
|
|
148
|
+
describe("runTaskLoop", () => {
|
|
149
|
+
beforeEach(() => {
|
|
150
|
+
tempDir = mkdtempSync(join(tmpdir(), "pw-loop-"));
|
|
151
|
+
writeConfig();
|
|
152
|
+
});
|
|
153
|
+
afterEach(() => {
|
|
154
|
+
if (prevConfigEnv === undefined)
|
|
155
|
+
delete process.env.PATCHWARDEN_CONFIG;
|
|
156
|
+
else
|
|
157
|
+
process.env.PATCHWARDEN_CONFIG = prevConfigEnv;
|
|
158
|
+
reloadConfig();
|
|
159
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
160
|
+
});
|
|
161
|
+
it("returns success with a bounded lineage summary", async () => {
|
|
162
|
+
const { deps } = depsFor({});
|
|
163
|
+
const result = await runTaskLoopWithDeps({
|
|
164
|
+
repo_path: ".",
|
|
165
|
+
goal: "Make a safe change",
|
|
166
|
+
agent: "fake",
|
|
167
|
+
verify_commands: ["npm test"],
|
|
168
|
+
}, deps);
|
|
169
|
+
assert.equal(result.stop_reason, "success");
|
|
170
|
+
assert.equal(result.final_status, "accepted");
|
|
171
|
+
assert.equal(result.tasks.main, "task-main");
|
|
172
|
+
const payload = JSON.stringify(result);
|
|
173
|
+
assert.ok(!payload.includes("stdout"));
|
|
174
|
+
assert.ok(!payload.includes("stderr"));
|
|
175
|
+
assert.ok(!payload.includes("diff.patch"));
|
|
176
|
+
});
|
|
177
|
+
it("keeps v1.3 behavior when direct_verify is false", async () => {
|
|
178
|
+
const { deps } = depsFor({});
|
|
179
|
+
const result = await runTaskLoopWithDeps({
|
|
180
|
+
repo_path: ".",
|
|
181
|
+
goal: "Run without Direct",
|
|
182
|
+
agent: "fake",
|
|
183
|
+
verify_commands: ["npm test"],
|
|
184
|
+
direct_verify: false,
|
|
185
|
+
}, deps);
|
|
186
|
+
assert.equal(result.stop_reason, "success");
|
|
187
|
+
assert.equal(result.direct_verify, false);
|
|
188
|
+
assert.deepEqual(result.tasks.direct_sessions, []);
|
|
189
|
+
assert.equal(result.isolation_mode, "current_repo");
|
|
190
|
+
assert.equal(result.worktree.status, "not_used");
|
|
191
|
+
});
|
|
192
|
+
it("records bounded agent routing when agent is auto", async () => {
|
|
193
|
+
const { deps } = depsFor({});
|
|
194
|
+
const result = await runTaskLoopWithDeps({
|
|
195
|
+
repo_path: ".",
|
|
196
|
+
goal: "Pick a safe agent",
|
|
197
|
+
agent: "auto",
|
|
198
|
+
verify_commands: ["npm test"],
|
|
199
|
+
scope_files: ["src/index.ts"],
|
|
200
|
+
}, deps);
|
|
201
|
+
assert.equal(result.stop_reason, "success");
|
|
202
|
+
assert.equal(result.agent_routing?.requested_agent, "auto");
|
|
203
|
+
assert.equal(result.agent_routing?.selected_agent, "fake");
|
|
204
|
+
assert.equal(result.agent_routing?.reason, "test route");
|
|
205
|
+
});
|
|
206
|
+
it("uses worktree isolation for task execution and records worktree evidence", async () => {
|
|
207
|
+
const { deps, calls } = depsFor({});
|
|
208
|
+
const result = await runTaskLoopWithDeps({
|
|
209
|
+
repo_path: "child-repo",
|
|
210
|
+
goal: "Run in a worktree",
|
|
211
|
+
agent: "fake",
|
|
212
|
+
verify_commands: ["npm test"],
|
|
213
|
+
isolation_mode: "worktree",
|
|
214
|
+
worktree_cleanup: "keep",
|
|
215
|
+
}, deps);
|
|
216
|
+
assert.equal(result.stop_reason, "success");
|
|
217
|
+
assert.equal(result.isolation_mode, "worktree");
|
|
218
|
+
assert.equal(result.worktree.worktree_id, "wt-test");
|
|
219
|
+
assert.equal(result.worktree.branch, "pw-test");
|
|
220
|
+
assert.equal(result.worktree.status, "active");
|
|
221
|
+
assert.ok(calls.includes(`worktree:${normalize(join(tempDir, "child-repo"))}`));
|
|
222
|
+
});
|
|
223
|
+
it("records Direct verification evidence when direct_verify succeeds", async () => {
|
|
224
|
+
const { deps } = depsFor({});
|
|
225
|
+
const result = await runTaskLoopWithDeps({
|
|
226
|
+
repo_path: ".",
|
|
227
|
+
goal: "Run with Direct verification",
|
|
228
|
+
agent: "fake",
|
|
229
|
+
verify_commands: ["npm test"],
|
|
230
|
+
direct_verify: true,
|
|
231
|
+
}, deps);
|
|
232
|
+
assert.equal(result.stop_reason, "success");
|
|
233
|
+
assert.equal(result.direct_verify, true);
|
|
234
|
+
assert.equal(result.tasks.direct_sessions.length, 1);
|
|
235
|
+
assert.equal(result.tasks.direct_sessions[0].session_id, "direct-test");
|
|
236
|
+
assert.equal(result.tasks.direct_sessions[0].status, "passed");
|
|
237
|
+
assert.equal(result.tasks.direct_sessions[0].audit_decision, "pass");
|
|
238
|
+
const payload = JSON.stringify(result);
|
|
239
|
+
assert.ok(!payload.includes("stdout_tail"));
|
|
240
|
+
assert.ok(!payload.includes("stderr_tail"));
|
|
241
|
+
assert.ok(!payload.includes("diff.patch"));
|
|
242
|
+
});
|
|
243
|
+
it("stops clearly when direct_verify is requested but Direct profile is disabled", async () => {
|
|
244
|
+
const configPath = join(tempDir, "patchwarden.config.json");
|
|
245
|
+
const raw = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
246
|
+
raw.enableDirectProfile = false;
|
|
247
|
+
writeFileSync(configPath, JSON.stringify(raw), "utf-8");
|
|
248
|
+
reloadConfig();
|
|
249
|
+
const { deps } = depsFor({});
|
|
250
|
+
const result = await runTaskLoopWithDeps({
|
|
251
|
+
repo_path: ".",
|
|
252
|
+
goal: "Run with unavailable Direct",
|
|
253
|
+
agent: "fake",
|
|
254
|
+
verify_commands: ["npm test"],
|
|
255
|
+
direct_verify: true,
|
|
256
|
+
}, deps);
|
|
257
|
+
assert.equal(result.stop_reason, "direct_profile_disabled");
|
|
258
|
+
assert.equal(result.final_status, "blocked");
|
|
259
|
+
assert.equal(result.tasks.main, "task-main");
|
|
260
|
+
assert.equal(result.tasks.direct_sessions[0].session_id, "not_created");
|
|
261
|
+
});
|
|
262
|
+
it("returns direct_verification_failed without leaking Direct logs", async () => {
|
|
263
|
+
const { deps } = depsFor({ directBundleStatus: "failed" });
|
|
264
|
+
const result = await runTaskLoopWithDeps({
|
|
265
|
+
repo_path: ".",
|
|
266
|
+
goal: "Run with failing Direct verification",
|
|
267
|
+
agent: "fake",
|
|
268
|
+
verify_commands: ["npm test"],
|
|
269
|
+
direct_verify: true,
|
|
270
|
+
}, deps);
|
|
271
|
+
assert.equal(result.stop_reason, "direct_verification_failed");
|
|
272
|
+
assert.equal(result.final_status, "needs_fix");
|
|
273
|
+
assert.equal(result.tasks.direct_sessions[0].failed_commands, 1);
|
|
274
|
+
const payload = JSON.stringify(result);
|
|
275
|
+
assert.ok(!payload.includes("stdout_tail"));
|
|
276
|
+
assert.ok(!payload.includes("stderr_tail"));
|
|
277
|
+
});
|
|
278
|
+
it("returns direct_audit_failed when Direct audit fails", async () => {
|
|
279
|
+
const { deps } = depsFor({ directAuditDecision: "fail" });
|
|
280
|
+
const result = await runTaskLoopWithDeps({
|
|
281
|
+
repo_path: ".",
|
|
282
|
+
goal: "Run with failing Direct audit",
|
|
283
|
+
agent: "fake",
|
|
284
|
+
verify_commands: ["npm test"],
|
|
285
|
+
direct_verify: true,
|
|
286
|
+
}, deps);
|
|
287
|
+
assert.equal(result.stop_reason, "direct_audit_failed");
|
|
288
|
+
assert.equal(result.final_status, "blocked");
|
|
289
|
+
assert.equal(result.tasks.direct_sessions[0].audit_decision, "fail");
|
|
290
|
+
});
|
|
291
|
+
it("creates a fix_tests follow-up after failed verification", async () => {
|
|
292
|
+
const { deps } = depsFor({
|
|
293
|
+
tasks: ["task-main", "task-fix"],
|
|
294
|
+
statuses: { "task-main": "failed_verification", "task-fix": "done_by_agent" },
|
|
295
|
+
verifications: { "task-main": "failed", "task-fix": "passed" },
|
|
296
|
+
audits: {
|
|
297
|
+
"task-main": { verdict: "warn", warn: ["test_exit_code"] },
|
|
298
|
+
"task-fix": { verdict: "pass" },
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
const result = await runTaskLoopWithDeps({
|
|
302
|
+
repo_path: ".",
|
|
303
|
+
goal: "Repair tests",
|
|
304
|
+
agent: "fake",
|
|
305
|
+
verify_commands: ["npm test"],
|
|
306
|
+
max_iterations: 2,
|
|
307
|
+
}, deps);
|
|
308
|
+
assert.equal(result.stop_reason, "success");
|
|
309
|
+
assert.equal(result.tasks.main, "task-main");
|
|
310
|
+
assert.deepEqual(result.tasks.fix, ["task-fix"]);
|
|
311
|
+
assert.equal(result.rounds.length, 2);
|
|
312
|
+
});
|
|
313
|
+
it("stops before execution when assessment needs confirmation", async () => {
|
|
314
|
+
const { deps, calls } = depsFor({ decisions: ["needs_confirm"] });
|
|
315
|
+
const result = await runTaskLoopWithDeps({
|
|
316
|
+
repo_path: ".",
|
|
317
|
+
goal: "Release-like work",
|
|
318
|
+
agent: "fake",
|
|
319
|
+
verify_commands: ["npm test"],
|
|
320
|
+
}, deps);
|
|
321
|
+
assert.equal(result.stop_reason, "user_confirmation_required");
|
|
322
|
+
assert.equal(result.stopped_before_execution, true);
|
|
323
|
+
assert.deepEqual(calls, ["assess"]);
|
|
324
|
+
});
|
|
325
|
+
it("returns max_iterations_reached when verification keeps failing", async () => {
|
|
326
|
+
const { deps } = depsFor({
|
|
327
|
+
statuses: { "task-main": "failed_verification" },
|
|
328
|
+
verifications: { "task-main": "failed" },
|
|
329
|
+
audits: { "task-main": { verdict: "warn", warn: ["test_exit_code"] } },
|
|
330
|
+
});
|
|
331
|
+
const result = await runTaskLoopWithDeps({
|
|
332
|
+
repo_path: ".",
|
|
333
|
+
goal: "Fix tests",
|
|
334
|
+
agent: "fake",
|
|
335
|
+
verify_commands: ["npm test"],
|
|
336
|
+
max_iterations: 1,
|
|
337
|
+
}, deps);
|
|
338
|
+
assert.equal(result.stop_reason, "max_iterations_reached");
|
|
339
|
+
assert.equal(result.final_status, "needs_fix");
|
|
340
|
+
});
|
|
341
|
+
it("writes BOM-free lineage JSON readable through get_task_lineage", async () => {
|
|
342
|
+
const { deps } = depsFor({});
|
|
343
|
+
const result = await runTaskLoopWithDeps({
|
|
344
|
+
repo_path: ".",
|
|
345
|
+
goal: "Persist lineage",
|
|
346
|
+
agent: "fake",
|
|
347
|
+
verify_commands: ["npm test"],
|
|
348
|
+
}, deps);
|
|
349
|
+
const lineagePath = join(tempDir, ".patchwarden", "lineages", result.lineage_id, "lineage.json");
|
|
350
|
+
const raw = readFileSync(lineagePath);
|
|
351
|
+
assert.notEqual(raw[0], 0xef);
|
|
352
|
+
const parsed = JSON.parse(raw.toString("utf-8"));
|
|
353
|
+
assert.equal(parsed.lineage_id, result.lineage_id);
|
|
354
|
+
const safe = getTaskLineage(result.lineage_id);
|
|
355
|
+
assert.equal(safe.lineage_id, result.lineage_id);
|
|
356
|
+
assert.equal(safe.rounds.length, 1);
|
|
357
|
+
});
|
|
358
|
+
it("reads legacy string direct_sessions as bounded evidence", () => {
|
|
359
|
+
const safe = writeTaskLineage({
|
|
360
|
+
lineage_id: "lineage_legacy_direct",
|
|
361
|
+
goal: "Legacy lineage",
|
|
362
|
+
repo_path: ".",
|
|
363
|
+
created_at: "2026-07-04T12:00:00.000Z",
|
|
364
|
+
updated_at: "2026-07-04T12:00:00.000Z",
|
|
365
|
+
final_status: "accepted",
|
|
366
|
+
stop_reason: "success",
|
|
367
|
+
next_action: "accept",
|
|
368
|
+
main_task: "task-main",
|
|
369
|
+
fix_tasks: [],
|
|
370
|
+
cleanup_tasks: [],
|
|
371
|
+
direct_sessions: ["direct-old"],
|
|
372
|
+
rounds: [],
|
|
373
|
+
warnings: [],
|
|
374
|
+
errors: [],
|
|
375
|
+
});
|
|
376
|
+
assert.equal(safe.tasks.direct_sessions[0].session_id, "direct-old");
|
|
377
|
+
const readBack = getTaskLineage("lineage_legacy_direct");
|
|
378
|
+
assert.equal(readBack.tasks.direct_sessions[0].session_id, "direct-old");
|
|
379
|
+
});
|
|
380
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|