kodingo-cli 1.4.0 → 1.4.2
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/dist/__tests__/branchSettlement.test.js +295 -0
- package/dist/__tests__/checkoutFreshnessGuard.test.js +221 -0
- package/dist/__tests__/deepScanConsentOrdering.test.js +121 -0
- package/dist/__tests__/deepScanHookBranchGate.test.js +136 -0
- package/dist/__tests__/deepScanLocal.test.js +65 -0
- package/dist/__tests__/deepScanNetworkFlows.test.js +154 -0
- package/dist/__tests__/initCoverageShortcut.test.js +54 -0
- package/dist/__tests__/installHook.test.js +62 -0
- package/dist/__tests__/pollAndOutcome.test.js +89 -0
- package/dist/__tests__/repo-identity.test.js +32 -0
- package/dist/__tests__/settleAlreadyCompleteProject.test.js +353 -0
- package/dist/cli.js +2 -1
- package/dist/commands/deep-scan.js +668 -8
- package/dist/commands/init.js +87 -23
- package/dist/commands/install-hook.js +23 -8
- package/dist/utils/repo-identity.js +23 -9
- package/package.json +2 -2
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/** Validation fixtures only; no production or customer identifiers. */
|
|
7
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
+
const node_test_1 = require("node:test");
|
|
9
|
+
const deep_scan_1 = require("../commands/deep-scan");
|
|
10
|
+
const repository = "validation-org/validation-repo";
|
|
11
|
+
(0, node_test_1.describe)("decideBranchSettlement", () => {
|
|
12
|
+
(0, node_test_1.it)("proceeds silently when the tracked branch equals the checkout's branch", () => {
|
|
13
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "match", trackedBranch: "main", branch: "main", repository, yes: false });
|
|
14
|
+
strict_1.default.deepEqual(decision, { action: "proceed" });
|
|
15
|
+
});
|
|
16
|
+
(0, node_test_1.it)("never overwrites a different tracked branch, even if the caller asked to record", () => {
|
|
17
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "mismatch", trackedBranch: "main", branch: "feature/x", repository, yes: false, promptAnswerYes: true });
|
|
18
|
+
strict_1.default.equal(decision.action, "proceed-held");
|
|
19
|
+
if (decision.action === "proceed-held") {
|
|
20
|
+
strict_1.default.match(decision.message, /tracked branch for .* is "main"/i);
|
|
21
|
+
strict_1.default.match(decision.message, /held/i);
|
|
22
|
+
strict_1.default.match(decision.message, /feature\/x/);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
(0, node_test_1.it)("records the branch when none is tracked and the user accepts the prompt", () => {
|
|
26
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "main", repository, yes: false, promptAnswerYes: true });
|
|
27
|
+
strict_1.default.deepEqual(decision, { action: "record" });
|
|
28
|
+
});
|
|
29
|
+
(0, node_test_1.it)("holds with a plain message when none is tracked and the user declines", () => {
|
|
30
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "main", repository, yes: false, promptAnswerYes: false });
|
|
31
|
+
strict_1.default.equal(decision.action, "proceed-held");
|
|
32
|
+
if (decision.action === "proceed-held") {
|
|
33
|
+
strict_1.default.match(decision.message, new RegExp(`No tracked branch is recorded for ${repository.replace(/[/]/g, "\\/")}`));
|
|
34
|
+
strict_1.default.match(decision.message, /held/i);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
(0, node_test_1.it)("--yes records when none is tracked and the checkout matches the remote's default branch", () => {
|
|
38
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "main", repository, yes: true, defaultBranch: "main" });
|
|
39
|
+
strict_1.default.deepEqual(decision, { action: "record" });
|
|
40
|
+
});
|
|
41
|
+
(0, node_test_1.it)("--yes refuses when none is tracked and the checkout does not match the remote's default branch", () => {
|
|
42
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "feature/x", repository, yes: true, defaultBranch: "main" });
|
|
43
|
+
strict_1.default.equal(decision.action, "refuse");
|
|
44
|
+
if (decision.action === "refuse")
|
|
45
|
+
strict_1.default.match(decision.message, /does not match the remote's default branch/);
|
|
46
|
+
});
|
|
47
|
+
(0, node_test_1.it)("--yes refuses when none is tracked and the default branch could not be determined", () => {
|
|
48
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "main", repository, yes: true, defaultBranch: null });
|
|
49
|
+
strict_1.default.equal(decision.action, "refuse");
|
|
50
|
+
if (decision.action === "refuse")
|
|
51
|
+
strict_1.default.match(decision.message, /could not be determined/);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
(0, node_test_1.describe)("decideBranchSettlement — scanPending:false (the 'coverage already complete, no scan pending' path)", () => {
|
|
55
|
+
(0, node_test_1.it)("a mismatch names both branches and says commits will not update Kortex — never 'this scan will be held' (there is no scan)", () => {
|
|
56
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "mismatch", trackedBranch: "main", branch: "feature/x", repository, yes: false, scanPending: false });
|
|
57
|
+
strict_1.default.equal(decision.action, "proceed-held");
|
|
58
|
+
if (decision.action === "proceed-held") {
|
|
59
|
+
strict_1.default.match(decision.message, /This project tracks "main"/);
|
|
60
|
+
strict_1.default.match(decision.message, /commits on "feature\/x" will not update Kortex/);
|
|
61
|
+
strict_1.default.match(decision.message, /Switch branches or ask an org admin/);
|
|
62
|
+
strict_1.default.equal(/this scan will be held/i.test(decision.message), false);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
(0, node_test_1.it)("--yes on a feature branch (not the default) still refuses without recording", () => {
|
|
66
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "feature/x", repository, yes: true, defaultBranch: "main", scanPending: false });
|
|
67
|
+
strict_1.default.equal(decision.action, "refuse");
|
|
68
|
+
});
|
|
69
|
+
(0, node_test_1.it)("--yes on the default branch still records", () => {
|
|
70
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "main", repository, yes: true, defaultBranch: "main", scanPending: false });
|
|
71
|
+
strict_1.default.deepEqual(decision, { action: "record" });
|
|
72
|
+
});
|
|
73
|
+
(0, node_test_1.it)("interactive accept still records, unaffected by scanPending", () => {
|
|
74
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "main", repository, yes: false, promptAnswerYes: true, scanPending: false });
|
|
75
|
+
strict_1.default.deepEqual(decision, { action: "record" });
|
|
76
|
+
});
|
|
77
|
+
(0, node_test_1.it)("interactive decline says commits will not update Kortex, never 'this scan will be held'", () => {
|
|
78
|
+
const decision = (0, deep_scan_1.decideBranchSettlement)({ outcome: "none", trackedBranch: null, branch: "main", repository, yes: false, promptAnswerYes: false, scanPending: false });
|
|
79
|
+
strict_1.default.equal(decision.action, "proceed-held");
|
|
80
|
+
if (decision.action === "proceed-held") {
|
|
81
|
+
strict_1.default.match(decision.message, /Commits will not update Kortex until one is tracked/);
|
|
82
|
+
strict_1.default.equal(/this scan will be held/i.test(decision.message), false);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
(0, node_test_1.it)("omitting scanPending (every existing caller) is byte-identical to the original first-scan wording", () => {
|
|
86
|
+
const withDefault = (0, deep_scan_1.decideBranchSettlement)({ outcome: "mismatch", trackedBranch: "main", branch: "feature/x", repository, yes: false });
|
|
87
|
+
const explicitTrue = (0, deep_scan_1.decideBranchSettlement)({ outcome: "mismatch", trackedBranch: "main", branch: "feature/x", repository, yes: false, scanPending: true });
|
|
88
|
+
strict_1.default.deepEqual(withDefault, explicitTrue);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
(0, node_test_1.describe)("describeCoverageCompleteOutcome", () => {
|
|
92
|
+
(0, node_test_1.it)("is only the confident 'commits will keep it up to date' message when nothing is held", () => {
|
|
93
|
+
const message = (0, deep_scan_1.describeCoverageCompleteOutcome)(false);
|
|
94
|
+
strict_1.default.match(message, /Kortex already has a complete read of this project/);
|
|
95
|
+
strict_1.default.match(message, /Your commits will keep it up to date/);
|
|
96
|
+
});
|
|
97
|
+
(0, node_test_1.it)("drops the confident claim when the branch settlement is held (mismatch, or declined/refused)", () => {
|
|
98
|
+
const message = (0, deep_scan_1.describeCoverageCompleteOutcome)(true);
|
|
99
|
+
strict_1.default.match(message, /Kortex already has a complete read of this project/);
|
|
100
|
+
strict_1.default.equal(/Your commits will keep it up to date/.test(message), false);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
(0, node_test_1.describe)("isFixedByTrackedBranchRecording", () => {
|
|
104
|
+
(0, node_test_1.it)("is fixed by recording: branch_unknown", () => {
|
|
105
|
+
strict_1.default.equal((0, deep_scan_1.isFixedByTrackedBranchRecording)("branch_unknown"), true);
|
|
106
|
+
});
|
|
107
|
+
(0, node_test_1.it)("is fixed by recording: a mismatch against an unregistered tracked branch", () => {
|
|
108
|
+
strict_1.default.equal((0, deep_scan_1.isFixedByTrackedBranchRecording)("branch_mismatch:feature/x:unregistered"), true);
|
|
109
|
+
});
|
|
110
|
+
(0, node_test_1.it)("is NOT fixed by recording: a mismatch against a real, different tracked branch", () => {
|
|
111
|
+
strict_1.default.equal((0, deep_scan_1.isFixedByTrackedBranchRecording)("branch_mismatch:feature/x:main"), false);
|
|
112
|
+
});
|
|
113
|
+
(0, node_test_1.it)("is NOT fixed by recording: dirty_checkout or detached_head", () => {
|
|
114
|
+
strict_1.default.equal((0, deep_scan_1.isFixedByTrackedBranchRecording)("dirty_checkout"), false);
|
|
115
|
+
strict_1.default.equal((0, deep_scan_1.isFixedByTrackedBranchRecording)("detached_head"), false);
|
|
116
|
+
});
|
|
117
|
+
(0, node_test_1.it)("is NOT fixed by recording: null/undefined (already applied, nothing held)", () => {
|
|
118
|
+
strict_1.default.equal((0, deep_scan_1.isFixedByTrackedBranchRecording)(null), false);
|
|
119
|
+
strict_1.default.equal((0, deep_scan_1.isFixedByTrackedBranchRecording)(undefined), false);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
(0, node_test_1.describe)("isHeldScanFixable", () => {
|
|
123
|
+
(0, node_test_1.it)("prefers the server's own fixableByTrackedBranch when present — even when it disagrees with the reason string", () => {
|
|
124
|
+
strict_1.default.equal((0, deep_scan_1.isHeldScanFixable)({ reason: "dirty_checkout", fixableByTrackedBranch: true }), true);
|
|
125
|
+
strict_1.default.equal((0, deep_scan_1.isHeldScanFixable)({ reason: "branch_mismatch:feature/x:unregistered", fixableByTrackedBranch: false }), false);
|
|
126
|
+
});
|
|
127
|
+
(0, node_test_1.it)("falls back to the static reason-string check when the server (an older version) doesn't send fixableByTrackedBranch", () => {
|
|
128
|
+
strict_1.default.equal((0, deep_scan_1.isHeldScanFixable)({ reason: "branch_mismatch:feature/x:unregistered" }), true);
|
|
129
|
+
strict_1.default.equal((0, deep_scan_1.isHeldScanFixable)({ reason: "dirty_checkout" }), false);
|
|
130
|
+
});
|
|
131
|
+
(0, node_test_1.it)("re-checks a mismatch whose scanned branch now equals the tracked branch — via the server's authoritative signal, not just the 'unregistered' literal", () => {
|
|
132
|
+
// reason alone ("branch_mismatch:main:develop") looks unfixable to the
|
|
133
|
+
// static check (tracked was "develop" at upload time, not "unregistered")
|
|
134
|
+
// — but the server re-evaluated it against the CURRENT tracked branch
|
|
135
|
+
// ("main", now equal to the scan's own branch) and says it fixes it.
|
|
136
|
+
strict_1.default.equal((0, deep_scan_1.isHeldScanFixable)({ reason: "branch_mismatch:main:develop", fixableByTrackedBranch: true }), true);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
(0, node_test_1.describe)("describeHeldScanDebugInfo", () => {
|
|
140
|
+
(0, node_test_1.it)("includes the tracked branch, the held scan's id/commit/reason, and the fixability decision", () => {
|
|
141
|
+
const line = (0, deep_scan_1.describeHeldScanDebugInfo)({
|
|
142
|
+
trackedBranch: "main",
|
|
143
|
+
lastCliScan: { id: "scan-1", commitSha: "deadbeef".repeat(5), reason: "branch_mismatch:main:unregistered", fixableByTrackedBranch: true },
|
|
144
|
+
fixable: true,
|
|
145
|
+
});
|
|
146
|
+
strict_1.default.match(line, /^\[debug\]/);
|
|
147
|
+
strict_1.default.match(line, /tracked branch=main/);
|
|
148
|
+
strict_1.default.match(line, /id=scan-1/);
|
|
149
|
+
strict_1.default.match(line, /commit=deadbeef/);
|
|
150
|
+
strict_1.default.match(line, /reason=branch_mismatch:main:unregistered/);
|
|
151
|
+
strict_1.default.match(line, /fixable=true/);
|
|
152
|
+
strict_1.default.match(line, /\(server\)/);
|
|
153
|
+
});
|
|
154
|
+
(0, node_test_1.it)("reports the reason-string fallback source when the server didn't send fixableByTrackedBranch", () => {
|
|
155
|
+
const line = (0, deep_scan_1.describeHeldScanDebugInfo)({
|
|
156
|
+
trackedBranch: "main",
|
|
157
|
+
lastCliScan: { id: "scan-1", commitSha: "a".repeat(40), reason: "branch_mismatch:main:unregistered" },
|
|
158
|
+
fixable: true,
|
|
159
|
+
});
|
|
160
|
+
strict_1.default.match(line, /\(reason-string fallback\)/);
|
|
161
|
+
});
|
|
162
|
+
(0, node_test_1.it)("reports no held scan and no tracked branch plainly", () => {
|
|
163
|
+
const line = (0, deep_scan_1.describeHeldScanDebugInfo)({ trackedBranch: null, lastCliScan: null, fixable: null });
|
|
164
|
+
strict_1.default.match(line, /tracked branch=none/);
|
|
165
|
+
strict_1.default.match(line, /no held CLI scan/);
|
|
166
|
+
strict_1.default.match(line, /fixable=n\/a/);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
(0, node_test_1.describe)("describeLastUploadStatus — the hook's held-reason file feeding deep-scan-status", () => {
|
|
170
|
+
(0, node_test_1.it)("reports a held upload with its reason", () => {
|
|
171
|
+
const line = (0, deep_scan_1.describeLastUploadStatus)({ applied: false, reason: "branch_mismatch:feature/x:unregistered" });
|
|
172
|
+
strict_1.default.match(line, /^Your last commit upload was held: /);
|
|
173
|
+
strict_1.default.match(line, /no tracked branch is recorded/i);
|
|
174
|
+
});
|
|
175
|
+
(0, node_test_1.it)("reports nothing when the last recorded upload applied", () => {
|
|
176
|
+
strict_1.default.equal((0, deep_scan_1.describeLastUploadStatus)({ applied: true, reason: "clean_tracked_branch" }), null);
|
|
177
|
+
});
|
|
178
|
+
(0, node_test_1.it)("reports nothing when there's no local state at all", () => {
|
|
179
|
+
strict_1.default.equal((0, deep_scan_1.describeLastUploadStatus)(null), null);
|
|
180
|
+
strict_1.default.equal((0, deep_scan_1.describeLastUploadStatus)(undefined), null);
|
|
181
|
+
});
|
|
182
|
+
(0, node_test_1.it)("reports nothing when applied is missing (mid-upload, or the run never resolved)", () => {
|
|
183
|
+
strict_1.default.equal((0, deep_scan_1.describeLastUploadStatus)({ reason: "dirty_checkout" }), null);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
(0, node_test_1.describe)("describeTrackedBranchNotRecorded", () => {
|
|
187
|
+
(0, node_test_1.it)("says so on its own line and gives the one command to fix it, when none is recorded", () => {
|
|
188
|
+
const line = (0, deep_scan_1.describeTrackedBranchNotRecorded)("none", "validation-org/validation-repo");
|
|
189
|
+
strict_1.default.match(line, /^No tracked branch is recorded for validation-org\/validation-repo\./);
|
|
190
|
+
strict_1.default.match(line, /`kodingo init`/);
|
|
191
|
+
});
|
|
192
|
+
(0, node_test_1.it)("adds nothing when a tracked branch already exists (match or mismatch)", () => {
|
|
193
|
+
strict_1.default.equal((0, deep_scan_1.describeTrackedBranchNotRecorded)("match", "org/repo"), null);
|
|
194
|
+
strict_1.default.equal((0, deep_scan_1.describeTrackedBranchNotRecorded)("mismatch", "org/repo"), null);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
(0, node_test_1.describe)("describeApplyReason", () => {
|
|
198
|
+
(0, node_test_1.it)("maps stale_full_tree (the server's reapply refusal) to an actionable sentence", () => {
|
|
199
|
+
const { sentence, nextStep } = (0, deep_scan_1.describeApplyReason)("stale_full_tree");
|
|
200
|
+
strict_1.default.match(sentence, /full-repository scan/i);
|
|
201
|
+
strict_1.default.match(sentence, /no longer the tracked branch's current head/i);
|
|
202
|
+
strict_1.default.match(nextStep, /kodingo deep-scan/);
|
|
203
|
+
strict_1.default.match(nextStep, /init --force/);
|
|
204
|
+
});
|
|
205
|
+
(0, node_test_1.it)("maps dirty_checkout to an actionable sentence", () => {
|
|
206
|
+
const { sentence, nextStep } = (0, deep_scan_1.describeApplyReason)("dirty_checkout");
|
|
207
|
+
strict_1.default.match(sentence, /uncommitted changes/i);
|
|
208
|
+
strict_1.default.match(nextStep, /commit or stash/i);
|
|
209
|
+
});
|
|
210
|
+
(0, node_test_1.it)("maps detached_head to an actionable sentence", () => {
|
|
211
|
+
const { sentence, nextStep } = (0, deep_scan_1.describeApplyReason)("detached_head");
|
|
212
|
+
strict_1.default.match(sentence, /detached head/i);
|
|
213
|
+
strict_1.default.match(nextStep, /check out a branch/i);
|
|
214
|
+
});
|
|
215
|
+
(0, node_test_1.it)("maps an unregistered branch mismatch", () => {
|
|
216
|
+
const { sentence, nextStep } = (0, deep_scan_1.describeApplyReason)("branch_mismatch:main:unregistered");
|
|
217
|
+
strict_1.default.match(sentence, /no tracked branch is recorded/i);
|
|
218
|
+
strict_1.default.match(nextStep, /kodingo init/);
|
|
219
|
+
});
|
|
220
|
+
(0, node_test_1.it)("maps a real branch mismatch naming both branches and the switch/admin next step", () => {
|
|
221
|
+
const { sentence, nextStep } = (0, deep_scan_1.describeApplyReason)("branch_mismatch:feature/x:main");
|
|
222
|
+
strict_1.default.match(sentence, /tracked branch is "main"/);
|
|
223
|
+
strict_1.default.match(sentence, /ran on "feature\/x"/);
|
|
224
|
+
strict_1.default.match(nextStep, /switch to "main"/i);
|
|
225
|
+
strict_1.default.match(nextStep, /org admin/i);
|
|
226
|
+
});
|
|
227
|
+
(0, node_test_1.it)("maps clean_tracked_branch to an empty next step", () => {
|
|
228
|
+
const { sentence, nextStep } = (0, deep_scan_1.describeApplyReason)("clean_tracked_branch");
|
|
229
|
+
strict_1.default.equal(sentence, "Applied.");
|
|
230
|
+
strict_1.default.equal(nextStep, "");
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
(0, node_test_1.describe)("buildUploadSummary", () => {
|
|
234
|
+
(0, node_test_1.it)("reports read/upload/already-known counts accurately, matching the production regression", () => {
|
|
235
|
+
const summary = (0, deep_scan_1.buildUploadSummary)(165, 2, 163, "4 short evidence excerpts, each capped at 200 characters");
|
|
236
|
+
strict_1.default.match(summary, /165 files read locally/);
|
|
237
|
+
strict_1.default.match(summary, /2 will upload/);
|
|
238
|
+
strict_1.default.match(summary, /163 already known to Kortex/);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
(0, node_test_1.describe)("renderScanStatus — never calls a GitHub backup record a CLI scan", () => {
|
|
242
|
+
(0, node_test_1.it)("a project with a real CLI scan: shows the local-scan line, omits the GitHub line", () => {
|
|
243
|
+
const lines = (0, deep_scan_1.renderScanStatus)({
|
|
244
|
+
coverage: 1, source: "cli",
|
|
245
|
+
lastCliScan: { commitSha: "b".repeat(40), applied: true, reason: "clean_tracked_branch", entityCount: 12, edgeCount: 5, fileCount: 2, completedAt: "2026-11-03T01:00:00.000Z" },
|
|
246
|
+
lastGithubScan: null,
|
|
247
|
+
});
|
|
248
|
+
strict_1.default.equal(lines[0], "Coverage: 100% (local scan)");
|
|
249
|
+
strict_1.default.match(lines[1], /^Last local scan: commit b{12} at 2026-11-03T01:00:00\.000Z — applied \(12 entities, 5 edges, 2 files\)\.$/);
|
|
250
|
+
strict_1.default.equal(lines.some((l) => l.startsWith("Last GitHub read:")), false);
|
|
251
|
+
strict_1.default.equal(lines.some((l) => l.includes("Last CLI scan")), false, "must never use the old, source-blind wording");
|
|
252
|
+
});
|
|
253
|
+
(0, node_test_1.it)("a project read only through GitHub: shows the GitHub-read line, never prints it as a CLI scan", () => {
|
|
254
|
+
const lines = (0, deep_scan_1.renderScanStatus)({
|
|
255
|
+
coverage: 1, source: "github",
|
|
256
|
+
lastCliScan: null,
|
|
257
|
+
lastGithubScan: { commitSha: "a".repeat(40), completedAt: "2026-11-03T05:00:00.000Z" },
|
|
258
|
+
});
|
|
259
|
+
strict_1.default.equal(lines[0], "Coverage: 100% (read through GitHub)");
|
|
260
|
+
strict_1.default.equal(lines[1], "No local scan yet.");
|
|
261
|
+
strict_1.default.match(lines[2], /^Last GitHub read: commit a{12} at 2026-11-03T05:00:00\.000Z\.$/);
|
|
262
|
+
});
|
|
263
|
+
(0, node_test_1.it)("neither a CLI nor a GitHub scan has run: no scan yet, no local scan yet, no GitHub line", () => {
|
|
264
|
+
const lines = (0, deep_scan_1.renderScanStatus)({ coverage: 0, source: null, lastCliScan: null, lastGithubScan: null });
|
|
265
|
+
strict_1.default.equal(lines[0], "Coverage: 0% (no scan yet)");
|
|
266
|
+
strict_1.default.equal(lines[1], "No local scan yet.");
|
|
267
|
+
strict_1.default.equal(lines.length, 2);
|
|
268
|
+
});
|
|
269
|
+
(0, node_test_1.it)("a held CLI scan is reported as held, with its reason — not as applied", () => {
|
|
270
|
+
const lines = (0, deep_scan_1.renderScanStatus)({
|
|
271
|
+
coverage: 0.5, source: "cli",
|
|
272
|
+
lastCliScan: { commitSha: "c".repeat(40), applied: false, reason: "dirty_checkout", entityCount: 0, edgeCount: 0, fileCount: 0, completedAt: "2026-11-03T02:00:00.000Z" },
|
|
273
|
+
lastGithubScan: null,
|
|
274
|
+
});
|
|
275
|
+
strict_1.default.match(lines[1], /^Last local scan: commit c{12} at 2026-11-03T02:00:00\.000Z — held\. Your working tree has uncommitted changes\./);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
(0, node_test_1.describe)("shouldSkipIncrementalScan", () => {
|
|
279
|
+
(0, node_test_1.it)("skips only on a confirmed mismatch", () => {
|
|
280
|
+
strict_1.default.equal((0, deep_scan_1.shouldSkipIncrementalScan)("mismatch"), true);
|
|
281
|
+
});
|
|
282
|
+
(0, node_test_1.it)("never skips on a match or when nothing is tracked yet", () => {
|
|
283
|
+
strict_1.default.equal((0, deep_scan_1.shouldSkipIncrementalScan)("match"), false);
|
|
284
|
+
strict_1.default.equal((0, deep_scan_1.shouldSkipIncrementalScan)("none"), false);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
(0, node_test_1.describe)("buildLocalReadSummary", () => {
|
|
288
|
+
(0, node_test_1.it)("reports only what's known locally — no upload/already-known split, since no session (and so no server data) exists yet", () => {
|
|
289
|
+
const summary = (0, deep_scan_1.buildLocalReadSummary)(165, "4 short evidence excerpts, each capped at 200 characters");
|
|
290
|
+
strict_1.default.match(summary, /165 files read locally/);
|
|
291
|
+
strict_1.default.match(summary, /checked against what Kortex already holds/);
|
|
292
|
+
strict_1.default.equal(/will upload/.test(summary), false);
|
|
293
|
+
strict_1.default.equal(/already known to Kortex/.test(summary), false);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/** Validation fixtures only; no production or customer identifiers.
|
|
7
|
+
* Covers the "never scan outdated code" guard: a full-tree scan (init's
|
|
8
|
+
* first scan, or `kodingo deep-scan` without --changed) must refuse when
|
|
9
|
+
* HEAD is behind, ahead of, or diverged from origin/<branch> — checked via
|
|
10
|
+
* a real `git fetch` against a real local bare repo acting as origin, with
|
|
11
|
+
* no network involved. --changed (the hook's exact invocation) must never
|
|
12
|
+
* be affected, and --dry-run must only warn, never refuse, since it uploads
|
|
13
|
+
* nothing.
|
|
14
|
+
*/
|
|
15
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
16
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
18
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
19
|
+
const node_child_process_1 = require("node:child_process");
|
|
20
|
+
const node_test_1 = require("node:test");
|
|
21
|
+
const deep_scan_1 = require("../commands/deep-scan");
|
|
22
|
+
function fakeFetch(responses) {
|
|
23
|
+
const calls = [];
|
|
24
|
+
const fn = async (url, init) => {
|
|
25
|
+
calls.push({ url, init });
|
|
26
|
+
const next = responses.shift();
|
|
27
|
+
if (!next)
|
|
28
|
+
throw new Error(`checkoutFreshnessGuard test: no mock response left for ${url}`);
|
|
29
|
+
return { ok: (next.status ?? 200) < 300, status: next.status ?? 200, json: async () => next.body };
|
|
30
|
+
};
|
|
31
|
+
return { fn, calls };
|
|
32
|
+
}
|
|
33
|
+
function withFetch(responses, run) {
|
|
34
|
+
const original = global.fetch;
|
|
35
|
+
const { fn, calls } = fakeFetch(responses);
|
|
36
|
+
global.fetch = fn;
|
|
37
|
+
return run(calls).finally(() => { global.fetch = original; });
|
|
38
|
+
}
|
|
39
|
+
function withConsoleCapture(run) {
|
|
40
|
+
const logs = { log: [], warn: [] };
|
|
41
|
+
const originalLog = console.log;
|
|
42
|
+
const originalWarn = console.warn;
|
|
43
|
+
console.log = (...args) => { logs.log.push(args.join(" ")); };
|
|
44
|
+
console.warn = (...args) => { logs.warn.push(args.join(" ")); };
|
|
45
|
+
return run(logs).finally(() => { console.log = originalLog; console.warn = originalWarn; });
|
|
46
|
+
}
|
|
47
|
+
function configureIdentity(root) {
|
|
48
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.email", "test@example.invalid"]);
|
|
49
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.name", "Validation Test"]);
|
|
50
|
+
}
|
|
51
|
+
/** A real local bare repo as origin, and a clone (the checkout under test)
|
|
52
|
+
* pushed up to date with it — no network involved anywhere. */
|
|
53
|
+
function makeRepoWithOrigin() {
|
|
54
|
+
const originRoot = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-freshness-origin-"));
|
|
55
|
+
(0, node_child_process_1.execFileSync)("git", ["init", "-q", "--bare", "-b", "main", originRoot]);
|
|
56
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-freshness-work-"));
|
|
57
|
+
(0, node_child_process_1.execFileSync)("git", ["clone", "-q", originRoot, root]);
|
|
58
|
+
configureIdentity(root);
|
|
59
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "page.ts"), "export function Page() { return 1; }");
|
|
60
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "add", "."]);
|
|
61
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "commit", "-qm", "fixture"]);
|
|
62
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "push", "-q", "origin", "main"]);
|
|
63
|
+
return { root, originRoot };
|
|
64
|
+
}
|
|
65
|
+
/** Pushes one more commit to origin from a throwaway second clone, so the
|
|
66
|
+
* fixture's `root` checkout falls behind without `root` itself touching it. */
|
|
67
|
+
function pushExtraCommitToOrigin(originRoot) {
|
|
68
|
+
const second = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-freshness-second-"));
|
|
69
|
+
(0, node_child_process_1.execFileSync)("git", ["clone", "-q", originRoot, second]);
|
|
70
|
+
configureIdentity(second);
|
|
71
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(second, "extra.ts"), "export const extra = 1;\n");
|
|
72
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", second, "add", "."]);
|
|
73
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", second, "commit", "-qm", "extra, pushed from elsewhere"]);
|
|
74
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", second, "push", "-q", "origin", "main"]);
|
|
75
|
+
}
|
|
76
|
+
function commitLocallyWithoutPushing(root) {
|
|
77
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "local-only.ts"), "export const localOnly = 1;\n");
|
|
78
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "add", "."]);
|
|
79
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "commit", "-qm", "unpushed local work"]);
|
|
80
|
+
}
|
|
81
|
+
// A function, not a shared array constant — fakeFetch's queue mutates
|
|
82
|
+
// (shift()s) whatever array it's given, so a plain shared constant would be
|
|
83
|
+
// drained by the first test that uses it and come up empty for the next.
|
|
84
|
+
function fullScanResponses() {
|
|
85
|
+
return [
|
|
86
|
+
{ body: { excerptsEnabled: true } }, // GET /deep-scan/policy
|
|
87
|
+
{ body: { sessionId: "sess-1", heldBlobShas: [], limits: { filesPerBatch: 200 } } }, // POST /deep-scan/sessions
|
|
88
|
+
{ body: { accepted: 1 } }, // POST /deep-scan/sessions/:id/files
|
|
89
|
+
{ body: { runId: "run-1" } }, // POST /deep-scan/sessions/:id/finalize
|
|
90
|
+
{ body: { state: "completed", applied: true, entity_count: 1, edge_count: 0, file_count: 1 } }, // GET /deep-scan/runs/:id
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
(0, node_test_1.describe)("checkout freshness guard — full-tree scans only", () => {
|
|
94
|
+
let oldToken;
|
|
95
|
+
(0, node_test_1.beforeEach)(() => { oldToken = process.env.KODINGO_TOKEN; process.env.KODINGO_TOKEN = "validation-token"; });
|
|
96
|
+
(0, node_test_1.afterEach)(() => { if (oldToken === undefined)
|
|
97
|
+
delete process.env.KODINGO_TOKEN;
|
|
98
|
+
else
|
|
99
|
+
process.env.KODINGO_TOKEN = oldToken; });
|
|
100
|
+
(0, node_test_1.it)("up to date: proceeds and prints the summary line, via a real git fetch against a real origin", async () => {
|
|
101
|
+
const { root } = makeRepoWithOrigin();
|
|
102
|
+
await withConsoleCapture((logs) => withFetch(fullScanResponses(), async (calls) => {
|
|
103
|
+
await strict_1.default.doesNotReject(() => (0, deep_scan_1.deepScanCommand)({ repo: root, yes: true }));
|
|
104
|
+
strict_1.default.equal(calls.length, 5, `expected the normal full-scan call sequence, got: ${JSON.stringify(calls.map((c) => c.url))}`);
|
|
105
|
+
strict_1.default.ok(logs.log.some((l) => /^Reading main at [0-9a-f]+, up to date with origin\/main\.$/.test(l)), `expected the up-to-date summary line, got: ${JSON.stringify(logs.log)}`);
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
(0, node_test_1.it)("behind: refuses before any Kortex API call is made", async () => {
|
|
109
|
+
const { root, originRoot } = makeRepoWithOrigin();
|
|
110
|
+
pushExtraCommitToOrigin(originRoot);
|
|
111
|
+
await withFetch([], async (calls) => {
|
|
112
|
+
await strict_1.default.rejects(() => (0, deep_scan_1.deepScanCommand)({ repo: root, yes: true }), /Your checkout of main is 1 commit behind origin\/main, so Kortex would read outdated code\. Run `git pull` and try again\./);
|
|
113
|
+
strict_1.default.equal(calls.length, 0, `expected zero Kortex API calls, got: ${JSON.stringify(calls.map((c) => c.url))}`);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
(0, node_test_1.it)("ahead: refuses with the unpushed-commits message", async () => {
|
|
117
|
+
const { root } = makeRepoWithOrigin();
|
|
118
|
+
commitLocallyWithoutPushing(root);
|
|
119
|
+
await withFetch([], async (calls) => {
|
|
120
|
+
await strict_1.default.rejects(() => (0, deep_scan_1.deepScanCommand)({ repo: root, yes: true }), /Your checkout of main has 1 commit that is not pushed\. Push first so Kortex reads the same code GitHub has\./);
|
|
121
|
+
strict_1.default.equal(calls.length, 0);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
(0, node_test_1.it)("diverged: refuses and reports both counts", async () => {
|
|
125
|
+
const { root, originRoot } = makeRepoWithOrigin();
|
|
126
|
+
pushExtraCommitToOrigin(originRoot);
|
|
127
|
+
commitLocallyWithoutPushing(root);
|
|
128
|
+
await withFetch([], async (calls) => {
|
|
129
|
+
await strict_1.default.rejects(() => (0, deep_scan_1.deepScanCommand)({ repo: root, yes: true }), /Your checkout of main has diverged from origin\/main: 1 commit not pushed and 1 commit behind\./);
|
|
130
|
+
strict_1.default.equal(calls.length, 0);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
(0, node_test_1.it)("fetch failure (no reachable origin): refuses under --yes without guessing, and makes no Kortex API call", async () => {
|
|
134
|
+
const { root } = makeRepoWithOrigin();
|
|
135
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "remote", "set-url", "origin", node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-nonexistent-origin-does-not-exist")]);
|
|
136
|
+
await withFetch([], async (calls) => {
|
|
137
|
+
await strict_1.default.rejects(() => (0, deep_scan_1.deepScanCommand)({ repo: root, yes: true }), /Couldn't check whether this checkout is up to date \(.+\)\. Refusing to guess under --yes\./);
|
|
138
|
+
strict_1.default.equal(calls.length, 0);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
(0, node_test_1.it)("fetch failure, interactive (non-TTY defaults to declining, same as answering \"no\"): refuses", async () => {
|
|
142
|
+
const { root } = makeRepoWithOrigin();
|
|
143
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "remote", "set-url", "origin", node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-nonexistent-origin-does-not-exist")]);
|
|
144
|
+
await withFetch([], async (calls) => {
|
|
145
|
+
await strict_1.default.rejects(() => (0, deep_scan_1.deepScanCommand)({ repo: root, yes: false }), /Couldn't check whether this checkout is up to date/);
|
|
146
|
+
strict_1.default.equal(calls.length, 0);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
(0, node_test_1.it)("the hook's exact invocation (--changed) never runs the freshness check, even when badly behind", async () => {
|
|
150
|
+
const { root } = makeRepoWithOrigin();
|
|
151
|
+
// A second, unpushed commit — this is "badly behind/ahead" from the
|
|
152
|
+
// freshness guard's point of view, and also gives --changed a real
|
|
153
|
+
// diff-tree parent to scope against (a root commit alone has none).
|
|
154
|
+
commitLocallyWithoutPushing(root);
|
|
155
|
+
await withFetch([
|
|
156
|
+
{ body: { outcome: "match", trackedBranch: "main" } }, // POST /deep-scan/branch/settle
|
|
157
|
+
...fullScanResponses(),
|
|
158
|
+
], async (calls) => {
|
|
159
|
+
await strict_1.default.doesNotReject(() => (0, deep_scan_1.deepScanCommand)({ repo: root, changed: true, yes: true }));
|
|
160
|
+
strict_1.default.equal(calls.length, 6);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
(0, node_test_1.it)("--dry-run: a stale checkout is reported as a warning, not a refusal, and the dry-run still completes (it uploads nothing)", async () => {
|
|
164
|
+
const { root, originRoot } = makeRepoWithOrigin();
|
|
165
|
+
pushExtraCommitToOrigin(originRoot);
|
|
166
|
+
const outFile = node_path_1.default.join(node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-freshness-dryrun-")), "payload.json");
|
|
167
|
+
await withConsoleCapture((logs) => withFetch([], async (calls) => {
|
|
168
|
+
await strict_1.default.doesNotReject(() => (0, deep_scan_1.deepScanCommand)({ repo: root, dryRun: outFile, yes: true }));
|
|
169
|
+
strict_1.default.equal(calls.length, 0, "dry-run never calls the Kortex API");
|
|
170
|
+
strict_1.default.ok(logs.warn.some((l) => /is 1 commit behind origin\/main, so Kortex would read outdated code/.test(l)), `expected a stale-checkout warning, got: ${JSON.stringify(logs.warn)}`);
|
|
171
|
+
strict_1.default.ok(node_fs_1.default.existsSync(outFile), "the dry-run payload should still be written");
|
|
172
|
+
}));
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
(0, node_test_1.describe)("decideFreshnessAction (pure)", () => {
|
|
176
|
+
const branch = "main";
|
|
177
|
+
(0, node_test_1.it)("up to date always proceeds, with the summary note", () => {
|
|
178
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "up-to-date", shortSha: "abc1234" }, branch, dryRun: false, yes: false });
|
|
179
|
+
strict_1.default.deepEqual(decision, { action: "proceed", note: "Reading main at abc1234, up to date with origin/main." });
|
|
180
|
+
});
|
|
181
|
+
(0, node_test_1.it)("behind refuses outside dry-run", () => {
|
|
182
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "behind", behind: 3 }, branch, dryRun: false, yes: true });
|
|
183
|
+
strict_1.default.equal(decision.action, "refuse");
|
|
184
|
+
if (decision.action === "refuse")
|
|
185
|
+
strict_1.default.match(decision.message, /is 3 commits behind origin\/main/);
|
|
186
|
+
});
|
|
187
|
+
(0, node_test_1.it)("behind warns under --dry-run instead of refusing", () => {
|
|
188
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "behind", behind: 1 }, branch, dryRun: true, yes: false });
|
|
189
|
+
strict_1.default.equal(decision.action, "warn");
|
|
190
|
+
});
|
|
191
|
+
(0, node_test_1.it)("unknown + --yes refuses, never guessing", () => {
|
|
192
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "unknown", reason: "offline" }, branch, dryRun: false, yes: true });
|
|
193
|
+
strict_1.default.equal(decision.action, "refuse");
|
|
194
|
+
if (decision.action === "refuse")
|
|
195
|
+
strict_1.default.match(decision.message, /Refusing to guess under --yes/);
|
|
196
|
+
});
|
|
197
|
+
(0, node_test_1.it)("unknown + interactive decline (promptAnswerYes: false) refuses", () => {
|
|
198
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "unknown", reason: "offline" }, branch, dryRun: false, yes: false, promptAnswerYes: false });
|
|
199
|
+
strict_1.default.equal(decision.action, "refuse");
|
|
200
|
+
});
|
|
201
|
+
(0, node_test_1.it)("unknown + interactive accept (promptAnswerYes: true) proceeds", () => {
|
|
202
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "unknown", reason: "offline" }, branch, dryRun: false, yes: false, promptAnswerYes: true });
|
|
203
|
+
strict_1.default.deepEqual(decision, { action: "proceed" });
|
|
204
|
+
});
|
|
205
|
+
(0, node_test_1.it)("unknown warns under --dry-run regardless of --yes", () => {
|
|
206
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "unknown", reason: "offline" }, branch, dryRun: true, yes: true });
|
|
207
|
+
strict_1.default.equal(decision.action, "warn");
|
|
208
|
+
});
|
|
209
|
+
(0, node_test_1.it)("ahead message correctly pluralizes a single commit", () => {
|
|
210
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "ahead", ahead: 1 }, branch, dryRun: false, yes: true });
|
|
211
|
+
strict_1.default.equal(decision.action, "refuse");
|
|
212
|
+
if (decision.action === "refuse")
|
|
213
|
+
strict_1.default.match(decision.message, /has 1 commit that is not pushed/);
|
|
214
|
+
});
|
|
215
|
+
(0, node_test_1.it)("ahead message correctly pluralizes multiple commits", () => {
|
|
216
|
+
const decision = (0, deep_scan_1.decideFreshnessAction)({ check: { outcome: "ahead", ahead: 2 }, branch, dryRun: false, yes: true });
|
|
217
|
+
strict_1.default.equal(decision.action, "refuse");
|
|
218
|
+
if (decision.action === "refuse")
|
|
219
|
+
strict_1.default.match(decision.message, /has 2 commits that are not pushed/);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/** Validation fixtures only; no production or customer identifiers.
|
|
7
|
+
* Proves nothing that needs the server (the upload session — which sends
|
|
8
|
+
* every file path, size, and blob SHA — and everything after it) happens
|
|
9
|
+
* before consent is granted. Uses a fake fetch client (same hand-rolled
|
|
10
|
+
* stub pattern as deepScanNetworkFlows.test.ts) that is only ever given
|
|
11
|
+
* exactly as many canned responses as the correctly-ordered flow should
|
|
12
|
+
* need — any extra, premature request throws "no mock response left",
|
|
13
|
+
* which fails the test.
|
|
14
|
+
*/
|
|
15
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
16
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
18
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
19
|
+
const node_child_process_1 = require("node:child_process");
|
|
20
|
+
const node_test_1 = require("node:test");
|
|
21
|
+
const deep_scan_1 = require("../commands/deep-scan");
|
|
22
|
+
function fakeFetch(responses) {
|
|
23
|
+
const calls = [];
|
|
24
|
+
const fn = async (url, init) => {
|
|
25
|
+
calls.push({ url, init });
|
|
26
|
+
const next = responses.shift();
|
|
27
|
+
if (!next)
|
|
28
|
+
throw new Error(`deepScanConsentOrdering test: no mock response left for ${url} — a request was made before consent (or beyond the expected flow)`);
|
|
29
|
+
return { ok: (next.status ?? 200) < 300, status: next.status ?? 200, json: async () => next.body };
|
|
30
|
+
};
|
|
31
|
+
return { fn, calls };
|
|
32
|
+
}
|
|
33
|
+
function withFetch(responses, run) {
|
|
34
|
+
const original = global.fetch;
|
|
35
|
+
const { fn, calls } = fakeFetch(responses);
|
|
36
|
+
global.fetch = fn;
|
|
37
|
+
return run(calls).finally(() => { global.fetch = original; });
|
|
38
|
+
}
|
|
39
|
+
function makeRepo() {
|
|
40
|
+
// A real local bare repo as origin (not the usual fake github.com remote
|
|
41
|
+
// URL used elsewhere in this file's sibling tests) — the checkout
|
|
42
|
+
// freshness guard now runs a real `git fetch origin main` ahead of the
|
|
43
|
+
// consent summary for every full-tree scan this file exercises, and a
|
|
44
|
+
// fake unreachable remote would make that fetch fail for real (and, worse,
|
|
45
|
+
// attempt a real network call to github.com).
|
|
46
|
+
const originRoot = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-consent-order-origin-"));
|
|
47
|
+
(0, node_child_process_1.execFileSync)("git", ["init", "-q", "--bare", "-b", "main", originRoot]);
|
|
48
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-consent-order-"));
|
|
49
|
+
(0, node_child_process_1.execFileSync)("git", ["clone", "-q", originRoot, root]);
|
|
50
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.email", "test@example.invalid"]);
|
|
51
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.name", "Validation Test"]);
|
|
52
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "page.ts"), "export function Page() { return 1; }");
|
|
53
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "add", "."]);
|
|
54
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "commit", "-qm", "fixture"]);
|
|
55
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "push", "-q", "origin", "main"]);
|
|
56
|
+
return root;
|
|
57
|
+
}
|
|
58
|
+
function withConsoleLog(run) {
|
|
59
|
+
const logs = [];
|
|
60
|
+
const original = console.log;
|
|
61
|
+
console.log = (...args) => { logs.push(args.join(" ")); };
|
|
62
|
+
return run(logs).finally(() => { console.log = original; });
|
|
63
|
+
}
|
|
64
|
+
(0, node_test_1.describe)("deepScanCommand — nothing leaves the machine before consent", () => {
|
|
65
|
+
(0, node_test_1.it)("interactive mode (non-TTY declines automatically): only the policy check happens, nothing manifest-bearing is ever sent", async () => {
|
|
66
|
+
const root = makeRepo();
|
|
67
|
+
const oldToken = process.env.KODINGO_TOKEN;
|
|
68
|
+
process.env.KODINGO_TOKEN = "validation-token";
|
|
69
|
+
try {
|
|
70
|
+
await withConsoleLog((logs) => withFetch(
|
|
71
|
+
// Exactly one response: the org excerpt-policy check, which carries
|
|
72
|
+
// no repo/file data and is needed to decide what extraction
|
|
73
|
+
// captures. If the (buggy) old order were still in place, the
|
|
74
|
+
// session-creation call would consume a second, non-existent
|
|
75
|
+
// mock response and throw.
|
|
76
|
+
[{ body: { excerptsEnabled: true } }], async (calls) => {
|
|
77
|
+
await (0, deep_scan_1.deepScanCommand)({ repo: root, yes: false });
|
|
78
|
+
strict_1.default.equal(calls.length, 1, `expected only the policy call, got: ${JSON.stringify(calls.map((c) => c.url))}`);
|
|
79
|
+
strict_1.default.ok(logs.some((l) => l.includes("Upload cancelled.")), `expected a cancellation log, got: ${JSON.stringify(logs)}`);
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
if (oldToken === undefined)
|
|
84
|
+
delete process.env.KODINGO_TOKEN;
|
|
85
|
+
else
|
|
86
|
+
process.env.KODINGO_TOKEN = oldToken;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
(0, node_test_1.it)("--yes: consent is local-only and granted before any server call, then the full upload still completes in order", async () => {
|
|
90
|
+
const root = makeRepo();
|
|
91
|
+
const oldToken = process.env.KODINGO_TOKEN;
|
|
92
|
+
process.env.KODINGO_TOKEN = "validation-token";
|
|
93
|
+
try {
|
|
94
|
+
await withConsoleLog((logs) => withFetch([
|
|
95
|
+
{ body: { excerptsEnabled: true } }, // GET /deep-scan/policy
|
|
96
|
+
{ body: { sessionId: "sess-1", heldBlobShas: [], limits: { filesPerBatch: 200 } } }, // POST /deep-scan/sessions
|
|
97
|
+
{ body: { accepted: 1 } }, // POST /deep-scan/sessions/:id/files
|
|
98
|
+
{ body: { runId: "run-1" } }, // POST /deep-scan/sessions/:id/finalize
|
|
99
|
+
{ body: { state: "completed", applied: true, entity_count: 1, edge_count: 0, file_count: 1 } }, // GET /deep-scan/runs/:id
|
|
100
|
+
], async (calls) => {
|
|
101
|
+
await (0, deep_scan_1.deepScanCommand)({ repo: root, yes: true });
|
|
102
|
+
strict_1.default.equal(calls.length, 5, `expected exactly 5 calls, got: ${JSON.stringify(calls.map((c) => c.url))}`);
|
|
103
|
+
strict_1.default.match(calls[0].url, /\/deep-scan\/policy$/);
|
|
104
|
+
strict_1.default.match(calls[1].url, /\/deep-scan\/sessions$/);
|
|
105
|
+
const manifest = JSON.parse(calls[1].init.body);
|
|
106
|
+
strict_1.default.equal(manifest.files.length, 1);
|
|
107
|
+
strict_1.default.equal(manifest.files[0].path, "page.ts");
|
|
108
|
+
strict_1.default.match(calls[2].url, /\/deep-scan\/sessions\/sess-1\/files$/);
|
|
109
|
+
strict_1.default.match(calls[3].url, /\/deep-scan\/sessions\/sess-1\/finalize$/);
|
|
110
|
+
strict_1.default.match(calls[4].url, /\/deep-scan\/runs\/run-1$/);
|
|
111
|
+
strict_1.default.ok(logs.some((l) => /Deep scan applied: 1 entities, 0 edges, 1 files/.test(l)), `expected an applied summary line, got: ${JSON.stringify(logs)}`);
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
if (oldToken === undefined)
|
|
116
|
+
delete process.env.KODINGO_TOKEN;
|
|
117
|
+
else
|
|
118
|
+
process.env.KODINGO_TOKEN = oldToken;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|