kodingo-cli 1.4.1 → 1.4.3
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 +1 -1
- package/dist/__tests__/checkoutFreshnessGuard.test.js +221 -0
- package/dist/__tests__/cliFixes.test.js +243 -0
- package/dist/__tests__/cliScanFixes.test.js +117 -0
- package/dist/__tests__/deepScanConsentOrdering.test.js +10 -2
- package/dist/__tests__/repoFilterFollowup.test.js +162 -0
- package/dist/adapters/cloud-adapter/cloud-persistence.js +14 -8
- package/dist/cli.js +1 -1
- package/dist/commands/check-rules.js +2 -16
- package/dist/commands/context.js +6 -17
- package/dist/commands/deep-scan.js +181 -8
- package/dist/commands/doctor.js +13 -8
- package/dist/commands/guardrails.js +1 -13
- package/dist/commands/init.js +11 -7
- package/dist/commands/query-memory.js +5 -16
- package/dist/commands/session-brief.js +1 -13
- package/dist/utils/persistence-config.js +68 -18
- package/package.json +1 -1
- package/dist/commands/deep-scan-process.js +0 -22
|
@@ -272,7 +272,7 @@ const repository = "validation-org/validation-repo";
|
|
|
272
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
273
|
lastGithubScan: null,
|
|
274
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\./);
|
|
275
|
+
strict_1.default.match(lines[1], /^Last local scan: commit c{12} at 2026-11-03T02:00:00\.000Z — held \(0 entities\)\. Your working tree has uncommitted changes\./);
|
|
276
276
|
});
|
|
277
277
|
});
|
|
278
278
|
(0, node_test_1.describe)("shouldSkipIncrementalScan", () => {
|
|
@@ -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,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
/** Invented, local fixtures for CLI configuration and scan outcomes. */
|
|
40
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
41
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
42
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
43
|
+
const node_child_process_1 = require("node:child_process");
|
|
44
|
+
const node_test_1 = require("node:test");
|
|
45
|
+
const persistence_config_1 = require("../utils/persistence-config");
|
|
46
|
+
function fixture(run) {
|
|
47
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(process.cwd(), ".cli-fixture-"));
|
|
48
|
+
try {
|
|
49
|
+
run(root);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
node_fs_1.default.rmSync(root, { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function config(workspaces) {
|
|
56
|
+
return { mode: "cloud", apiUrl: "https://example.invalid", workspaces };
|
|
57
|
+
}
|
|
58
|
+
function git(root, ...args) {
|
|
59
|
+
return (0, node_child_process_1.execFileSync)("git", ["-C", root, ...args], { encoding: "utf8" }).trim();
|
|
60
|
+
}
|
|
61
|
+
function repo(run) {
|
|
62
|
+
fixture(root => {
|
|
63
|
+
git(root, "init", "-q");
|
|
64
|
+
git(root, "config", "user.name", "Fixture");
|
|
65
|
+
git(root, "config", "user.email", "fixture@example.invalid");
|
|
66
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "source.ts"), "export const value = 1;\n");
|
|
67
|
+
git(root, "add", "source.ts");
|
|
68
|
+
git(root, "commit", "-qm", "fixture");
|
|
69
|
+
run(root);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
(0, node_test_1.describe)("nearest workspace lookup", () => {
|
|
73
|
+
const cases = [
|
|
74
|
+
["capitalized path", "Project", "Project"],
|
|
75
|
+
["case folded path", "Project", "project"],
|
|
76
|
+
["trailing slash", "Project/", "Project"],
|
|
77
|
+
["backslash key", "Project\\Nested", "Project/Nested"],
|
|
78
|
+
["parent directory", "Project", "Project/Nested"],
|
|
79
|
+
["deep parent directory", "Project", "Project/Nested/Deep"],
|
|
80
|
+
["nested entry", "Project/Nested", "Project/Nested/Deep"],
|
|
81
|
+
["case folded nested", "PROJECT/NESTED", "Project/Nested/Deep"],
|
|
82
|
+
["trailing slash nested", "Project/Nested/", "Project/Nested/Deep"],
|
|
83
|
+
["mixed slash and case", "PROJECT\\NESTED\\", "Project/Nested/Deep"],
|
|
84
|
+
];
|
|
85
|
+
for (const [label, key, cwd] of cases)
|
|
86
|
+
(0, node_test_1.it)(label, () => fixture(root => {
|
|
87
|
+
const keyPath = node_path_1.default.join(root, key);
|
|
88
|
+
const ws = config({ [keyPath]: { mode: "cloud", token: "fixture-token" } });
|
|
89
|
+
strict_1.default.equal((0, persistence_config_1.findWorkspaceEntry)(node_path_1.default.join(root, cwd), ws)?.token, "fixture-token");
|
|
90
|
+
strict_1.default.deepEqual(Object.keys(ws.workspaces), [keyPath]);
|
|
91
|
+
}));
|
|
92
|
+
(0, node_test_1.it)("nearest entry wins", () => fixture(root => {
|
|
93
|
+
const ws = config({ [node_path_1.default.join(root, "Project")]: { mode: "cloud", token: "parent" }, [node_path_1.default.join(root, "Project/Nested")]: { mode: "cloud", token: "nested" } });
|
|
94
|
+
strict_1.default.equal((0, persistence_config_1.findWorkspaceEntry)(node_path_1.default.join(root, "Project/Nested/Deep"), ws)?.token, "nested");
|
|
95
|
+
}));
|
|
96
|
+
(0, node_test_1.it)("no match returns null", () => fixture(root => {
|
|
97
|
+
strict_1.default.equal((0, persistence_config_1.findWorkspaceEntry)(node_path_1.default.join(root, "Other"), config({ [node_path_1.default.join(root, "Project")]: { mode: "cloud", token: "fixture" } })), null);
|
|
98
|
+
}));
|
|
99
|
+
(0, node_test_1.it)("symlink resolves to registered path", () => fixture(root => {
|
|
100
|
+
const target = node_path_1.default.join(root, "Target");
|
|
101
|
+
node_fs_1.default.mkdirSync(target);
|
|
102
|
+
node_fs_1.default.symlinkSync(target, node_path_1.default.join(root, "Alias"));
|
|
103
|
+
strict_1.default.equal((0, persistence_config_1.findWorkspaceEntry)(node_path_1.default.join(root, "Alias"), config({ [target]: { mode: "cloud", token: "fixture" } }))?.token, "fixture");
|
|
104
|
+
}));
|
|
105
|
+
(0, node_test_1.it)("registered symlink resolves to actual path", () => fixture(root => {
|
|
106
|
+
const target = node_path_1.default.join(root, "Target");
|
|
107
|
+
node_fs_1.default.mkdirSync(target);
|
|
108
|
+
const alias = node_path_1.default.join(root, "Alias");
|
|
109
|
+
node_fs_1.default.symlinkSync(target, alias);
|
|
110
|
+
strict_1.default.equal((0, persistence_config_1.findWorkspaceEntry)(target, config({ [alias]: { mode: "cloud", token: "fixture" } }))?.token, "fixture");
|
|
111
|
+
}));
|
|
112
|
+
});
|
|
113
|
+
(0, node_test_1.describe)("configuration file safety", () => {
|
|
114
|
+
(0, node_test_1.it)("writes a private directory and file atomically", { skip: process.platform === "win32" }, () => fixture(root => {
|
|
115
|
+
const script = `const c=require(${JSON.stringify(node_path_1.default.resolve("dist/utils/persistence-config.js"))}); c.writeConfig({mode:"cloud",apiUrl:"https://example.invalid"});`;
|
|
116
|
+
(0, node_child_process_1.execFileSync)(process.execPath, ["-e", script], { env: { ...process.env, HOME: root } });
|
|
117
|
+
const dir = node_path_1.default.join(root, ".kodingo");
|
|
118
|
+
strict_1.default.equal(node_fs_1.default.statSync(dir).mode & 0o077, 0);
|
|
119
|
+
strict_1.default.equal(node_fs_1.default.statSync(node_path_1.default.join(dir, "config.json")).mode & 0o077, 0);
|
|
120
|
+
strict_1.default.deepEqual(node_fs_1.default.readdirSync(dir), ["config.json"]);
|
|
121
|
+
}));
|
|
122
|
+
(0, node_test_1.it)("tightens old permissions and warns once", { skip: process.platform === "win32" }, () => fixture(root => {
|
|
123
|
+
const dir = node_path_1.default.join(root, ".kodingo");
|
|
124
|
+
node_fs_1.default.mkdirSync(dir, { mode: 0o755 });
|
|
125
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(dir, "config.json"), '{"mode":"cloud"}', { mode: 0o644 });
|
|
126
|
+
const script = `const c=require(${JSON.stringify(node_path_1.default.resolve("dist/utils/persistence-config.js"))}); c.readConfig(); c.readConfig();`;
|
|
127
|
+
const { spawnSync } = require("node:child_process");
|
|
128
|
+
const result = spawnSync(process.execPath, ["-e", script], { env: { ...process.env, HOME: root }, encoding: "utf8" });
|
|
129
|
+
strict_1.default.equal(result.status, 0);
|
|
130
|
+
strict_1.default.equal(result.stderr.trim().split("\n").length, 1);
|
|
131
|
+
strict_1.default.equal(node_fs_1.default.statSync(dir).mode & 0o077, 0);
|
|
132
|
+
strict_1.default.equal(node_fs_1.default.statSync(node_path_1.default.join(dir, "config.json")).mode & 0o077, 0);
|
|
133
|
+
}));
|
|
134
|
+
});
|
|
135
|
+
(0, node_test_1.describe)("cloud text query", () => {
|
|
136
|
+
(0, node_test_1.it)("sends q and repo without a proposed-only filter", async () => {
|
|
137
|
+
const original = global.fetch;
|
|
138
|
+
const token = process.env.KODINGO_API_TOKEN;
|
|
139
|
+
const url = process.env.KODINGO_API_URL;
|
|
140
|
+
process.env.KODINGO_API_TOKEN = "fixture-token";
|
|
141
|
+
process.env.KODINGO_API_URL = "https://example.invalid";
|
|
142
|
+
let requested = "";
|
|
143
|
+
global.fetch = (async (input) => { requested = input; return { ok: true, status: 200, json: async () => ({ data: [] }) }; });
|
|
144
|
+
try {
|
|
145
|
+
const cloud = await Promise.resolve().then(() => __importStar(require("../adapters/cloud-adapter/cloud-persistence")));
|
|
146
|
+
strict_1.default.deepEqual(await cloud.queryMemory("invoice", 10, "/Fixture/Repo"), []);
|
|
147
|
+
strict_1.default.match(requested, /q=invoice/);
|
|
148
|
+
strict_1.default.match(requested, /repo=Repo/);
|
|
149
|
+
strict_1.default.doesNotMatch(requested, /status=proposed/);
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
global.fetch = original;
|
|
153
|
+
if (token === undefined)
|
|
154
|
+
delete process.env.KODINGO_API_TOKEN;
|
|
155
|
+
else
|
|
156
|
+
process.env.KODINGO_API_TOKEN = token;
|
|
157
|
+
if (url === undefined)
|
|
158
|
+
delete process.env.KODINGO_API_URL;
|
|
159
|
+
else
|
|
160
|
+
process.env.KODINGO_API_URL = url;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
(0, node_test_1.it)("propagates authentication errors", async () => {
|
|
164
|
+
const original = global.fetch;
|
|
165
|
+
const token = process.env.KODINGO_API_TOKEN;
|
|
166
|
+
const url = process.env.KODINGO_API_URL;
|
|
167
|
+
process.env.KODINGO_API_TOKEN = "fixture-token";
|
|
168
|
+
process.env.KODINGO_API_URL = "https://example.invalid";
|
|
169
|
+
global.fetch = (async () => ({ ok: false, status: 401, text: async () => "Unauthorized" }));
|
|
170
|
+
try {
|
|
171
|
+
const cloud = await Promise.resolve().then(() => __importStar(require("../adapters/cloud-adapter/cloud-persistence")));
|
|
172
|
+
await strict_1.default.rejects(cloud.queryMemory("invoice"), /401.*Unauthorized/);
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
global.fetch = original;
|
|
176
|
+
if (token === undefined)
|
|
177
|
+
delete process.env.KODINGO_API_TOKEN;
|
|
178
|
+
else
|
|
179
|
+
process.env.KODINGO_API_TOKEN = token;
|
|
180
|
+
if (url === undefined)
|
|
181
|
+
delete process.env.KODINGO_API_URL;
|
|
182
|
+
else
|
|
183
|
+
process.env.KODINGO_API_URL = url;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
(0, node_test_1.describe)("query-memory command output", () => {
|
|
188
|
+
for (const [label, response, expected] of [
|
|
189
|
+
["empty successful search", "{ok:true,status:200,json:async()=>({data:[]})}", 'No results for "invoice" in this project.'],
|
|
190
|
+
["authentication failure", "{ok:false,status:401,text:async()=>\"Unauthorized\"}", "kodingo-api error 401: Unauthorized"],
|
|
191
|
+
])
|
|
192
|
+
(0, node_test_1.it)(label, () => fixture(root => {
|
|
193
|
+
const { spawnSync } = require("node:child_process");
|
|
194
|
+
const cfg = node_path_1.default.join(root, ".kodingo");
|
|
195
|
+
node_fs_1.default.mkdirSync(cfg, { mode: 0o700 });
|
|
196
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(cfg, "config.json"), JSON.stringify({ mode: "cloud", apiUrl: "https://example.invalid", token: "fixture-token" }), { mode: 0o600 });
|
|
197
|
+
const script = `global.fetch=async()=>(${response});require(${JSON.stringify(node_path_1.default.resolve("dist/commands/query-memory.js"))}).queryMemoryCommand("invoice",{limit:10}).catch(e=>{console.error(e.message);process.exitCode=1})`;
|
|
198
|
+
const result = spawnSync(process.execPath, ["-e", script], { cwd: root, env: { ...process.env, HOME: root }, encoding: "utf8" });
|
|
199
|
+
strict_1.default.match(result.stdout + result.stderr, new RegExp(expected.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
|
200
|
+
strict_1.default.equal(result.status, label === "authentication failure" ? 1 : 0);
|
|
201
|
+
}));
|
|
202
|
+
});
|
|
203
|
+
(0, node_test_1.describe)("doctor workspace credentials", () => {
|
|
204
|
+
for (const hasWorkspace of [false, true])
|
|
205
|
+
(0, node_test_1.it)(hasWorkspace ? "validates the folder token" : "reports a missing folder token", () => fixture(root => {
|
|
206
|
+
const { spawnSync } = require("node:child_process");
|
|
207
|
+
const project = node_path_1.default.join(root, "Project");
|
|
208
|
+
node_fs_1.default.mkdirSync(project);
|
|
209
|
+
const cfg = node_path_1.default.join(root, ".kodingo");
|
|
210
|
+
node_fs_1.default.mkdirSync(cfg, { mode: 0o700 });
|
|
211
|
+
const workspaces = hasWorkspace ? { [project]: { mode: "cloud", apiUrl: "https://example.invalid", token: "folder-token" } } : {};
|
|
212
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(cfg, "config.json"), JSON.stringify({ mode: "cloud", apiUrl: "https://example.invalid", workspaces }), { mode: 0o600 });
|
|
213
|
+
const script = `global.fetch=async(url,init)=>{if(url.endsWith('/health'))return {ok:true,status:200};if(url.includes('/memory')){if(init?.method==='POST')return {ok:true,status:200,json:async()=>({id:'fixture-id'})};if(init?.method==='DELETE')return {ok:true,status:204};return {ok:true,status:200,json:async()=>({data:[{id:'fixture-id',createdAt:'2026-01-01',updatedAt:'2026-01-01',status:'proposed',confidence:0.5}]})}}throw Error(url)};require(${JSON.stringify(node_path_1.default.resolve("dist/commands/doctor.js"))}).doctorCommand().catch(e=>{console.error(e.message);process.exitCode=1})`;
|
|
214
|
+
const result = spawnSync(process.execPath, ["-e", script], { cwd: project, env: { ...process.env, HOME: root }, encoding: "utf8" });
|
|
215
|
+
if (hasWorkspace) {
|
|
216
|
+
strict_1.default.match(result.stdout, /OK: KODINGO_API_TOKEN is configured/);
|
|
217
|
+
strict_1.default.match(result.stdout, /OK: kodingo-api token valid/);
|
|
218
|
+
}
|
|
219
|
+
else
|
|
220
|
+
strict_1.default.match(result.stdout, /No project token for this folder\. Run kodingo init here\./);
|
|
221
|
+
}));
|
|
222
|
+
});
|
|
223
|
+
(0, node_test_1.describe)("credential fallback", () => {
|
|
224
|
+
for (const globalToken of [undefined, "legacy-token"])
|
|
225
|
+
(0, node_test_1.it)(globalToken ? "uses top-level token if no workspace matches" : "returns no token if nothing matches", () => fixture(root => {
|
|
226
|
+
const { spawnSync } = require("node:child_process");
|
|
227
|
+
const cfg = node_path_1.default.join(root, ".kodingo");
|
|
228
|
+
node_fs_1.default.mkdirSync(cfg, { mode: 0o700 });
|
|
229
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(cfg, "config.json"), JSON.stringify({ mode: "cloud", apiUrl: "https://example.invalid", token: globalToken, workspaces: { [node_path_1.default.join(root, "Other")]: { mode: "cloud", token: "other" } } }), { mode: 0o600 });
|
|
230
|
+
const script = `console.log(JSON.stringify(require(${JSON.stringify(node_path_1.default.resolve("dist/utils/persistence-config.js"))}).getCredentials(process.cwd())))`;
|
|
231
|
+
const result = spawnSync(process.execPath, ["-e", script], { cwd: root, env: { ...process.env, HOME: root }, encoding: "utf8" });
|
|
232
|
+
strict_1.default.equal(result.status, 0);
|
|
233
|
+
strict_1.default.equal(JSON.parse(result.stdout).token, globalToken ?? "");
|
|
234
|
+
}));
|
|
235
|
+
(0, node_test_1.it)("writeWorkspaceConfig preserves the original key", () => fixture(root => {
|
|
236
|
+
const { spawnSync } = require("node:child_process");
|
|
237
|
+
const key = node_path_1.default.join(root, "Project");
|
|
238
|
+
const script = `const c=require(${JSON.stringify(node_path_1.default.resolve("dist/utils/persistence-config.js"))});c.writeWorkspaceConfig(${JSON.stringify(key)},{mode:"cloud",token:"fixture"});console.log(JSON.stringify(Object.keys(c.readConfig().workspaces)))`;
|
|
239
|
+
const result = spawnSync(process.execPath, ["-e", script], { cwd: root, env: { ...process.env, HOME: root }, encoding: "utf8" });
|
|
240
|
+
strict_1.default.equal(result.status, 0);
|
|
241
|
+
strict_1.default.deepEqual(JSON.parse(result.stdout), [key]);
|
|
242
|
+
}));
|
|
243
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
/** Invented, local fixtures for scan and checkout behavior. */
|
|
7
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const node_child_process_1 = require("node:child_process");
|
|
11
|
+
const node_test_1 = require("node:test");
|
|
12
|
+
const deep_scan_1 = require("../commands/deep-scan");
|
|
13
|
+
const init_1 = require("../commands/init");
|
|
14
|
+
function fixture(run) {
|
|
15
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(process.cwd(), ".cli-fixture-"));
|
|
16
|
+
try {
|
|
17
|
+
run(root);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
node_fs_1.default.rmSync(root, { recursive: true, force: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function git(root, ...args) {
|
|
24
|
+
return (0, node_child_process_1.execFileSync)("git", ["-C", root, ...args], { encoding: "utf8" }).trim();
|
|
25
|
+
}
|
|
26
|
+
function repo(run) {
|
|
27
|
+
fixture(root => {
|
|
28
|
+
git(root, "init", "-q");
|
|
29
|
+
git(root, "config", "user.name", "Fixture");
|
|
30
|
+
git(root, "config", "user.email", "fixture@example.invalid");
|
|
31
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "source.ts"), "export const value = 1;\n");
|
|
32
|
+
git(root, "add", "source.ts");
|
|
33
|
+
git(root, "commit", "-qm", "fixture");
|
|
34
|
+
run(root);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
(0, node_test_1.describe)("apply reason wording", () => {
|
|
38
|
+
for (const [reason, fragment] of [
|
|
39
|
+
["dirty_checkout", "Commit or stash them"],
|
|
40
|
+
["unverifiable_commit", "right owner"],
|
|
41
|
+
["behind", "Pull"],
|
|
42
|
+
["ahead", "Push"],
|
|
43
|
+
["diverged", "Reconcile"],
|
|
44
|
+
["branch_not_tracked", "kodingo init"],
|
|
45
|
+
["branch_untracked", "kodingo init"],
|
|
46
|
+
["detached_head", "Check out a branch"],
|
|
47
|
+
["custom_code", "custom_code"],
|
|
48
|
+
])
|
|
49
|
+
(0, node_test_1.it)(reason, () => {
|
|
50
|
+
const result = (0, deep_scan_1.describeApplyReason)(reason);
|
|
51
|
+
strict_1.default.match(result.sentence + result.nextStep, new RegExp(fragment));
|
|
52
|
+
strict_1.default.doesNotMatch(result.sentence, /unknown reason/);
|
|
53
|
+
});
|
|
54
|
+
(0, node_test_1.it)("missing reason means processing", () => {
|
|
55
|
+
strict_1.default.match((0, deep_scan_1.describeApplyReason)(null).sentence, /still processing/);
|
|
56
|
+
});
|
|
57
|
+
for (const field of ["reason", "applyReason", "apply_reason"])
|
|
58
|
+
(0, node_test_1.it)(`outcome uses ${field}`, () => {
|
|
59
|
+
const lines = [];
|
|
60
|
+
const old = console.log;
|
|
61
|
+
const exit = process.exitCode;
|
|
62
|
+
console.log = (...parts) => lines.push(parts.join(" "));
|
|
63
|
+
try {
|
|
64
|
+
(0, deep_scan_1.printFinalOutcome)({ applied: false, [field]: "dirty_checkout" }, false);
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
console.log = old;
|
|
68
|
+
process.exitCode = exit;
|
|
69
|
+
}
|
|
70
|
+
strict_1.default.match(lines.join(" "), /uncommitted changes/);
|
|
71
|
+
});
|
|
72
|
+
(0, node_test_1.it)("outcome without reason says processing", () => {
|
|
73
|
+
const lines = [];
|
|
74
|
+
const old = console.log;
|
|
75
|
+
const exit = process.exitCode;
|
|
76
|
+
console.log = (...parts) => lines.push(parts.join(" "));
|
|
77
|
+
try {
|
|
78
|
+
(0, deep_scan_1.printFinalOutcome)({ applied: false, state: "processing" }, true);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
console.log = old;
|
|
82
|
+
process.exitCode = exit;
|
|
83
|
+
}
|
|
84
|
+
strict_1.default.match(lines.join(" "), /still processing/);
|
|
85
|
+
});
|
|
86
|
+
(0, node_test_1.it)("status includes processing, commit and count", () => {
|
|
87
|
+
const lines = (0, deep_scan_1.renderScanStatus)({ lastCliScan: { commitSha: "a".repeat(40), applied: false, reason: null, entityCount: 7, edgeCount: 0, fileCount: 0, completedAt: null } });
|
|
88
|
+
strict_1.default.match(lines.join(" "), /processing \(7 entities\)/);
|
|
89
|
+
strict_1.default.match(lines.join(" "), /aaaaaaaaaaaa/);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
(0, node_test_1.describe)("local checkout hygiene", () => {
|
|
93
|
+
(0, node_test_1.it)("local exclude leaves worktree and index clean", () => repo(root => {
|
|
94
|
+
(0, init_1.ensureLocalExclude)(root, ".kortex/");
|
|
95
|
+
strict_1.default.equal(git(root, "status", "--porcelain"), "");
|
|
96
|
+
strict_1.default.match(node_fs_1.default.readFileSync(node_path_1.default.join(root, ".git/info/exclude"), "utf8"), /\.kortex\//);
|
|
97
|
+
}));
|
|
98
|
+
(0, node_test_1.it)("local exclude is idempotent", () => repo(root => {
|
|
99
|
+
(0, init_1.ensureLocalExclude)(root, ".kortex/");
|
|
100
|
+
(0, init_1.ensureLocalExclude)(root, ".kortex/");
|
|
101
|
+
strict_1.default.equal(node_fs_1.default.readFileSync(node_path_1.default.join(root, ".git/info/exclude"), "utf8").split(".kortex/").length, 2);
|
|
102
|
+
}));
|
|
103
|
+
(0, node_test_1.it)("staged Kortex ignore lines are clean", () => repo(root => {
|
|
104
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, ".gitignore"), "# Kortex\n.kortex/\n");
|
|
105
|
+
git(root, "add", ".gitignore");
|
|
106
|
+
strict_1.default.equal((0, deep_scan_1.isDirtyCheckout)(root), false);
|
|
107
|
+
}));
|
|
108
|
+
(0, node_test_1.it)("real source modification is dirty", () => repo(root => {
|
|
109
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "source.ts"), "export const value = 2;\n");
|
|
110
|
+
strict_1.default.equal((0, deep_scan_1.isDirtyCheckout)(root), true);
|
|
111
|
+
}));
|
|
112
|
+
(0, node_test_1.it)("untracked generated folder is clean", () => repo(root => {
|
|
113
|
+
node_fs_1.default.mkdirSync(node_path_1.default.join(root, ".kortex"));
|
|
114
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, ".kortex/state.json"), "{}");
|
|
115
|
+
strict_1.default.equal((0, deep_scan_1.isDirtyCheckout)(root), false);
|
|
116
|
+
}));
|
|
117
|
+
});
|
|
@@ -37,14 +37,22 @@ function withFetch(responses, run) {
|
|
|
37
37
|
return run(calls).finally(() => { global.fetch = original; });
|
|
38
38
|
}
|
|
39
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]);
|
|
40
48
|
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-consent-order-"));
|
|
41
|
-
(0, node_child_process_1.execFileSync)("git", ["
|
|
49
|
+
(0, node_child_process_1.execFileSync)("git", ["clone", "-q", originRoot, root]);
|
|
42
50
|
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.email", "test@example.invalid"]);
|
|
43
51
|
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.name", "Validation Test"]);
|
|
44
|
-
(0, node_child_process_1.execFileSync)("git", ["-C", root, "remote", "add", "origin", "git@github.com:validation/repository.git"]);
|
|
45
52
|
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "page.ts"), "export function Page() { return 1; }");
|
|
46
53
|
(0, node_child_process_1.execFileSync)("git", ["-C", root, "add", "."]);
|
|
47
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"]);
|
|
48
56
|
return root;
|
|
49
57
|
}
|
|
50
58
|
function withConsoleLog(run) {
|