fallow-similar-code 3.43.1 → 3.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fallow-similar-code",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.44.0",
|
|
4
4
|
"description": "First-party local embedding sidecar for Fallow similar-code analysis",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"bin",
|
|
18
18
|
"scripts",
|
|
19
|
+
"!scripts/*.test.js",
|
|
19
20
|
"README.md",
|
|
20
21
|
"LICENSE"
|
|
21
22
|
],
|
|
@@ -26,13 +27,13 @@
|
|
|
26
27
|
"detect-libc": "2.1.2"
|
|
27
28
|
},
|
|
28
29
|
"optionalDependencies": {
|
|
29
|
-
"@fallow-cli/fallow-similar-code-darwin-arm64": "3.
|
|
30
|
-
"@fallow-cli/fallow-similar-code-darwin-x64": "3.
|
|
31
|
-
"@fallow-cli/fallow-similar-code-linux-x64-gnu": "3.
|
|
32
|
-
"@fallow-cli/fallow-similar-code-linux-arm64-gnu": "3.
|
|
33
|
-
"@fallow-cli/fallow-similar-code-linux-x64-musl": "3.
|
|
34
|
-
"@fallow-cli/fallow-similar-code-linux-arm64-musl": "3.
|
|
35
|
-
"@fallow-cli/fallow-similar-code-win32-x64-msvc": "3.
|
|
36
|
-
"@fallow-cli/fallow-similar-code-win32-arm64-msvc": "3.
|
|
30
|
+
"@fallow-cli/fallow-similar-code-darwin-arm64": "3.44.0",
|
|
31
|
+
"@fallow-cli/fallow-similar-code-darwin-x64": "3.44.0",
|
|
32
|
+
"@fallow-cli/fallow-similar-code-linux-x64-gnu": "3.44.0",
|
|
33
|
+
"@fallow-cli/fallow-similar-code-linux-arm64-gnu": "3.44.0",
|
|
34
|
+
"@fallow-cli/fallow-similar-code-linux-x64-musl": "3.44.0",
|
|
35
|
+
"@fallow-cli/fallow-similar-code-linux-arm64-musl": "3.44.0",
|
|
36
|
+
"@fallow-cli/fallow-similar-code-win32-x64-msvc": "3.44.0",
|
|
37
|
+
"@fallow-cli/fallow-similar-code-win32-arm64-msvc": "3.44.0"
|
|
37
38
|
}
|
|
38
39
|
}
|
package/scripts/run-binary.js
CHANGED
|
@@ -15,10 +15,10 @@ const SETUP_HARD_EXIT_GRACE_MS = 1000;
|
|
|
15
15
|
const SETUP_TIMEOUT_EXIT_CODE = 124;
|
|
16
16
|
const SETUP_TIMEOUT_MESSAGE =
|
|
17
17
|
"local model setup timed out; check DNS, proxy, and network connectivity before retrying";
|
|
18
|
-
const SIGNAL_EXIT_CODES =
|
|
18
|
+
const SIGNAL_EXIT_CODES = [
|
|
19
19
|
["SIGINT", 130],
|
|
20
20
|
["SIGTERM", 143],
|
|
21
|
-
]
|
|
21
|
+
];
|
|
22
22
|
|
|
23
23
|
const detectLibc = () => {
|
|
24
24
|
try {
|
|
@@ -122,7 +122,7 @@ const superviseSetup = async (
|
|
|
122
122
|
});
|
|
123
123
|
let forceTimer;
|
|
124
124
|
let hardExitTimer;
|
|
125
|
-
let
|
|
125
|
+
let forwardedExit;
|
|
126
126
|
let timedOut = false;
|
|
127
127
|
let resolveHardExit;
|
|
128
128
|
const hardExit = new Promise((resolve) => {
|
|
@@ -144,11 +144,11 @@ const superviseSetup = async (
|
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
const signalHandlers = new Map();
|
|
147
|
-
for (const signal of SIGNAL_EXIT_CODES
|
|
147
|
+
for (const [signal, status] of SIGNAL_EXIT_CODES) {
|
|
148
148
|
const handler = () => {
|
|
149
149
|
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
150
|
-
|
|
151
|
-
terminate(signal,
|
|
150
|
+
forwardedExit ??= { signal, status, timedOut: false };
|
|
151
|
+
terminate(signal, forwardedExit.status);
|
|
152
152
|
};
|
|
153
153
|
signalHandlers.set(signal, handler);
|
|
154
154
|
process.on(signal, handler);
|
|
@@ -165,14 +165,7 @@ const superviseSetup = async (
|
|
|
165
165
|
if (timedOut) {
|
|
166
166
|
return { status: SETUP_TIMEOUT_EXIT_CODE, signal: null, timedOut: true };
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
return {
|
|
170
|
-
status: SIGNAL_EXIT_CODES.get(forwardedSignal) ?? 1,
|
|
171
|
-
signal: forwardedSignal,
|
|
172
|
-
timedOut: false,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
return { status: status ?? 1, signal, timedOut: false };
|
|
168
|
+
return forwardedExit ?? { status: status ?? 1, signal, timedOut: false };
|
|
176
169
|
} finally {
|
|
177
170
|
clearTimeout(timeout);
|
|
178
171
|
if (forceTimer) clearTimeout(forceTimer);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const assert = require("node:assert/strict");
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const test = require("node:test");
|
|
7
|
-
const companion = require("../package.json");
|
|
8
|
-
|
|
9
|
-
test("all optional native packages are exact-version compatible", () => {
|
|
10
|
-
for (const [name, version] of Object.entries(companion.optionalDependencies)) {
|
|
11
|
-
assert.equal(version, companion.version);
|
|
12
|
-
const directory = name.replace("@fallow-cli/fallow-similar-code-", "fallow-similar-code-");
|
|
13
|
-
const manifestPath = path.join(__dirname, "..", "..", directory, "package.json");
|
|
14
|
-
const native = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
15
|
-
assert.equal(native.name, name);
|
|
16
|
-
assert.equal(native.version, companion.version);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const assert = require("node:assert/strict");
|
|
4
|
-
const test = require("node:test");
|
|
5
|
-
const { getPlatformPackage, isPlatformPackage } = require("./platform-package");
|
|
6
|
-
|
|
7
|
-
test("maps every supported target to its platform package", () => {
|
|
8
|
-
assert.equal(
|
|
9
|
-
getPlatformPackage("darwin", "arm64"),
|
|
10
|
-
"@fallow-cli/fallow-similar-code-darwin-arm64",
|
|
11
|
-
);
|
|
12
|
-
assert.equal(
|
|
13
|
-
getPlatformPackage("linux", "x64", "glibc"),
|
|
14
|
-
"@fallow-cli/fallow-similar-code-linux-x64-gnu",
|
|
15
|
-
);
|
|
16
|
-
assert.equal(
|
|
17
|
-
getPlatformPackage("linux", "arm64", "musl"),
|
|
18
|
-
"@fallow-cli/fallow-similar-code-linux-arm64-musl",
|
|
19
|
-
);
|
|
20
|
-
assert.equal(
|
|
21
|
-
getPlatformPackage("win32", "x64"),
|
|
22
|
-
"@fallow-cli/fallow-similar-code-win32-x64-msvc",
|
|
23
|
-
);
|
|
24
|
-
assert.equal(getPlatformPackage("freebsd", "x64"), undefined);
|
|
25
|
-
assert.equal(isPlatformPackage("@fallow-cli/fallow-similar-code-darwin-arm64"), true);
|
|
26
|
-
assert.equal(isPlatformPackage("@fallow-cli/darwin-arm64"), false);
|
|
27
|
-
});
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const assert = require("node:assert/strict");
|
|
4
|
-
const test = require("node:test");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const crypto = require("node:crypto");
|
|
7
|
-
const fs = require("node:fs");
|
|
8
|
-
const os = require("node:os");
|
|
9
|
-
const { spawn } = require("node:child_process");
|
|
10
|
-
const { once } = require("node:events");
|
|
11
|
-
const { resolvePlatformPackage } = require("./run-binary");
|
|
12
|
-
const ownManifest = require("../package.json");
|
|
13
|
-
const {
|
|
14
|
-
SETUP_PROCESS_TIMEOUT_MS,
|
|
15
|
-
SETUP_TIMEOUT_EXIT_CODE,
|
|
16
|
-
SETUP_TIMEOUT_MESSAGE,
|
|
17
|
-
resolveBinaryArtifact,
|
|
18
|
-
setupTimeoutFor,
|
|
19
|
-
spawnNative,
|
|
20
|
-
superviseSetup,
|
|
21
|
-
} = require("./run-binary");
|
|
22
|
-
|
|
23
|
-
const PACKAGE_NAME = "@fallow-cli/fallow-similar-code-darwin-arm64";
|
|
24
|
-
const manifest = (overrides = {}) =>
|
|
25
|
-
JSON.stringify({ name: PACKAGE_NAME, version: ownManifest.version, ...overrides });
|
|
26
|
-
|
|
27
|
-
test("resolves an exact-version regular native binary", () => {
|
|
28
|
-
const manifestPath = path.join("/packages", "native", "package.json");
|
|
29
|
-
const resolved = resolveBinaryArtifact(
|
|
30
|
-
PACKAGE_NAME,
|
|
31
|
-
() => manifestPath,
|
|
32
|
-
() => manifest(),
|
|
33
|
-
() => ({ isFile: () => true, isSymbolicLink: () => false }),
|
|
34
|
-
);
|
|
35
|
-
assert.equal(resolved.binaryPath, path.join("/packages", "native", "fallow-similar-code"));
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("rejects a platform package from another release", () => {
|
|
39
|
-
assert.throws(
|
|
40
|
-
() =>
|
|
41
|
-
resolveBinaryArtifact(
|
|
42
|
-
PACKAGE_NAME,
|
|
43
|
-
() => "/native/package.json",
|
|
44
|
-
() => manifest({ version: "0.0.0" }),
|
|
45
|
-
() => ({ isFile: () => true, isSymbolicLink: () => false }),
|
|
46
|
-
),
|
|
47
|
-
/version mismatch/,
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("rejects symlinked binaries", () => {
|
|
52
|
-
assert.throws(
|
|
53
|
-
() =>
|
|
54
|
-
resolveBinaryArtifact(
|
|
55
|
-
PACKAGE_NAME,
|
|
56
|
-
() => "/native/package.json",
|
|
57
|
-
() => manifest(),
|
|
58
|
-
(filePath) => ({
|
|
59
|
-
isFile: () => true,
|
|
60
|
-
isSymbolicLink: () => !filePath.endsWith("package.json"),
|
|
61
|
-
}),
|
|
62
|
-
),
|
|
63
|
-
/not a regular file/,
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("rejects a symlinked platform manifest", () => {
|
|
68
|
-
assert.throws(
|
|
69
|
-
() =>
|
|
70
|
-
resolveBinaryArtifact(
|
|
71
|
-
PACKAGE_NAME,
|
|
72
|
-
() => "/native/package.json",
|
|
73
|
-
() => manifest(),
|
|
74
|
-
() => ({ isFile: () => true, isSymbolicLink: () => true }),
|
|
75
|
-
),
|
|
76
|
-
/platform manifest is not a regular file/,
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("returns the exact owning manifest in the verification artifact", () => {
|
|
81
|
-
const manifestPath = path.join("/packages", "native", "package.json");
|
|
82
|
-
const artifact = resolveBinaryArtifact(
|
|
83
|
-
PACKAGE_NAME,
|
|
84
|
-
() => manifestPath,
|
|
85
|
-
() => manifest(),
|
|
86
|
-
() => ({ isFile: () => true, isSymbolicLink: () => false }),
|
|
87
|
-
);
|
|
88
|
-
assert.deepEqual(artifact, {
|
|
89
|
-
packageName: PACKAGE_NAME,
|
|
90
|
-
packageVersion: ownManifest.version,
|
|
91
|
-
manifestPath,
|
|
92
|
-
binaryName: "fallow-similar-code",
|
|
93
|
-
binaryPath: path.join("/packages", "native", "fallow-similar-code"),
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("rejects a manifest that does not belong to the resolved package", () => {
|
|
98
|
-
assert.throws(
|
|
99
|
-
() =>
|
|
100
|
-
resolveBinaryArtifact(
|
|
101
|
-
PACKAGE_NAME,
|
|
102
|
-
() => "/native/package.json",
|
|
103
|
-
() => manifest({ name: "@fallow-cli/other" }),
|
|
104
|
-
() => ({ isFile: () => true, isSymbolicLink: () => false }),
|
|
105
|
-
),
|
|
106
|
-
/ownership mismatch/,
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test("uses the Windows executable basename in the artifact", () => {
|
|
111
|
-
const artifact = resolveBinaryArtifact(
|
|
112
|
-
PACKAGE_NAME,
|
|
113
|
-
() => path.join("C:\\packages", "native", "package.json"),
|
|
114
|
-
() => manifest(),
|
|
115
|
-
() => ({ isFile: () => true, isSymbolicLink: () => false }),
|
|
116
|
-
"win32",
|
|
117
|
-
);
|
|
118
|
-
assert.equal(artifact.binaryName, "fallow-similar-code.exe");
|
|
119
|
-
assert.match(artifact.binaryPath, /fallow-similar-code\.exe$/);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test("bounds only the direct setup command", () => {
|
|
123
|
-
assert.equal(setupTimeoutFor(["setup", "--local"]), SETUP_PROCESS_TIMEOUT_MS);
|
|
124
|
-
assert.equal(setupTimeoutFor(["status", "--json"]), null);
|
|
125
|
-
assert.equal(setupTimeoutFor(["serve"]), null);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test("setup timeout guidance names the network phases a user can inspect", () => {
|
|
129
|
-
assert.match(SETUP_TIMEOUT_MESSAGE, /timed out/);
|
|
130
|
-
assert.match(SETUP_TIMEOUT_MESSAGE, /DNS/);
|
|
131
|
-
assert.match(SETUP_TIMEOUT_MESSAGE, /proxy/);
|
|
132
|
-
assert.match(SETUP_TIMEOUT_MESSAGE, /network connectivity/);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test("force-kills a local setup process that ignores graceful termination", async () => {
|
|
136
|
-
const result = await superviseSetup(
|
|
137
|
-
process.execPath,
|
|
138
|
-
["-e", "process.on('SIGTERM', () => {}); setInterval(() => {}, 1000)"],
|
|
139
|
-
{ timeoutMs: 80, terminateGraceMs: 40, hardExitGraceMs: 100 },
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
assert.deepEqual(result, {
|
|
143
|
-
status: SETUP_TIMEOUT_EXIT_CODE,
|
|
144
|
-
signal: null,
|
|
145
|
-
timedOut: true,
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test("returns a successful local setup process result", async () => {
|
|
150
|
-
const result = await superviseSetup(process.execPath, ["-e", "process.exit(0)"], {
|
|
151
|
-
timeoutMs: 1000,
|
|
152
|
-
terminateGraceMs: 40,
|
|
153
|
-
hardExitGraceMs: 100,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
assert.deepEqual(result, { status: 0, signal: null, timedOut: false });
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test("spawns non-setup commands without a wrapper timeout", () => {
|
|
160
|
-
let captured = null;
|
|
161
|
-
const result = spawnNative("/fixture/sidecar", ["status", "--json"], (binary, args, options) => {
|
|
162
|
-
captured = { binary, args, options };
|
|
163
|
-
return { status: 0, signal: null };
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
assert.equal(result.status, 0);
|
|
167
|
-
assert.equal(captured.binary, "/fixture/sidecar");
|
|
168
|
-
assert.deepEqual(captured.args, ["status", "--json"]);
|
|
169
|
-
assert.deepEqual(captured.options, { env: process.env, stdio: "inherit" });
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test(
|
|
173
|
-
"the signed setup launcher preserves forwarded SIGTERM as exit 143",
|
|
174
|
-
{ skip: process.platform === "win32", timeout: 10_000 },
|
|
175
|
-
async (t) => {
|
|
176
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), "fallow-setup-signal-"));
|
|
177
|
-
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
178
|
-
const packageName = resolvePlatformPackage();
|
|
179
|
-
const packageDir = path.join(root, "node_modules", packageName);
|
|
180
|
-
fs.mkdirSync(packageDir, { recursive: true });
|
|
181
|
-
const binaryName = "fallow-similar-code";
|
|
182
|
-
const binaryPath = path.join(packageDir, binaryName);
|
|
183
|
-
const binary = Buffer.from(
|
|
184
|
-
"#!/usr/bin/env node\nprocess.on('SIGTERM', () => process.exit(0)); process.stdout.write('READY\\n'); setInterval(() => {}, 1000);\n",
|
|
185
|
-
);
|
|
186
|
-
const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519");
|
|
187
|
-
fs.writeFileSync(binaryPath, binary, { mode: 0o755 });
|
|
188
|
-
fs.writeFileSync(`${binaryPath}.sig`, crypto.sign(null, binary, privateKey));
|
|
189
|
-
fs.writeFileSync(
|
|
190
|
-
path.join(packageDir, "package.json"),
|
|
191
|
-
JSON.stringify({
|
|
192
|
-
name: packageName,
|
|
193
|
-
version: ownManifest.version,
|
|
194
|
-
fallowDigests: {
|
|
195
|
-
[binaryName]: `sha256:${crypto.createHash("sha256").update(binary).digest("hex")}`,
|
|
196
|
-
},
|
|
197
|
-
}),
|
|
198
|
-
);
|
|
199
|
-
// The real verifier checks a signed fixture using an ephemeral trust key.
|
|
200
|
-
// Package resolution, digest verification, spawning and signal forwarding all run.
|
|
201
|
-
const driver = `
|
|
202
|
-
const crypto = require("node:crypto");
|
|
203
|
-
const verifier = require(${JSON.stringify(require.resolve("./verify-binary"))});
|
|
204
|
-
const verify = verifier.verifyBinary;
|
|
205
|
-
const publicKey = crypto.createPublicKey(${JSON.stringify(publicKey.export({ type: "spki", format: "pem" }))});
|
|
206
|
-
verifier.verifyBinary = artifact => verify(artifact, { createPublicKey: () => publicKey });
|
|
207
|
-
require(${JSON.stringify(require.resolve("./run-binary"))}).run(["setup"]);
|
|
208
|
-
`;
|
|
209
|
-
const child = spawn(process.execPath, ["-e", driver], {
|
|
210
|
-
env: { ...process.env, NODE_PATH: path.join(root, "node_modules") },
|
|
211
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
212
|
-
});
|
|
213
|
-
t.after(() => child.kill("SIGKILL"));
|
|
214
|
-
let ready = false;
|
|
215
|
-
let stdout = "";
|
|
216
|
-
let stderr = "";
|
|
217
|
-
child.stdout.on("data", (chunk) => {
|
|
218
|
-
stdout += chunk.toString();
|
|
219
|
-
if (!ready && stdout.includes("READY")) {
|
|
220
|
-
ready = true;
|
|
221
|
-
child.kill("SIGTERM");
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
child.stderr.on("data", (chunk) => {
|
|
225
|
-
stderr += chunk.toString();
|
|
226
|
-
});
|
|
227
|
-
const [status, signal] = await once(child, "close");
|
|
228
|
-
assert.equal(ready, true, stderr);
|
|
229
|
-
assert.equal(signal, null);
|
|
230
|
-
assert.equal(status, 143, stderr);
|
|
231
|
-
},
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
test("a glibc host uses the static musl package when the gnu package is missing", () => {
|
|
235
|
-
const installedOnly = (name) => (request) => {
|
|
236
|
-
if (request !== `${name}/package.json`) throw new Error(`Cannot find module '${request}'`);
|
|
237
|
-
return `/nm/${request}`;
|
|
238
|
-
};
|
|
239
|
-
const gnu = "@fallow-cli/fallow-similar-code-linux-x64-gnu";
|
|
240
|
-
const musl = "@fallow-cli/fallow-similar-code-linux-x64-musl";
|
|
241
|
-
const host = { platform: "linux", arch: "x64", libc: "glibc" };
|
|
242
|
-
assert.equal(resolvePlatformPackage({ ...host, resolve: installedOnly(gnu) }), gnu);
|
|
243
|
-
assert.equal(resolvePlatformPackage({ ...host, resolve: installedOnly(musl) }), musl);
|
|
244
|
-
assert.equal(
|
|
245
|
-
resolvePlatformPackage({ ...host, libc: "musl", resolve: installedOnly(gnu) }),
|
|
246
|
-
musl,
|
|
247
|
-
"a musl host never falls back to a glibc binary",
|
|
248
|
-
);
|
|
249
|
-
assert.equal(
|
|
250
|
-
resolvePlatformPackage({ ...host, resolve: installedOnly("none") }),
|
|
251
|
-
gnu,
|
|
252
|
-
"the error names the package that matches the host",
|
|
253
|
-
);
|
|
254
|
-
});
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const assert = require("node:assert/strict");
|
|
4
|
-
const crypto = require("node:crypto");
|
|
5
|
-
const fs = require("node:fs");
|
|
6
|
-
const os = require("node:os");
|
|
7
|
-
const path = require("node:path");
|
|
8
|
-
const test = require("node:test");
|
|
9
|
-
const ownManifest = require("../package.json");
|
|
10
|
-
const { verifyBinary } = require("./verify-binary");
|
|
11
|
-
|
|
12
|
-
const PACKAGE_NAME = "@fallow-cli/fallow-similar-code-darwin-arm64";
|
|
13
|
-
const BINARY_NAME = "fallow-similar-code";
|
|
14
|
-
|
|
15
|
-
const digest = (bytes) => `sha256:${crypto.createHash("sha256").update(bytes).digest("hex")}`;
|
|
16
|
-
|
|
17
|
-
const makeFixture = (t, options = {}) => {
|
|
18
|
-
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "fallow-similar-code-verify-"));
|
|
19
|
-
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
|
|
20
|
-
const binaryPath = path.join(directory, BINARY_NAME);
|
|
21
|
-
const manifestPath = path.join(directory, "package.json");
|
|
22
|
-
const binary = options.binary ?? Buffer.from("trusted binary");
|
|
23
|
-
fs.writeFileSync(binaryPath, binary);
|
|
24
|
-
fs.writeFileSync(`${binaryPath}.sig`, options.signature ?? Buffer.alloc(64));
|
|
25
|
-
const manifest = {
|
|
26
|
-
name: PACKAGE_NAME,
|
|
27
|
-
version: ownManifest.version,
|
|
28
|
-
fallowDigests: { [BINARY_NAME]: options.digest ?? digest(binary) },
|
|
29
|
-
...options.manifest,
|
|
30
|
-
};
|
|
31
|
-
fs.writeFileSync(manifestPath, JSON.stringify(manifest));
|
|
32
|
-
return {
|
|
33
|
-
artifact: {
|
|
34
|
-
packageName: PACKAGE_NAME,
|
|
35
|
-
packageVersion: ownManifest.version,
|
|
36
|
-
manifestPath,
|
|
37
|
-
binaryName: BINARY_NAME,
|
|
38
|
-
binaryPath,
|
|
39
|
-
},
|
|
40
|
-
manifestPath,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const acceptSignature = {
|
|
45
|
-
verify: () => true,
|
|
46
|
-
createPublicKey: () => ({}),
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
test("verifies Ed25519 and the exact platform manifest digest before launch", (t) => {
|
|
50
|
-
const binary = Buffer.from("signed trusted binary");
|
|
51
|
-
const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519");
|
|
52
|
-
const { artifact } = makeFixture(t, {
|
|
53
|
-
binary,
|
|
54
|
-
signature: crypto.sign(null, binary, privateKey),
|
|
55
|
-
});
|
|
56
|
-
assert.deepEqual(verifyBinary(artifact, { createPublicKey: () => publicKey }), { ok: true });
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("rejects the legacy path-only call instead of falling back to signature-only", () => {
|
|
60
|
-
const result = verifyBinary("/native/fallow-similar-code", acceptSignature);
|
|
61
|
-
assert.equal(result.ok, false);
|
|
62
|
-
assert.equal(result.code, "artifact-invalid");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("rejects malformed and invalid detached signatures", (t) => {
|
|
66
|
-
const malformed = makeFixture(t, { signature: Buffer.alloc(63) });
|
|
67
|
-
assert.equal(verifyBinary(malformed.artifact).code, "sig-invalid");
|
|
68
|
-
|
|
69
|
-
const invalid = makeFixture(t);
|
|
70
|
-
assert.equal(
|
|
71
|
-
verifyBinary(invalid.artifact, {
|
|
72
|
-
verify: () => false,
|
|
73
|
-
createPublicKey: () => ({}),
|
|
74
|
-
}).code,
|
|
75
|
-
"sig-invalid",
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("fails closed when the embedded digest is missing or malformed", (t) => {
|
|
80
|
-
const absent = makeFixture(t, { manifest: { fallowDigests: undefined } });
|
|
81
|
-
assert.equal(verifyBinary(absent.artifact, acceptSignature).code, "digest-missing");
|
|
82
|
-
|
|
83
|
-
const missingEntry = makeFixture(t, { manifest: { fallowDigests: {} } });
|
|
84
|
-
assert.equal(verifyBinary(missingEntry.artifact, acceptSignature).code, "digest-missing");
|
|
85
|
-
|
|
86
|
-
const malformed = makeFixture(t, {
|
|
87
|
-
manifest: { fallowDigests: { [BINARY_NAME]: "not-a-digest" } },
|
|
88
|
-
});
|
|
89
|
-
assert.equal(verifyBinary(malformed.artifact, acceptSignature).code, "digest-invalid");
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("rejects digest tampering even when signature verification succeeds", (t) => {
|
|
93
|
-
const binary = Buffer.from("authentically signed but stale digest");
|
|
94
|
-
const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519");
|
|
95
|
-
const fixture = makeFixture(t, {
|
|
96
|
-
binary,
|
|
97
|
-
signature: crypto.sign(null, binary, privateKey),
|
|
98
|
-
digest: `sha256:${"a".repeat(64)}`,
|
|
99
|
-
});
|
|
100
|
-
const result = verifyBinary(fixture.artifact, { createPublicKey: () => publicKey });
|
|
101
|
-
assert.equal(result.ok, false);
|
|
102
|
-
assert.equal(result.code, "digest-mismatch");
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("rejects a manifest owned by another package or version", (t) => {
|
|
106
|
-
const wrongOwner = makeFixture(t, { manifest: { name: "@fallow-cli/other" } });
|
|
107
|
-
assert.equal(verifyBinary(wrongOwner.artifact, acceptSignature).code, "package-mismatch");
|
|
108
|
-
|
|
109
|
-
const wrongVersion = makeFixture(t, { manifest: { version: "0.0.0" } });
|
|
110
|
-
assert.equal(verifyBinary(wrongVersion.artifact, acceptSignature).code, "version-mismatch");
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test("rejects a digest from an adjacent manifest", (t) => {
|
|
114
|
-
const fixture = makeFixture(t);
|
|
115
|
-
const adjacent = fs.mkdtempSync(path.join(os.tmpdir(), "fallow-similar-code-adjacent-"));
|
|
116
|
-
t.after(() => fs.rmSync(adjacent, { recursive: true, force: true }));
|
|
117
|
-
const result = verifyBinary(
|
|
118
|
-
{ ...fixture.artifact, manifestPath: path.join(adjacent, "package.json") },
|
|
119
|
-
acceptSignature,
|
|
120
|
-
);
|
|
121
|
-
assert.equal(result.ok, false);
|
|
122
|
-
assert.equal(result.code, "package-mismatch");
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test("rejects a missing platform manifest", (t) => {
|
|
126
|
-
const fixture = makeFixture(t);
|
|
127
|
-
fs.rmSync(fixture.manifestPath);
|
|
128
|
-
assert.equal(verifyBinary(fixture.artifact, acceptSignature).code, "manifest-invalid");
|
|
129
|
-
});
|