pi-vault-mind 0.14.2 → 0.16.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/CHANGELOG.md +293 -0
- package/README.md +5 -5
- package/agents/broadcaster.agent.md +2 -2
- package/agents/heavy-lifter.agent.md +1 -1
- package/agents/main.agent.md +29 -0
- package/agents/manager.agent.md +1 -1
- package/agents/miner.agent.md +1 -1
- package/dist/packages/obsidian/src/client.js +331 -0
- package/dist/packages/obsidian/src/types.js +1 -0
- package/dist/src/activity.d.ts +49 -0
- package/dist/src/activity.js +175 -0
- package/dist/src/agent-bus/Agent.d.ts +9 -1
- package/dist/src/agent-bus/Agent.js +18 -2
- package/dist/src/agent-bus/index.d.ts +5 -5
- package/dist/src/agent-bus/index.js +1 -1
- package/dist/src/agent-queue.js +12 -3
- package/dist/src/agents/BroadcasterAgent.d.ts +1 -1
- package/dist/src/agents/BroadcasterAgent.js +2 -2
- package/dist/src/agents/HeavyLifterAgent.d.ts +1 -1
- package/dist/src/agents/HeavyLifterAgent.js +2 -2
- package/dist/src/agents/ManagerAgent.js +1 -1
- package/dist/src/agents/MinerAgent.d.ts +1 -1
- package/dist/src/agents/MinerAgent.js +2 -2
- package/dist/src/agents/index.d.ts +2 -2
- package/dist/src/agents/index.js +2 -2
- package/dist/src/auth.d.ts +17 -15
- package/dist/src/auth.js +26 -37
- package/dist/src/autosync.js +2 -2
- package/dist/src/commands.d.ts +2 -19
- package/dist/src/commands.js +301 -231
- package/dist/src/config-keys.d.ts +16 -0
- package/dist/src/config-keys.js +45 -0
- package/dist/src/discover-schema.js +4 -4
- package/dist/src/edits.d.ts +21 -0
- package/dist/src/edits.js +75 -0
- package/dist/src/embedding-probe.d.ts +34 -0
- package/dist/src/embedding-probe.js +142 -0
- package/dist/src/embedding-providers.d.ts +133 -0
- package/dist/src/embedding-providers.js +173 -0
- package/dist/src/embedding-secrets.d.ts +38 -0
- package/dist/src/embedding-secrets.js +291 -0
- package/dist/src/engine.d.ts +6 -0
- package/dist/src/engine.js +78 -6
- package/dist/src/events.js +7 -10
- package/dist/src/extension-packages.d.ts +9 -0
- package/dist/src/extension-packages.js +14 -0
- package/dist/src/git.d.ts +19 -0
- package/dist/src/git.js +78 -0
- package/dist/src/graph.d.ts +2 -1
- package/dist/src/graph.js +47 -13
- package/dist/src/identities-config.d.ts +6 -0
- package/dist/src/identities-config.js +39 -0
- package/dist/src/identity-injector.js +1 -1
- package/dist/src/index.js +9 -26
- package/dist/src/lance.d.ts +9 -0
- package/dist/src/lance.js +143 -203
- package/dist/src/modal-client.d.ts +16 -0
- package/dist/src/modal-client.js +16 -0
- package/dist/src/modal-config.d.ts +37 -14
- package/dist/src/modal-config.js +59 -32
- package/dist/src/model-router.d.ts +27 -0
- package/dist/src/model-router.js +67 -0
- package/dist/src/models.d.ts +42 -0
- package/dist/src/models.js +78 -0
- package/dist/src/personalize.js +17 -3
- package/dist/src/scaffold.d.ts +48 -0
- package/dist/src/scaffold.js +246 -0
- package/dist/src/server.d.ts +47 -4
- package/dist/src/server.js +988 -221
- package/dist/src/session-search.d.ts +63 -0
- package/dist/src/session-search.js +379 -0
- package/dist/src/settings-ui.d.ts +2 -2
- package/dist/src/settings-ui.js +76 -135
- package/dist/src/sync.d.ts +3 -3
- package/dist/src/sync.js +19 -15
- package/dist/src/tool-catalog.d.ts +18 -0
- package/dist/src/tool-catalog.js +232 -0
- package/dist/src/tools/marksman.js +1 -1
- package/dist/src/tools.js +111 -65
- package/dist/src/types.d.ts +127 -71
- package/dist/src/utils.d.ts +57 -6
- package/dist/src/utils.js +114 -28
- package/dist/src/vault-tools.d.ts +34 -0
- package/dist/src/vault-tools.js +99 -0
- package/dist/src/vault-writer.js +4 -1
- package/dist/src/vm-handlers.js +140 -43
- package/dist/src/watcher.js +9 -9
- package/dist/test/activity-tool.test.js +54 -0
- package/dist/test/agent-bus/Agent.test.js +174 -0
- package/dist/test/agent-bus/AgentLoader.test.js +180 -0
- package/dist/test/agent-bus/AgentRegistry.test.js +86 -0
- package/dist/test/agent-bus/LLMProvider.test.js +162 -0
- package/dist/test/agent-bus/TaskQueue.test.js +256 -0
- package/dist/test/agent-dispatch-context.test.js +73 -0
- package/dist/test/agent-queue.test.js +1 -1
- package/dist/test/agents/Agents.test.js +282 -0
- package/dist/test/auth.test.js +57 -56
- package/dist/test/bridge-identity.test.js +34 -3
- package/dist/test/classify-search-mode.test.js +51 -0
- package/dist/test/commands.test.js +410 -0
- package/dist/test/config-merge.test.js +98 -0
- package/dist/test/context-capture.test.js +56 -0
- package/dist/test/discover-schema.test.js +8 -5
- package/dist/test/dispatch.test.js +45 -91
- package/dist/test/edits.test.js +144 -0
- package/dist/test/embedding-probe.test.js +424 -0
- package/dist/test/embedding-providers.test.js +157 -0
- package/dist/test/embedding-secrets.test.js +210 -0
- package/dist/test/engine-identity.test.js +1 -1
- package/dist/test/events.test.js +675 -0
- package/dist/test/git-bridge.test.js +160 -0
- package/dist/test/graph.test.js +464 -0
- package/dist/test/helpers/server.js +81 -0
- package/dist/test/identity-injector.test.js +197 -0
- package/dist/test/index.test.js +5 -7
- package/dist/test/lance-modal.test.js +67 -2
- package/dist/test/lance.test.js +429 -0
- package/dist/test/modal-client.test.js +1 -1
- package/dist/test/modal-config.test.js +92 -79
- package/dist/test/model-readiness.test.js +122 -0
- package/dist/test/model-router.test.js +99 -0
- package/dist/test/obsidian-client.test.js +42 -0
- package/dist/test/personalize.test.js +1 -1
- package/dist/test/rest-models.test.js +153 -0
- package/dist/test/rest-queue.test.js +135 -87
- package/dist/test/rest-setup.test.js +625 -115
- package/dist/test/rest-vm.test.js +355 -94
- package/dist/test/server-cors.test.js +48 -0
- package/dist/test/server-ws.test.js +61 -34
- package/dist/test/session-crud.test.js +323 -0
- package/dist/test/session-search.test.js +139 -0
- package/dist/test/settings-ui.test.js +113 -4
- package/dist/test/sync.test.js +12 -12
- package/dist/test/tombstone.test.js +8 -10
- package/dist/test/tool-catalog.test.js +86 -0
- package/dist/test/utils.test.js +588 -0
- package/dist/test/vault-tools.test.js +103 -12
- package/dist/test/vault-writer.test.js +371 -0
- package/dist/test/vm-handlers.test.js +620 -0
- package/extension-packages.json +9 -0
- package/package.json +107 -90
- package/pi-vault-mind.config.example.json +24 -2
- package/scripts/check-deps.sh +35 -32
- package/scripts/cli-e2e.mjs +215 -0
- package/scripts/configuration-e2e.mjs +783 -0
- package/scripts/e2e-commands.mjs +391 -0
- package/scripts/e2e-ws.mjs +3 -2
- package/scripts/fetch-modal-token.sh +4 -3
- package/scripts/generate-config-keys-json.mjs +45 -0
- package/scripts/generate-extension-packages-json.mjs +55 -0
- package/scripts/pi-session-query +0 -0
- package/scripts/publish-obsidian-plugin.sh +0 -0
- package/scripts/reset-test-vault.sh +2 -2
- package/scripts/setup-test-config.sh +0 -0
- package/scripts/setup-vault-pi.sh +48 -9
- package/scripts/test-slash-commands.mjs +2 -2
- package/scripts/vault-pi.sh +12 -3
- package/skills/github-release-notes-file/SKILL.md +42 -0
- package/skills/obsidian-guided-test-session/SKILL.md +110 -0
- package/skills/obsidian-interactive-test/SKILL.md +88 -0
- package/skills/obsidian-plugin-publish/SKILL.md +58 -0
- package/skills/pi-vault-mind-release/SKILL.md +141 -0
- package/skills/pre-test-release/SKILL.md +116 -0
- package/dist/test/auto-indexer.test.js +0 -2
|
@@ -0,0 +1,783 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { once } from "node:events";
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as http from "node:http";
|
|
8
|
+
import * as os from "node:os";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
|
+
|
|
12
|
+
import { isDeepStrictEqual } from "node:util";
|
|
13
|
+
|
|
14
|
+
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const REPO_ROOT = path.resolve(SCRIPT_DIR, "..");
|
|
16
|
+
const MASK = "••••••••";
|
|
17
|
+
const READY_PREFIX = "CONFIGURATION_E2E_READY:";
|
|
18
|
+
const SECRET_KEYS = ["localApiKey", "remoteApiKey", "remoteReadApiKey", "remoteWriteApiKey"];
|
|
19
|
+
const LEGACY_CONFIG_KEY = {
|
|
20
|
+
localApiKey: "apiKey",
|
|
21
|
+
remoteApiKey: "remoteApiKey",
|
|
22
|
+
remoteReadApiKey: "remoteReadApiKey",
|
|
23
|
+
remoteWriteApiKey: "remoteWriteApiKey",
|
|
24
|
+
};
|
|
25
|
+
const COMPILED_PAIRS = [
|
|
26
|
+
["src/auth.ts", "dist/src/auth.js"],
|
|
27
|
+
["src/config-keys.ts", "dist/src/config-keys.js"],
|
|
28
|
+
["src/embedding-probe.ts", "dist/src/embedding-probe.js"],
|
|
29
|
+
["src/embedding-secrets.ts", "dist/src/embedding-secrets.js"],
|
|
30
|
+
["src/modal-config.ts", "dist/src/modal-config.js"],
|
|
31
|
+
["src/scaffold.ts", "dist/src/scaffold.js"],
|
|
32
|
+
["src/server.ts", "dist/src/server.js"],
|
|
33
|
+
["src/utils.ts", "dist/src/utils.js"],
|
|
34
|
+
["src/watcher.ts", "dist/src/watcher.js"],
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
class CompiledOutputBlocker extends Error {}
|
|
38
|
+
|
|
39
|
+
function checkCompiledOutput() {
|
|
40
|
+
const missing = [];
|
|
41
|
+
const stale = [];
|
|
42
|
+
for (const [sourceRelative, compiledRelative] of COMPILED_PAIRS) {
|
|
43
|
+
const sourcePath = path.join(REPO_ROOT, sourceRelative);
|
|
44
|
+
const compiledPath = path.join(REPO_ROOT, compiledRelative);
|
|
45
|
+
if (!fs.existsSync(compiledPath)) {
|
|
46
|
+
missing.push(compiledRelative);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (fs.statSync(sourcePath).mtimeMs > fs.statSync(compiledPath).mtimeMs) {
|
|
50
|
+
stale.push(compiledRelative);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (missing.length > 0 || stale.length > 0) {
|
|
54
|
+
const reasons = [];
|
|
55
|
+
if (missing.length > 0) reasons.push(`missing: ${missing.join(", ")}`);
|
|
56
|
+
if (stale.length > 0) reasons.push(`stale: ${stale.join(", ")}`);
|
|
57
|
+
throw new CompiledOutputBlocker(
|
|
58
|
+
`compiled extension output is not current (${reasons.join("; ")}); run npm run build`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function requireCondition(condition, message) {
|
|
64
|
+
if (!condition) throw new Error(message);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function requireEqual(actual, expected, message) {
|
|
68
|
+
requireCondition(Object.is(actual, expected), message);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function requireJsonEqual(actual, expected, message) {
|
|
72
|
+
requireCondition(isDeepStrictEqual(actual, expected), message);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function withTimeout(promise, timeoutMs, message) {
|
|
76
|
+
let timer;
|
|
77
|
+
const timeout = new Promise((_, reject) => {
|
|
78
|
+
timer = setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
79
|
+
});
|
|
80
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function secretValue(label) {
|
|
84
|
+
return `${label}_${randomUUID().replaceAll("-", "")}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function secretFragments(secrets) {
|
|
88
|
+
return [
|
|
89
|
+
...new Set(secrets.flatMap((secret) => [secret, secret.slice(0, 24), secret.slice(-24)])),
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function containsSecret(text, fragments) {
|
|
94
|
+
return fragments.some((fragment) => fragment.length > 0 && text.includes(fragment));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function requireSecretFree(text, fragments, surface) {
|
|
98
|
+
if (containsSecret(text, fragments)) {
|
|
99
|
+
throw new Error(`${surface} exposed secret material`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function redactText(value, fragments) {
|
|
104
|
+
let text = String(value);
|
|
105
|
+
for (const fragment of [...fragments].sort((a, b) => b.length - a.length)) {
|
|
106
|
+
text = text.replaceAll(fragment, "[REDACTED]");
|
|
107
|
+
}
|
|
108
|
+
return text;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function statusByKind(body, kind) {
|
|
112
|
+
return body?.embeddingSecrets?.secrets?.find((entry) => entry?.kind === kind);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function mutationStatusByKind(body, kind) {
|
|
116
|
+
return body?.secrets?.find((entry) => entry?.kind === kind);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function expectedStatus(kind, configured, source) {
|
|
120
|
+
return { kind, configured, masked: configured ? MASK : null, source };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function listen(server) {
|
|
124
|
+
server.listen(0, "127.0.0.1");
|
|
125
|
+
await once(server, "listening");
|
|
126
|
+
const address = server.address();
|
|
127
|
+
requireCondition(address && typeof address === "object", "fixture did not bind a TCP port");
|
|
128
|
+
return `http://127.0.0.1:${address.port}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function closeServer(server) {
|
|
132
|
+
if (!server?.listening) return;
|
|
133
|
+
const closed = once(server, "close");
|
|
134
|
+
server.close();
|
|
135
|
+
server.closeAllConnections?.();
|
|
136
|
+
await withTimeout(closed, 5_000, "fixture server teardown timed out");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function createOpenAiFixture(name, models) {
|
|
140
|
+
const calls = [];
|
|
141
|
+
const firstDiscoveryPath = name === "local" ? "/api/tags" : "/models";
|
|
142
|
+
const server = http.createServer((request, response) => {
|
|
143
|
+
calls.push({
|
|
144
|
+
method: request.method,
|
|
145
|
+
path: request.url,
|
|
146
|
+
authorization: request.headers.authorization,
|
|
147
|
+
});
|
|
148
|
+
response.setHeader("Content-Type", "application/json");
|
|
149
|
+
if (request.method === "GET" && request.url === firstDiscoveryPath) {
|
|
150
|
+
response.writeHead(404);
|
|
151
|
+
response.end(JSON.stringify({ error: "OpenAI-compatible discovery only" }));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (request.method === "GET" && request.url === "/v1/models") {
|
|
155
|
+
response.writeHead(200);
|
|
156
|
+
response.end(JSON.stringify({ object: "list", data: models.map((id) => ({ id })) }));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
response.writeHead(404);
|
|
160
|
+
response.end(JSON.stringify({ error: "not found" }));
|
|
161
|
+
});
|
|
162
|
+
return { server, calls, baseUrl: await listen(server) };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function childProgram() {
|
|
166
|
+
const serverUrl = pathToFileURL(path.join(REPO_ROOT, "dist/src/server.js")).href;
|
|
167
|
+
const watcherUrl = pathToFileURL(path.join(REPO_ROOT, "dist/src/watcher.js")).href;
|
|
168
|
+
return `
|
|
169
|
+
import { once } from "node:events";
|
|
170
|
+
const { createServerState, startServer, stopServer } = await import(${JSON.stringify(serverUrl)});
|
|
171
|
+
const { createWatcherState } = await import(${JSON.stringify(watcherUrl)});
|
|
172
|
+
const serverState = createServerState(0);
|
|
173
|
+
const watcherState = createWatcherState();
|
|
174
|
+
const pi = {
|
|
175
|
+
sendUserMessage() {},
|
|
176
|
+
events: { emit() {} },
|
|
177
|
+
getAllTools() { return []; },
|
|
178
|
+
registerCommand() {},
|
|
179
|
+
registerTool() {},
|
|
180
|
+
};
|
|
181
|
+
let stopping = false;
|
|
182
|
+
const stop = () => {
|
|
183
|
+
if (stopping) return;
|
|
184
|
+
stopping = true;
|
|
185
|
+
stopServer(serverState);
|
|
186
|
+
setImmediate(() => process.exit(0));
|
|
187
|
+
};
|
|
188
|
+
process.on("SIGINT", stop);
|
|
189
|
+
process.on("SIGTERM", stop);
|
|
190
|
+
startServer(pi, serverState, watcherState);
|
|
191
|
+
if (!serverState.server) throw new Error("compiled extension server was not created");
|
|
192
|
+
if (!serverState.server.listening) await once(serverState.server, "listening");
|
|
193
|
+
const address = serverState.server.address();
|
|
194
|
+
if (!address || typeof address !== "object") throw new Error("compiled extension server has no address");
|
|
195
|
+
process.stdout.write(${JSON.stringify(READY_PREFIX)} + address.port + "\\n");
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function startExtension(vaultDir, fragments) {
|
|
200
|
+
const child = spawn(process.execPath, ["--input-type=module", "--eval", childProgram()], {
|
|
201
|
+
cwd: vaultDir,
|
|
202
|
+
env: {
|
|
203
|
+
HOME: vaultDir,
|
|
204
|
+
LANG: process.env.LANG ?? "C",
|
|
205
|
+
PATH: process.env.PATH ?? "",
|
|
206
|
+
PI_CODING_AGENT_DIR: path.join(vaultDir, ".pi", "agent"),
|
|
207
|
+
TMPDIR: os.tmpdir(),
|
|
208
|
+
USERPROFILE: vaultDir,
|
|
209
|
+
},
|
|
210
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const capture = { child, stdout: "", stderr: "" };
|
|
214
|
+
let readyBuffer = "";
|
|
215
|
+
const ready = new Promise((resolve, reject) => {
|
|
216
|
+
child.stdout.on("data", (chunk) => {
|
|
217
|
+
const text = chunk.toString();
|
|
218
|
+
capture.stdout += text;
|
|
219
|
+
readyBuffer += text;
|
|
220
|
+
if (containsSecret(text, fragments)) {
|
|
221
|
+
reject(new Error("compiled extension stdout exposed secret material"));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
for (const line of readyBuffer.split(/\r?\n/)) {
|
|
225
|
+
if (!line.startsWith(READY_PREFIX)) continue;
|
|
226
|
+
const port = Number(line.slice(READY_PREFIX.length));
|
|
227
|
+
if (!Number.isInteger(port) || port <= 0) {
|
|
228
|
+
reject(new Error("compiled extension reported an invalid port"));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
resolve(port);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
child.stderr.on("data", (chunk) => {
|
|
236
|
+
const text = chunk.toString();
|
|
237
|
+
capture.stderr += text;
|
|
238
|
+
if (containsSecret(text, fragments)) {
|
|
239
|
+
reject(new Error("compiled extension stderr exposed secret material"));
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
child.once("error", () => reject(new Error("compiled extension process failed to start")));
|
|
243
|
+
child.once("close", (code) => {
|
|
244
|
+
reject(new Error(`compiled extension exited before readiness (status ${code ?? "signal"})`));
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
capture.port = await withTimeout(ready, 15_000, "compiled extension readiness timed out");
|
|
250
|
+
return capture;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
await stopExtension(capture);
|
|
253
|
+
requireSecretFree(capture.stdout, fragments, "captured compiled extension stdout");
|
|
254
|
+
requireSecretFree(capture.stderr, fragments, "captured compiled extension stderr");
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function stopExtension(capture) {
|
|
260
|
+
if (!capture?.child || capture.child.exitCode !== null || capture.child.signalCode !== null)
|
|
261
|
+
return;
|
|
262
|
+
let closePromise = once(capture.child, "close");
|
|
263
|
+
capture.child.kill("SIGTERM");
|
|
264
|
+
try {
|
|
265
|
+
await withTimeout(closePromise, 5_000, "compiled extension teardown timed out");
|
|
266
|
+
} catch {
|
|
267
|
+
if (capture.child.exitCode === null && capture.child.signalCode === null) {
|
|
268
|
+
closePromise = once(capture.child, "close");
|
|
269
|
+
capture.child.kill("SIGKILL");
|
|
270
|
+
await withTimeout(closePromise, 5_000, "compiled extension force-teardown timed out");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async function requestJson(port, method, route, options, fragments, observedPayloads) {
|
|
276
|
+
const headers = { "Content-Type": "application/json" };
|
|
277
|
+
if (options?.token !== undefined) headers.Authorization = `Bearer ${options.token}`;
|
|
278
|
+
const response = await fetch(`http://127.0.0.1:${port}${route}`, {
|
|
279
|
+
method,
|
|
280
|
+
headers,
|
|
281
|
+
body: options && Object.hasOwn(options, "body") ? JSON.stringify(options.body) : undefined,
|
|
282
|
+
});
|
|
283
|
+
const raw = await response.text();
|
|
284
|
+
observedPayloads.push(raw);
|
|
285
|
+
requireSecretFree(raw, fragments, `${method} ${route} response`);
|
|
286
|
+
let body;
|
|
287
|
+
try {
|
|
288
|
+
body = raw ? JSON.parse(raw) : {};
|
|
289
|
+
} catch {
|
|
290
|
+
throw new Error(`${method} ${route} returned non-JSON content`);
|
|
291
|
+
}
|
|
292
|
+
return { status: response.status, body };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function main() {
|
|
296
|
+
checkCompiledOutput();
|
|
297
|
+
|
|
298
|
+
const secrets = {
|
|
299
|
+
bridge: secretValue("bridge"),
|
|
300
|
+
legacyLocal: secretValue("legacy_local"),
|
|
301
|
+
legacyRemote: secretValue("legacy_remote"),
|
|
302
|
+
legacyRead: secretValue("legacy_read"),
|
|
303
|
+
legacyWrite: secretValue("legacy_write"),
|
|
304
|
+
replacementRemoteFirst: secretValue("remote_first"),
|
|
305
|
+
replacementRemoteFinal: secretValue("remote_final"),
|
|
306
|
+
replacementRead: secretValue("read_final"),
|
|
307
|
+
localProbe: secretValue("local_probe"),
|
|
308
|
+
remoteProbeApi: secretValue("remote_probe_api"),
|
|
309
|
+
remoteProbeRead: secretValue("remote_probe_read"),
|
|
310
|
+
remoteProbeWrite: secretValue("remote_probe_write"),
|
|
311
|
+
};
|
|
312
|
+
const fragments = secretFragments(Object.values(secrets));
|
|
313
|
+
failureFragments = fragments;
|
|
314
|
+
const observedPayloads = [];
|
|
315
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "pvm-configuration-e2e-"));
|
|
316
|
+
const vaultDir = path.join(tempRoot, "vault");
|
|
317
|
+
const relocatedVaultDir = path.join(tempRoot, "relocated-vault");
|
|
318
|
+
const vaultMindDir = path.join(vaultDir, ".vault-mind");
|
|
319
|
+
const configPath = path.join(vaultMindDir, "vault-mind.config.json");
|
|
320
|
+
const envPath = path.join(vaultMindDir, "vault-mind.env");
|
|
321
|
+
const baselineDefaultVault = {
|
|
322
|
+
path: vaultDir,
|
|
323
|
+
autoStart: false,
|
|
324
|
+
autoSync: false,
|
|
325
|
+
autoSyncTags: ["publish", "reference"],
|
|
326
|
+
autoSyncMinLength: 240,
|
|
327
|
+
collectionPrefix: "configuration-e2e",
|
|
328
|
+
customPolicy: { preserve: true },
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
let localFixture;
|
|
332
|
+
let remoteFixture;
|
|
333
|
+
let extension;
|
|
334
|
+
let failure;
|
|
335
|
+
let teardownFailure;
|
|
336
|
+
|
|
337
|
+
try {
|
|
338
|
+
fs.mkdirSync(vaultMindDir, { recursive: true });
|
|
339
|
+
fs.mkdirSync(relocatedVaultDir, { recursive: true });
|
|
340
|
+
fs.mkdirSync(path.join(vaultDir, ".pi", "agent"), { recursive: true });
|
|
341
|
+
|
|
342
|
+
localFixture = await createOpenAiFixture("local", ["zeta-local", "alpha-local"]);
|
|
343
|
+
remoteFixture = await createOpenAiFixture("remote", ["zeta-remote", "alpha-remote"]);
|
|
344
|
+
|
|
345
|
+
const initialConfig = {
|
|
346
|
+
version: 2,
|
|
347
|
+
collections: {},
|
|
348
|
+
injectors: [],
|
|
349
|
+
vaultMind: {
|
|
350
|
+
dataDir: ".lancedb",
|
|
351
|
+
embedding: {
|
|
352
|
+
localUrl: `${localFixture.baseUrl}/v1/embeddings`,
|
|
353
|
+
remoteUrl: `${remoteFixture.baseUrl}/v1/embeddings`,
|
|
354
|
+
model: "alpha-remote",
|
|
355
|
+
dim: 768,
|
|
356
|
+
useTransformers: false,
|
|
357
|
+
apiKey: secrets.legacyLocal,
|
|
358
|
+
remoteApiKey: secrets.legacyRemote,
|
|
359
|
+
remoteReadApiKey: secrets.legacyRead,
|
|
360
|
+
remoteWriteApiKey: secrets.legacyWrite,
|
|
361
|
+
fallback: { enabled: true },
|
|
362
|
+
},
|
|
363
|
+
folders: {
|
|
364
|
+
inbox: "Old/Inbox",
|
|
365
|
+
library: "Old/Library",
|
|
366
|
+
presentations: "Old/Presentations",
|
|
367
|
+
journal: "Old/Journal",
|
|
368
|
+
},
|
|
369
|
+
graph: { enabled: true, canvasSync: false },
|
|
370
|
+
vaults: { default: baselineDefaultVault },
|
|
371
|
+
},
|
|
372
|
+
extensionCompatibility: {
|
|
373
|
+
"pi-context": { enabled: false, includeSelection: true },
|
|
374
|
+
"other-extension": { enabled: true, mode: "strict" },
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
fs.writeFileSync(configPath, `${JSON.stringify(initialConfig, null, 2)}\n`, "utf-8");
|
|
378
|
+
fs.writeFileSync(
|
|
379
|
+
envPath,
|
|
380
|
+
`# configuration e2e\nPVM_API_TOKEN="${secrets.bridge}"\nUNRELATED_SETTING="keep-me"\n`,
|
|
381
|
+
{ encoding: "utf-8", mode: 0o600 }
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
extension = await startExtension(vaultDir, fragments);
|
|
385
|
+
const request = (method, route, options = {}) =>
|
|
386
|
+
requestJson(extension.port, method, route, options, fragments, observedPayloads);
|
|
387
|
+
|
|
388
|
+
{
|
|
389
|
+
const accepted = await request("GET", "/vm/status", { token: secrets.bridge });
|
|
390
|
+
const providerRejected = await request("GET", "/vm/status", {
|
|
391
|
+
token: secrets.legacyRemote,
|
|
392
|
+
});
|
|
393
|
+
requireEqual(accepted.status, 200, "dedicated bridge token was not accepted");
|
|
394
|
+
requireEqual(accepted.body?.ok, true, "authenticated status did not report success");
|
|
395
|
+
requireEqual(
|
|
396
|
+
providerRejected.status,
|
|
397
|
+
401,
|
|
398
|
+
"legacy provider token authenticated a bridge request"
|
|
399
|
+
);
|
|
400
|
+
console.log("PASS bridge versus provider authentication boundary");
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
{
|
|
404
|
+
const response = await request("GET", "/vault-mind/config", { token: secrets.bridge });
|
|
405
|
+
requireEqual(response.status, 200, "config read failed");
|
|
406
|
+
requireEqual(response.body?.hasToken, true, "config read did not recognize the bridge token");
|
|
407
|
+
for (const key of SECRET_KEYS) {
|
|
408
|
+
requireEqual(
|
|
409
|
+
response.body?.config?.vaultMind?.embedding?.[LEGACY_CONFIG_KEY[key]],
|
|
410
|
+
MASK,
|
|
411
|
+
`config read did not redact ${key}`
|
|
412
|
+
);
|
|
413
|
+
requireJsonEqual(
|
|
414
|
+
statusByKind(response.body, key),
|
|
415
|
+
expectedStatus(key, true, "legacy-config"),
|
|
416
|
+
`initial ${key} status did not report legacy ownership`
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
console.log("PASS legacy secret redaction and ownership status");
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
{
|
|
423
|
+
const migrated = await request("PUT", "/vm/embedding/secrets", {
|
|
424
|
+
token: secrets.bridge,
|
|
425
|
+
body: {
|
|
426
|
+
localApiKey: null,
|
|
427
|
+
remoteApiKey: secrets.replacementRemoteFirst,
|
|
428
|
+
remoteReadApiKey: secrets.replacementRead,
|
|
429
|
+
remoteWriteApiKey: null,
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
requireEqual(migrated.status, 200, "legacy secret migration failed");
|
|
433
|
+
requireEqual(migrated.body?.ok, true, "legacy secret migration did not report success");
|
|
434
|
+
requireJsonEqual(
|
|
435
|
+
mutationStatusByKind(migrated.body, "localApiKey"),
|
|
436
|
+
expectedStatus("localApiKey", false, "none"),
|
|
437
|
+
"local secret deletion status is incorrect"
|
|
438
|
+
);
|
|
439
|
+
requireJsonEqual(
|
|
440
|
+
mutationStatusByKind(migrated.body, "remoteApiKey"),
|
|
441
|
+
expectedStatus("remoteApiKey", true, "extension-secret-store"),
|
|
442
|
+
"remote secret migration status is incorrect"
|
|
443
|
+
);
|
|
444
|
+
requireJsonEqual(
|
|
445
|
+
mutationStatusByKind(migrated.body, "remoteReadApiKey"),
|
|
446
|
+
expectedStatus("remoteReadApiKey", true, "extension-secret-store"),
|
|
447
|
+
"read secret migration status is incorrect"
|
|
448
|
+
);
|
|
449
|
+
requireJsonEqual(
|
|
450
|
+
mutationStatusByKind(migrated.body, "remoteWriteApiKey"),
|
|
451
|
+
expectedStatus("remoteWriteApiKey", false, "none"),
|
|
452
|
+
"write secret deletion status is incorrect"
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
const replaced = await request("PUT", "/vm/embedding/secrets", {
|
|
456
|
+
token: secrets.bridge,
|
|
457
|
+
body: { remoteApiKey: secrets.replacementRemoteFinal },
|
|
458
|
+
});
|
|
459
|
+
requireEqual(replaced.status, 200, "stored remote secret replacement failed");
|
|
460
|
+
requireJsonEqual(
|
|
461
|
+
mutationStatusByKind(replaced.body, "remoteApiKey"),
|
|
462
|
+
expectedStatus("remoteApiKey", true, "extension-secret-store"),
|
|
463
|
+
"remote replacement status is incorrect"
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
const storedEnv = fs.readFileSync(envPath, "utf-8");
|
|
467
|
+
requireCondition(
|
|
468
|
+
storedEnv.includes(secrets.bridge),
|
|
469
|
+
"secret mutation removed the bridge token"
|
|
470
|
+
);
|
|
471
|
+
requireCondition(
|
|
472
|
+
storedEnv.includes('UNRELATED_SETTING="keep-me"'),
|
|
473
|
+
"secret mutation removed an unrelated env entry"
|
|
474
|
+
);
|
|
475
|
+
requireCondition(
|
|
476
|
+
storedEnv.includes(secrets.replacementRemoteFinal),
|
|
477
|
+
"final remote secret was not stored"
|
|
478
|
+
);
|
|
479
|
+
requireCondition(
|
|
480
|
+
storedEnv.includes(secrets.replacementRead),
|
|
481
|
+
"remote read secret was not stored"
|
|
482
|
+
);
|
|
483
|
+
requireCondition(
|
|
484
|
+
!storedEnv.includes(secrets.replacementRemoteFirst),
|
|
485
|
+
"replaced remote secret remained stored"
|
|
486
|
+
);
|
|
487
|
+
requireCondition(
|
|
488
|
+
!storedEnv.includes("PVM_LOCAL_EMBEDDING_API_KEY="),
|
|
489
|
+
"deleted local secret remained stored"
|
|
490
|
+
);
|
|
491
|
+
requireCondition(
|
|
492
|
+
!storedEnv.includes("PVM_MODAL_WRITE_TOKEN="),
|
|
493
|
+
"deleted write secret remained stored"
|
|
494
|
+
);
|
|
495
|
+
const storedConfig = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
496
|
+
for (const key of SECRET_KEYS) {
|
|
497
|
+
requireCondition(
|
|
498
|
+
!Object.hasOwn(storedConfig.vaultMind.embedding, LEGACY_CONFIG_KEY[key]),
|
|
499
|
+
`legacy ${LEGACY_CONFIG_KEY[key]} remained in configuration`
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
console.log("PASS secret migration replacement deletion and response redaction");
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
{
|
|
506
|
+
const response = await request("POST", "/vm/embedding/probe", {
|
|
507
|
+
token: secrets.bridge,
|
|
508
|
+
body: {
|
|
509
|
+
target: "local",
|
|
510
|
+
url: `${localFixture.baseUrl}/v1/embeddings/`,
|
|
511
|
+
model: "zeta-local",
|
|
512
|
+
transientSecrets: { apiKey: secrets.localProbe },
|
|
513
|
+
},
|
|
514
|
+
});
|
|
515
|
+
requireEqual(response.status, 200, "local probe failed");
|
|
516
|
+
requireJsonEqual(
|
|
517
|
+
response.body,
|
|
518
|
+
{
|
|
519
|
+
ok: true,
|
|
520
|
+
target: "local",
|
|
521
|
+
endpoint: localFixture.baseUrl,
|
|
522
|
+
models: [
|
|
523
|
+
{ id: "alpha-local", name: "alpha-local", dim: null },
|
|
524
|
+
{ id: "zeta-local", name: "zeta-local", dim: null },
|
|
525
|
+
],
|
|
526
|
+
selectedModelAvailable: true,
|
|
527
|
+
latencyMs: response.body?.latencyMs,
|
|
528
|
+
error: null,
|
|
529
|
+
},
|
|
530
|
+
"local OpenAI-compatible response was not normalized"
|
|
531
|
+
);
|
|
532
|
+
requireCondition(
|
|
533
|
+
Number.isFinite(response.body?.latencyMs) && response.body.latencyMs >= 0,
|
|
534
|
+
"local probe latency is invalid"
|
|
535
|
+
);
|
|
536
|
+
requireJsonEqual(
|
|
537
|
+
localFixture.calls,
|
|
538
|
+
[
|
|
539
|
+
{ method: "GET", path: "/api/tags", authorization: `Bearer ${secrets.localProbe}` },
|
|
540
|
+
{ method: "GET", path: "/v1/models", authorization: `Bearer ${secrets.localProbe}` },
|
|
541
|
+
],
|
|
542
|
+
"local probe did not use the normalized discovery path and local credential"
|
|
543
|
+
);
|
|
544
|
+
console.log("PASS Local OpenAI-compatible probe normalization");
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
{
|
|
548
|
+
const response = await request("POST", "/vm/embedding/probe", {
|
|
549
|
+
token: secrets.bridge,
|
|
550
|
+
body: {
|
|
551
|
+
target: "remote",
|
|
552
|
+
url: `${remoteFixture.baseUrl}/v1/embeddings`,
|
|
553
|
+
model: "missing-remote",
|
|
554
|
+
transientSecrets: {
|
|
555
|
+
apiKey: secrets.remoteProbeApi,
|
|
556
|
+
readApiKey: secrets.remoteProbeRead,
|
|
557
|
+
writeApiKey: secrets.remoteProbeWrite,
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
});
|
|
561
|
+
requireEqual(response.status, 200, "remote probe failed");
|
|
562
|
+
requireJsonEqual(
|
|
563
|
+
response.body,
|
|
564
|
+
{
|
|
565
|
+
ok: true,
|
|
566
|
+
target: "remote",
|
|
567
|
+
endpoint: remoteFixture.baseUrl,
|
|
568
|
+
models: [
|
|
569
|
+
{ id: "alpha-remote", name: "alpha-remote", dim: null },
|
|
570
|
+
{ id: "zeta-remote", name: "zeta-remote", dim: null },
|
|
571
|
+
],
|
|
572
|
+
selectedModelAvailable: false,
|
|
573
|
+
latencyMs: response.body?.latencyMs,
|
|
574
|
+
error: null,
|
|
575
|
+
},
|
|
576
|
+
"remote OpenAI-compatible response was not normalized"
|
|
577
|
+
);
|
|
578
|
+
requireCondition(
|
|
579
|
+
Number.isFinite(response.body?.latencyMs) && response.body.latencyMs >= 0,
|
|
580
|
+
"remote probe latency is invalid"
|
|
581
|
+
);
|
|
582
|
+
requireJsonEqual(
|
|
583
|
+
remoteFixture.calls,
|
|
584
|
+
[
|
|
585
|
+
{ method: "GET", path: "/models", authorization: `Bearer ${secrets.remoteProbeRead}` },
|
|
586
|
+
{ method: "GET", path: "/v1/models", authorization: `Bearer ${secrets.remoteProbeRead}` },
|
|
587
|
+
],
|
|
588
|
+
"remote probe did not use the normalized discovery path and read credential"
|
|
589
|
+
);
|
|
590
|
+
console.log("PASS Remote OpenAI-compatible probe normalization");
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
let expectedDefaultVault;
|
|
594
|
+
{
|
|
595
|
+
const setup = await request("POST", "/vm/setup", {
|
|
596
|
+
token: secrets.bridge,
|
|
597
|
+
body: {
|
|
598
|
+
vault: relocatedVaultDir,
|
|
599
|
+
localUrl: `${localFixture.baseUrl}/v1/embeddings`,
|
|
600
|
+
remoteUrl: `${remoteFixture.baseUrl}/v1/embeddings`,
|
|
601
|
+
model: "zeta-remote",
|
|
602
|
+
useTransformers: false,
|
|
603
|
+
folders: {
|
|
604
|
+
inbox: " Agent/Inbox ",
|
|
605
|
+
library: "Agent/Library",
|
|
606
|
+
presentations: "Agent/Presentations",
|
|
607
|
+
journal: "Agent/Journal",
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
});
|
|
611
|
+
requireEqual(setup.status, 200, "setup rerun failed");
|
|
612
|
+
requireEqual(setup.body?.ok, true, "setup rerun did not report success");
|
|
613
|
+
|
|
614
|
+
expectedDefaultVault = { ...baselineDefaultVault, path: relocatedVaultDir };
|
|
615
|
+
const restoration = await request("PATCH", "/vm/config", {
|
|
616
|
+
token: secrets.bridge,
|
|
617
|
+
body: {
|
|
618
|
+
vaultMind: {
|
|
619
|
+
vaults: { default: expectedDefaultVault },
|
|
620
|
+
embedding: {
|
|
621
|
+
localUrl: `${localFixture.baseUrl}/v1/embeddings`,
|
|
622
|
+
remoteUrl: `${remoteFixture.baseUrl}/v1/embeddings`,
|
|
623
|
+
workspace: "configuration-e2e",
|
|
624
|
+
model: "zeta-remote",
|
|
625
|
+
dim: 1024,
|
|
626
|
+
fallback: { enabled: true },
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
extensionCompatibility: {
|
|
630
|
+
"pi-context": { enabled: true, includeSelection: true },
|
|
631
|
+
"other-extension": { enabled: true, mode: "strict" },
|
|
632
|
+
},
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
requireEqual(restoration.status, 200, "setup sibling restoration patch failed");
|
|
636
|
+
requireEqual(restoration.body?.ok, true, "setup sibling restoration did not report success");
|
|
637
|
+
const persisted = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
638
|
+
requireJsonEqual(
|
|
639
|
+
persisted.vaultMind.vaults.default,
|
|
640
|
+
expectedDefaultVault,
|
|
641
|
+
"setup rerun did not preserve every default-vault sibling"
|
|
642
|
+
);
|
|
643
|
+
console.log("PASS setup rerun default-vault sibling preservation");
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
{
|
|
647
|
+
const config = await request("GET", "/vault-mind/config", { token: secrets.bridge });
|
|
648
|
+
const status = await request("GET", "/vm/status", { token: secrets.bridge });
|
|
649
|
+
requireEqual(config.status, 200, "final config reload failed");
|
|
650
|
+
requireEqual(status.status, 200, "final status reload failed");
|
|
651
|
+
requireEqual(config.body?.hasToken, true, "final config lost bridge-token status");
|
|
652
|
+
requireJsonEqual(
|
|
653
|
+
config.body?.config?.vaultMind?.vaults?.default,
|
|
654
|
+
expectedDefaultVault,
|
|
655
|
+
"final config lost default-vault siblings"
|
|
656
|
+
);
|
|
657
|
+
requireJsonEqual(
|
|
658
|
+
config.body?.config?.vaultMind?.folders,
|
|
659
|
+
{
|
|
660
|
+
inbox: "Agent/Inbox",
|
|
661
|
+
library: "Agent/Library",
|
|
662
|
+
presentations: "Agent/Presentations",
|
|
663
|
+
journal: "Agent/Journal",
|
|
664
|
+
},
|
|
665
|
+
"final config did not retain setup folders"
|
|
666
|
+
);
|
|
667
|
+
const embedding = config.body?.config?.vaultMind?.embedding;
|
|
668
|
+
requireEqual(
|
|
669
|
+
embedding?.localUrl,
|
|
670
|
+
`${localFixture.baseUrl}/v1/embeddings`,
|
|
671
|
+
"final local URL is incorrect"
|
|
672
|
+
);
|
|
673
|
+
requireEqual(
|
|
674
|
+
embedding?.remoteUrl,
|
|
675
|
+
`${remoteFixture.baseUrl}/v1/embeddings`,
|
|
676
|
+
"final remote URL is incorrect"
|
|
677
|
+
);
|
|
678
|
+
requireEqual(embedding?.workspace, "configuration-e2e", "final workspace is incorrect");
|
|
679
|
+
requireEqual(embedding?.model, "zeta-remote", "final model is incorrect");
|
|
680
|
+
requireEqual(embedding?.dim, 1024, "final dimension is incorrect");
|
|
681
|
+
requireJsonEqual(
|
|
682
|
+
embedding?.fallback,
|
|
683
|
+
{ enabled: true },
|
|
684
|
+
"final fallback policy is incorrect"
|
|
685
|
+
);
|
|
686
|
+
for (const key of SECRET_KEYS) {
|
|
687
|
+
requireCondition(
|
|
688
|
+
!Object.hasOwn(embedding, LEGACY_CONFIG_KEY[key]),
|
|
689
|
+
`final config retained legacy ${LEGACY_CONFIG_KEY[key]}`
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
requireJsonEqual(
|
|
693
|
+
statusByKind(config.body, "localApiKey"),
|
|
694
|
+
expectedStatus("localApiKey", false, "none"),
|
|
695
|
+
"final local secret status is incorrect"
|
|
696
|
+
);
|
|
697
|
+
requireJsonEqual(
|
|
698
|
+
statusByKind(config.body, "remoteApiKey"),
|
|
699
|
+
expectedStatus("remoteApiKey", true, "extension-secret-store"),
|
|
700
|
+
"final remote secret status is incorrect"
|
|
701
|
+
);
|
|
702
|
+
requireJsonEqual(
|
|
703
|
+
statusByKind(config.body, "remoteReadApiKey"),
|
|
704
|
+
expectedStatus("remoteReadApiKey", true, "extension-secret-store"),
|
|
705
|
+
"final remote read status is incorrect"
|
|
706
|
+
);
|
|
707
|
+
requireJsonEqual(
|
|
708
|
+
statusByKind(config.body, "remoteWriteApiKey"),
|
|
709
|
+
expectedStatus("remoteWriteApiKey", false, "none"),
|
|
710
|
+
"final remote write status is incorrect"
|
|
711
|
+
);
|
|
712
|
+
requireEqual(status.body?.ok, true, "final status did not report success");
|
|
713
|
+
requireEqual(status.body?.configured, true, "final status did not report configured");
|
|
714
|
+
requireEqual(status.body?.embedding?.model, "zeta-remote", "final status model is incorrect");
|
|
715
|
+
requireEqual(status.body?.embedding?.dim, 1024, "final status dimension is incorrect");
|
|
716
|
+
requireEqual(
|
|
717
|
+
status.body?.server?.running,
|
|
718
|
+
true,
|
|
719
|
+
"final status did not report a running server"
|
|
720
|
+
);
|
|
721
|
+
requireEqual(
|
|
722
|
+
status.body?.server?.port,
|
|
723
|
+
extension.port,
|
|
724
|
+
"final status reported the wrong port"
|
|
725
|
+
);
|
|
726
|
+
console.log("PASS final config and status completion reload");
|
|
727
|
+
}
|
|
728
|
+
} catch (error) {
|
|
729
|
+
failure = error;
|
|
730
|
+
} finally {
|
|
731
|
+
const cleanupErrors = [];
|
|
732
|
+
const attemptCleanup = async (action) => {
|
|
733
|
+
try {
|
|
734
|
+
await action();
|
|
735
|
+
} catch (error) {
|
|
736
|
+
cleanupErrors.push(error);
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
await attemptCleanup(() => stopExtension(extension));
|
|
740
|
+
await attemptCleanup(() => closeServer(localFixture?.server));
|
|
741
|
+
await attemptCleanup(() => closeServer(remoteFixture?.server));
|
|
742
|
+
await attemptCleanup(async () => {
|
|
743
|
+
if (extension) {
|
|
744
|
+
requireSecretFree(extension.stdout, fragments, "captured compiled extension stdout");
|
|
745
|
+
requireSecretFree(extension.stderr, fragments, "captured compiled extension stderr");
|
|
746
|
+
}
|
|
747
|
+
for (const payload of observedPayloads) {
|
|
748
|
+
requireSecretFree(payload, fragments, "captured HTTP response");
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
await attemptCleanup(async () => {
|
|
752
|
+
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
753
|
+
requireCondition(!fs.existsSync(tempRoot), "temporary vault cleanup failed");
|
|
754
|
+
});
|
|
755
|
+
teardownFailure = cleanupErrors[0];
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
if (failure && teardownFailure) {
|
|
759
|
+
const failureMessage = failure instanceof Error ? failure.message : String(failure);
|
|
760
|
+
const cleanupMessage =
|
|
761
|
+
teardownFailure instanceof Error ? teardownFailure.message : String(teardownFailure);
|
|
762
|
+
throw new Error(`${failureMessage}; cleanup also failed: ${cleanupMessage}`);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
if (failure) throw failure;
|
|
766
|
+
if (teardownFailure) throw teardownFailure;
|
|
767
|
+
console.log("PASS child-output sentinel scan and deterministic teardown");
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
let exitCode = 0;
|
|
771
|
+
let failureFragments = [];
|
|
772
|
+
try {
|
|
773
|
+
await main();
|
|
774
|
+
} catch (error) {
|
|
775
|
+
exitCode = 1;
|
|
776
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
777
|
+
if (error instanceof CompiledOutputBlocker) {
|
|
778
|
+
console.error(`BLOCKED configuration-e2e: ${message}`);
|
|
779
|
+
} else {
|
|
780
|
+
console.error(`FAIL configuration-e2e: ${redactText(message, failureFragments)}`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
process.exitCode = exitCode;
|