@specific.dev/spectest 0.90.1 → 0.90.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coverage.d.ts +2 -0
- package/dist/coverage.js +15 -10
- package/dist/harness/browser-coverage.d.ts +4 -3
- package/dist/harness/browser-coverage.js +14 -8
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/project-files.js +4 -35
- package/package.json +1 -1
- package/src/coverage.test.ts +28 -0
- package/src/coverage.ts +15 -10
- package/src/harness/browser-coverage.test.ts +9 -6
- package/src/harness/browser-coverage.ts +12 -7
- package/src/index.ts +1 -2
- package/src/project-files.ts +4 -37
package/dist/coverage.d.ts
CHANGED
|
@@ -213,6 +213,8 @@ export declare const NODE_COVERAGE_DUMP_PREFIX = "node-";
|
|
|
213
213
|
* source map: the inline `data:` map in the text, the file the last
|
|
214
214
|
* `sourceMappingURL` comment names, or `<script>.map` next to the
|
|
215
215
|
* script; `sourcesContent` dropped (the sources are the repository).
|
|
216
|
+
* Records are keyed by their descriptor and compiled-source hash, not
|
|
217
|
+
* their URL: a recompilation can reuse a URL with different source.
|
|
216
218
|
* "Once per branch" is a marker file under `.spectest/scripts/`: the
|
|
217
219
|
* directory is shared by every process of the service and forks with
|
|
218
220
|
* the environment, so a record written at bring-up or by an ancestor
|
package/dist/coverage.js
CHANGED
|
@@ -196,6 +196,8 @@ export const NODE_COVERAGE_DUMP_PREFIX = "node-";
|
|
|
196
196
|
* source map: the inline `data:` map in the text, the file the last
|
|
197
197
|
* `sourceMappingURL` comment names, or `<script>.map` next to the
|
|
198
198
|
* script; `sourcesContent` dropped (the sources are the repository).
|
|
199
|
+
* Records are keyed by their descriptor and compiled-source hash, not
|
|
200
|
+
* their URL: a recompilation can reuse a URL with different source.
|
|
199
201
|
* "Once per branch" is a marker file under `.spectest/scripts/`: the
|
|
200
202
|
* directory is shared by every process of the service and forks with
|
|
201
203
|
* the environment, so a record written at bring-up or by an ancestor
|
|
@@ -242,7 +244,9 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
242
244
|
const SELF = url.pathToFileURL(__filename).href;
|
|
243
245
|
const SCRIPTS = path.join(dir, ${JSON.stringify(NODE_COVERAGE_SCRIPTS_SUBDIR)});
|
|
244
246
|
const MARKERS = path.join(dir, ${JSON.stringify(NODE_COVERAGE_MARKERS_SUBDIR)});
|
|
245
|
-
|
|
247
|
+
// V8 script ids identify a compiled script within this process. A URL
|
|
248
|
+
// can be reused by another process, vm context, or compilation.
|
|
249
|
+
const known = new Map();
|
|
246
250
|
let seq = 0;
|
|
247
251
|
|
|
248
252
|
function isApp(u) {
|
|
@@ -375,7 +379,6 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
375
379
|
fs.renameSync(tmp, file);
|
|
376
380
|
}
|
|
377
381
|
function describe(s, source) {
|
|
378
|
-
const id = idOf(s.url);
|
|
379
382
|
let scriptPath = null;
|
|
380
383
|
try {
|
|
381
384
|
scriptPath = url.fileURLToPath(s.url);
|
|
@@ -383,16 +386,20 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
383
386
|
const text = typeof source === "string" ? source : null;
|
|
384
387
|
const record = {
|
|
385
388
|
url: s.url,
|
|
389
|
+
sourceHash: text !== null ? crypto.createHash("sha256").update(text).digest("hex") : null,
|
|
386
390
|
lineLengths: text !== null ? lineLengths(text) : null,
|
|
387
391
|
functions: s.functions.map(function (f) {
|
|
388
392
|
return [f.functionName, f.ranges[0].startOffset, f.ranges[0].endOffset];
|
|
389
393
|
}),
|
|
390
394
|
sourceMap: text !== null && scriptPath !== null ? readMap(scriptPath, text) : null,
|
|
391
395
|
};
|
|
392
|
-
|
|
393
|
-
|
|
396
|
+
const document = JSON.stringify({ spectestScript: record });
|
|
397
|
+
const id = idOf(document);
|
|
398
|
+
if (!fs.existsSync(path.join(MARKERS, id))) {
|
|
399
|
+
writeAtomic(path.join(SCRIPTS, id + ".json"), document);
|
|
394
400
|
fs.writeFileSync(path.join(MARKERS, id), "");
|
|
395
|
-
}
|
|
401
|
+
}
|
|
402
|
+
return id;
|
|
396
403
|
}
|
|
397
404
|
function take() {
|
|
398
405
|
const res = post("Profiler.takePreciseCoverage");
|
|
@@ -413,9 +420,7 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
413
420
|
if (kept.length === 0 && units.size === 0) return;
|
|
414
421
|
const fresh = [];
|
|
415
422
|
for (const s of kept) {
|
|
416
|
-
if (known.has(s.
|
|
417
|
-
known.add(s.url);
|
|
418
|
-
if (!fs.existsSync(path.join(MARKERS, idOf(s.url)))) fresh.push(s);
|
|
423
|
+
if (!known.has(s.scriptId)) fresh.push(s);
|
|
419
424
|
}
|
|
420
425
|
if (fresh.length > 0) {
|
|
421
426
|
try {
|
|
@@ -426,7 +431,7 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
426
431
|
for (const s of fresh) {
|
|
427
432
|
const r = post("Debugger.getScriptSource", { scriptId: s.scriptId });
|
|
428
433
|
try {
|
|
429
|
-
describe(s, r && r.scriptSource);
|
|
434
|
+
known.set(s.scriptId, describe(s, r && r.scriptSource));
|
|
430
435
|
} catch (e) {}
|
|
431
436
|
}
|
|
432
437
|
post("Debugger.disable");
|
|
@@ -442,7 +447,7 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
442
447
|
result: kept.map(function (s) {
|
|
443
448
|
return {
|
|
444
449
|
url: s.url,
|
|
445
|
-
spectestScript:
|
|
450
|
+
spectestScript: known.get(s.scriptId) || null,
|
|
446
451
|
functions: s.functions.filter(ran).map(function (f) {
|
|
447
452
|
const first = f.ranges[0];
|
|
448
453
|
const out = [first.startOffset, first.endOffset - first.startOffset, first.count];
|
|
@@ -41,11 +41,12 @@ export interface DecodedSourceMap {
|
|
|
41
41
|
/** Decode one VLQ-encoded segment into its fields. */
|
|
42
42
|
export declare function decodeVlq(segment: string): number[];
|
|
43
43
|
/**
|
|
44
|
-
* Normalise a source-map `sources` entry
|
|
44
|
+
* Normalise a source-map `sources` entry without discarding its identity. Bundlers prefix
|
|
45
45
|
* their own scheme (`webpack:///./src/a.ts`), dev servers serve absolute
|
|
46
46
|
* URLs paths (`/src/a.ts`), builds write relative ones (`../src/a.ts`).
|
|
47
|
-
* The server
|
|
48
|
-
*
|
|
47
|
+
* The server validates file identity against the repository. Preserve
|
|
48
|
+
* virtual namespaces and external URLs; losing them makes foreign
|
|
49
|
+
* sources indistinguishable from project files.
|
|
49
50
|
*/
|
|
50
51
|
export declare function normalizeSourcePath(src: string, sourceRoot?: string): string;
|
|
51
52
|
/** Sources nobody's change can be attributed to: dependencies and bundler
|
|
@@ -86,22 +86,28 @@ export function decodeVlq(segment) {
|
|
|
86
86
|
return out;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
-
* Normalise a source-map `sources` entry
|
|
89
|
+
* Normalise a source-map `sources` entry without discarding its identity. Bundlers prefix
|
|
90
90
|
* their own scheme (`webpack:///./src/a.ts`), dev servers serve absolute
|
|
91
91
|
* URLs paths (`/src/a.ts`), builds write relative ones (`../src/a.ts`).
|
|
92
|
-
* The server
|
|
93
|
-
*
|
|
92
|
+
* The server validates file identity against the repository. Preserve
|
|
93
|
+
* virtual namespaces and external URLs; losing them makes foreign
|
|
94
|
+
* sources indistinguishable from project files.
|
|
94
95
|
*/
|
|
95
96
|
export function normalizeSourcePath(src, sourceRoot) {
|
|
96
97
|
let s = src;
|
|
97
98
|
if (sourceRoot && !/^[a-z]+:/i.test(s)) {
|
|
98
99
|
s = sourceRoot.replace(/\/?$/, "/") + s;
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
// Keep virtual source identity intact. Stripping the scheme turned
|
|
102
|
+
// webpack://_N_E/../src/utils.ts (a foreign source) into a plausible
|
|
103
|
+
// project path; a suffix match then attributed its lines to lib/utils.ts.
|
|
104
|
+
// Do not use URL here: it collapses the traversal we need to preserve.
|
|
105
|
+
if (/^(webpack|turbopack):\/\//.test(s))
|
|
106
|
+
return s;
|
|
107
|
+
s = s.replace(/^file:\/\//, "");
|
|
108
|
+
// External URLs keep their identity; Vite's /@fs is an explicit file path.
|
|
109
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(s))
|
|
110
|
+
return s;
|
|
105
111
|
s = s.replace(/^\/@fs\//, "/");
|
|
106
112
|
s = s.replace(/\?.*$/, "");
|
|
107
113
|
// Turbopack (Next.js) roots every source at the `[project]` token —
|
package/dist/index.d.ts
CHANGED
|
@@ -829,8 +829,7 @@ export type ServiceImage = {
|
|
|
829
829
|
* Runs in `defineEnvironment`, and in the daemon's runtime `startService`
|
|
830
830
|
* twin, inside the VM, where the repo sits at the project root. Existence
|
|
831
831
|
* checks go through the project-file resolver, so the same rules as
|
|
832
|
-
* `ctx.readProjectFile` apply
|
|
833
|
-
* instead of read stale).
|
|
832
|
+
* `ctx.readProjectFile` apply.
|
|
834
833
|
*/
|
|
835
834
|
export declare function validateServiceImage(serviceName: string, image: ServiceImage): ServiceImage;
|
|
836
835
|
export interface VolumeMount {
|
package/dist/index.js
CHANGED
|
@@ -253,8 +253,7 @@ const BUILD_TARGET_RE = /^[^\s]+$/;
|
|
|
253
253
|
* Runs in `defineEnvironment`, and in the daemon's runtime `startService`
|
|
254
254
|
* twin, inside the VM, where the repo sits at the project root. Existence
|
|
255
255
|
* checks go through the project-file resolver, so the same rules as
|
|
256
|
-
* `ctx.readProjectFile` apply
|
|
257
|
-
* instead of read stale).
|
|
256
|
+
* `ctx.readProjectFile` apply.
|
|
258
257
|
*/
|
|
259
258
|
export function validateServiceImage(serviceName, image) {
|
|
260
259
|
if (image.type !== "dockerfile")
|
package/dist/project-files.js
CHANGED
|
@@ -9,46 +9,20 @@
|
|
|
9
9
|
// on EVERY start, warm ones included.
|
|
10
10
|
//
|
|
11
11
|
// A warm start happens only when the warm-template hash matches, so /workspace
|
|
12
|
-
// is correct for every file that is IN that hash. It can be behind for the
|
|
13
|
-
//
|
|
14
|
-
// edit keeps the fast start)
|
|
15
|
-
// `spectest/.specignore`.
|
|
12
|
+
// is correct for every file that is IN that hash. It can be behind for the one
|
|
13
|
+
// kind of file the hash excludes: `spectest/tests/**` (excluded so a test-only
|
|
14
|
+
// edit keeps the fast start).
|
|
16
15
|
//
|
|
17
16
|
// Hence the rule below: a path under `spectest/` resolves against the app copy
|
|
18
17
|
// first, because that copy is always current — this is what lets a fixture live
|
|
19
18
|
// in `spectest/tests/fixtures/` and still be found after it was added. Any
|
|
20
19
|
// other path resolves against /workspace, which the hash keeps current.
|
|
21
|
-
|
|
22
|
-
// The remaining hole is a file that `.specignore` excludes AND that sits outside
|
|
23
|
-
// `spectest/`: /workspace holds whatever the cold start uploaded, so a later
|
|
24
|
-
// edit is invisible. Nothing can repair those bytes at read time, so we refuse
|
|
25
|
-
// to read them instead of returning stale content. The control plane writes the
|
|
26
|
-
// exact path list it excluded (env.rs) into ENV_IGNORED_FILE.
|
|
27
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
20
|
+
import { existsSync } from "node:fs";
|
|
28
21
|
import path from "node:path";
|
|
29
22
|
/** The extracted repo — `ctx.projectRoot`. */
|
|
30
23
|
export const WORKSPACE = process.env.SPECTEST_WORKSPACE ?? "/workspace";
|
|
31
24
|
/** The app dir; the user's `spectest/` sits directly under it. */
|
|
32
25
|
export const APP_DIR = process.env.SPECTEST_APP_DIR ?? "/opt/spectest/app";
|
|
33
|
-
/** Paths (repo-relative) the warm-template hash skipped because of
|
|
34
|
-
* `spectest/.specignore`. Written by the control plane at env start; absent
|
|
35
|
-
* when the project ships no `.specignore`. */
|
|
36
|
-
const ENV_IGNORED_FILE = "/run/spectest-env-ignored.json";
|
|
37
|
-
let _envIgnored;
|
|
38
|
-
function envIgnored() {
|
|
39
|
-
if (_envIgnored)
|
|
40
|
-
return _envIgnored;
|
|
41
|
-
let paths = [];
|
|
42
|
-
try {
|
|
43
|
-
const raw = JSON.parse(readFileSync(ENV_IGNORED_FILE, "utf8"));
|
|
44
|
-
paths = raw.paths ?? [];
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
/* No file (no .specignore, or an older env) — nothing to refuse. */
|
|
48
|
-
}
|
|
49
|
-
_envIgnored = new Set(paths);
|
|
50
|
-
return _envIgnored;
|
|
51
|
-
}
|
|
52
26
|
/** Project files resolved since the last take — what a test read
|
|
53
27
|
* through the SDK. Module memory: forks with the environment; the
|
|
54
28
|
* coverage capture takes and clears it after every case, so a forked
|
|
@@ -89,11 +63,6 @@ export function resolveProjectPath(p, opts = {}) {
|
|
|
89
63
|
if (existsSync(app))
|
|
90
64
|
return app;
|
|
91
65
|
}
|
|
92
|
-
if (envIgnored().has(rel)) {
|
|
93
|
-
throw new Error(`project file "${p}" is excluded by the environment cache ignore rules, so the copy in the VM ` +
|
|
94
|
-
`is whatever a cold start uploaded and can be out of date. Move it under ` +
|
|
95
|
-
`spectest/tests/ (still cache-free, and always re-uploaded), or drop the pattern.`);
|
|
96
|
-
}
|
|
97
66
|
return path.join(WORKSPACE, rel);
|
|
98
67
|
}
|
|
99
68
|
/** {@link resolveProjectPath}, but a missing file is an error that names every
|
package/package.json
CHANGED
package/src/coverage.test.ts
CHANGED
|
@@ -297,6 +297,34 @@ describe.if(hasNode)("nodeCoverage hook (real node)", () => {
|
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
299
|
|
|
300
|
+
test("recompiled scripts at the same URL get distinct records within and across processes", async () => {
|
|
301
|
+
const dir = await scratch();
|
|
302
|
+
const sharedUrl = `file://${path.join(dir, "shared.js")}`;
|
|
303
|
+
await fs.writeFile(path.join(dir, "main.js"), `
|
|
304
|
+
const vm = require("node:vm");
|
|
305
|
+
vm.runInThisContext("globalThis.value = 1;", { filename: ${JSON.stringify(sharedUrl)} });
|
|
306
|
+
vm.runInThisContext("globalThis.value = 2;", { filename: ${JSON.stringify(sharedUrl)} });
|
|
307
|
+
`);
|
|
308
|
+
expect(await runOnce(dir, "main.js")).toBe(0);
|
|
309
|
+
const first = (await Promise.all((await dumpsIn(dir)).map((n) => readDump(dir, n))))
|
|
310
|
+
.flatMap((d) => d.result).filter((s) => s.url === sharedUrl);
|
|
311
|
+
expect(first).toHaveLength(2);
|
|
312
|
+
const ids = new Set(first.map((s) => s.spectestScript));
|
|
313
|
+
expect(ids.size).toBe(2); // same URL, line lengths and extents, different source
|
|
314
|
+
for (const id of ids) {
|
|
315
|
+
const record = JSON.parse(await fs.readFile(path.join(dir, NODE_COVERAGE_SCRIPTS_SUBDIR, `${id}.json`), "utf8"));
|
|
316
|
+
expect(record.spectestScript.url).toBe(sharedUrl);
|
|
317
|
+
expect(record.spectestScript.sourceHash).toMatch(/^[a-f0-9]{64}$/);
|
|
318
|
+
}
|
|
319
|
+
// A second process shares the marker directory. Identical descriptors
|
|
320
|
+
// deduplicate, but must never borrow the other compilation's identity.
|
|
321
|
+
expect(await runOnce(dir, "main.js")).toBe(0);
|
|
322
|
+
const all = (await Promise.all((await dumpsIn(dir)).map((n) => readDump(dir, n))))
|
|
323
|
+
.flatMap((d) => d.result).filter((s) => s.url === sharedUrl);
|
|
324
|
+
expect(all).toHaveLength(4);
|
|
325
|
+
expect(new Set(all.map((s) => s.spectestScript))).toEqual(ids);
|
|
326
|
+
});
|
|
327
|
+
|
|
300
328
|
test("short-lived CLI processes write at exit; the map next to the script is recorded once, no NODE_V8_COVERAGE", async () => {
|
|
301
329
|
const dir = await scratch();
|
|
302
330
|
await fs.writeFile(path.join(dir, "cli.js"), "function used() { return 1 }\nfunction unused() { return 2 }\nused();\n");
|
package/src/coverage.ts
CHANGED
|
@@ -342,6 +342,8 @@ export const NODE_COVERAGE_DUMP_PREFIX = "node-";
|
|
|
342
342
|
* source map: the inline `data:` map in the text, the file the last
|
|
343
343
|
* `sourceMappingURL` comment names, or `<script>.map` next to the
|
|
344
344
|
* script; `sourcesContent` dropped (the sources are the repository).
|
|
345
|
+
* Records are keyed by their descriptor and compiled-source hash, not
|
|
346
|
+
* their URL: a recompilation can reuse a URL with different source.
|
|
345
347
|
* "Once per branch" is a marker file under `.spectest/scripts/`: the
|
|
346
348
|
* directory is shared by every process of the service and forks with
|
|
347
349
|
* the environment, so a record written at bring-up or by an ancestor
|
|
@@ -388,7 +390,9 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
388
390
|
const SELF = url.pathToFileURL(__filename).href;
|
|
389
391
|
const SCRIPTS = path.join(dir, ${JSON.stringify(NODE_COVERAGE_SCRIPTS_SUBDIR)});
|
|
390
392
|
const MARKERS = path.join(dir, ${JSON.stringify(NODE_COVERAGE_MARKERS_SUBDIR)});
|
|
391
|
-
|
|
393
|
+
// V8 script ids identify a compiled script within this process. A URL
|
|
394
|
+
// can be reused by another process, vm context, or compilation.
|
|
395
|
+
const known = new Map();
|
|
392
396
|
let seq = 0;
|
|
393
397
|
|
|
394
398
|
function isApp(u) {
|
|
@@ -521,7 +525,6 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
521
525
|
fs.renameSync(tmp, file);
|
|
522
526
|
}
|
|
523
527
|
function describe(s, source) {
|
|
524
|
-
const id = idOf(s.url);
|
|
525
528
|
let scriptPath = null;
|
|
526
529
|
try {
|
|
527
530
|
scriptPath = url.fileURLToPath(s.url);
|
|
@@ -529,16 +532,20 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
529
532
|
const text = typeof source === "string" ? source : null;
|
|
530
533
|
const record = {
|
|
531
534
|
url: s.url,
|
|
535
|
+
sourceHash: text !== null ? crypto.createHash("sha256").update(text).digest("hex") : null,
|
|
532
536
|
lineLengths: text !== null ? lineLengths(text) : null,
|
|
533
537
|
functions: s.functions.map(function (f) {
|
|
534
538
|
return [f.functionName, f.ranges[0].startOffset, f.ranges[0].endOffset];
|
|
535
539
|
}),
|
|
536
540
|
sourceMap: text !== null && scriptPath !== null ? readMap(scriptPath, text) : null,
|
|
537
541
|
};
|
|
538
|
-
|
|
539
|
-
|
|
542
|
+
const document = JSON.stringify({ spectestScript: record });
|
|
543
|
+
const id = idOf(document);
|
|
544
|
+
if (!fs.existsSync(path.join(MARKERS, id))) {
|
|
545
|
+
writeAtomic(path.join(SCRIPTS, id + ".json"), document);
|
|
540
546
|
fs.writeFileSync(path.join(MARKERS, id), "");
|
|
541
|
-
}
|
|
547
|
+
}
|
|
548
|
+
return id;
|
|
542
549
|
}
|
|
543
550
|
function take() {
|
|
544
551
|
const res = post("Profiler.takePreciseCoverage");
|
|
@@ -559,9 +566,7 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
559
566
|
if (kept.length === 0 && units.size === 0) return;
|
|
560
567
|
const fresh = [];
|
|
561
568
|
for (const s of kept) {
|
|
562
|
-
if (known.has(s.
|
|
563
|
-
known.add(s.url);
|
|
564
|
-
if (!fs.existsSync(path.join(MARKERS, idOf(s.url)))) fresh.push(s);
|
|
569
|
+
if (!known.has(s.scriptId)) fresh.push(s);
|
|
565
570
|
}
|
|
566
571
|
if (fresh.length > 0) {
|
|
567
572
|
try {
|
|
@@ -572,7 +577,7 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
572
577
|
for (const s of fresh) {
|
|
573
578
|
const r = post("Debugger.getScriptSource", { scriptId: s.scriptId });
|
|
574
579
|
try {
|
|
575
|
-
describe(s, r && r.scriptSource);
|
|
580
|
+
known.set(s.scriptId, describe(s, r && r.scriptSource));
|
|
576
581
|
} catch (e) {}
|
|
577
582
|
}
|
|
578
583
|
post("Debugger.disable");
|
|
@@ -588,7 +593,7 @@ export const NODE_COVERAGE_HOOK = `"use strict";
|
|
|
588
593
|
result: kept.map(function (s) {
|
|
589
594
|
return {
|
|
590
595
|
url: s.url,
|
|
591
|
-
spectestScript:
|
|
596
|
+
spectestScript: known.get(s.scriptId) || null,
|
|
592
597
|
functions: s.functions.filter(ran).map(function (f) {
|
|
593
598
|
const first = f.ranges[0];
|
|
594
599
|
const out = [first.startOffset, first.endOffset - first.startOffset, first.count];
|
|
@@ -41,10 +41,10 @@ describe("source maps", () => {
|
|
|
41
41
|
mappings: "AAAA,ICAA;ACIA",
|
|
42
42
|
});
|
|
43
43
|
expect(map).not.toBeNull();
|
|
44
|
-
expect(map!.sources).toEqual(["src/a.ts", "node_modules/x.js", "src/b.ts"]);
|
|
44
|
+
expect(map!.sources).toEqual(["webpack:///./src/a.ts", "webpack:///./node_modules/x.js", "src/b.ts"]);
|
|
45
45
|
const files = mapToOriginal(map!, new Map([[1, 2], [2, 0]]));
|
|
46
|
-
expect([...files.keys()]).toEqual(["src/a.ts", "src/b.ts"]);
|
|
47
|
-
expect(files.get("src/a.ts")!.get(1)).toBe(2);
|
|
46
|
+
expect([...files.keys()]).toEqual(["webpack:///./src/a.ts", "src/b.ts"]);
|
|
47
|
+
expect(files.get("webpack:///./src/a.ts")!.get(1)).toBe(2);
|
|
48
48
|
expect(files.get("src/b.ts")!.get(5)).toBe(0);
|
|
49
49
|
});
|
|
50
50
|
|
|
@@ -54,9 +54,12 @@ describe("source maps", () => {
|
|
|
54
54
|
expect(decodeSourceMap("nope")).toBeNull();
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
test("normalizeSourcePath
|
|
58
|
-
expect(normalizeSourcePath("webpack:///./src/a.ts")).toBe("src/a.ts");
|
|
59
|
-
expect(normalizeSourcePath("
|
|
57
|
+
test("normalizeSourcePath preserves namespaces and external origins", () => {
|
|
58
|
+
expect(normalizeSourcePath("webpack:///./src/a.ts")).toBe("webpack:///./src/a.ts");
|
|
59
|
+
expect(normalizeSourcePath("webpack://_N_E/../src/utils.ts")).toBe("webpack://_N_E/../src/utils.ts");
|
|
60
|
+
expect(normalizeSourcePath("webpack://_N_E/./lib/utils.ts")).toBe("webpack://_N_E/./lib/utils.ts");
|
|
61
|
+
expect(normalizeSourcePath("turbopack:///[project]/src/a.ts")).toBe("turbopack:///[project]/src/a.ts");
|
|
62
|
+
expect(normalizeSourcePath("http://app.test/src/a.ts?t=1")).toBe("http://app.test/src/a.ts?t=1");
|
|
60
63
|
expect(normalizeSourcePath("/@fs/repo/src/a.ts")).toBe("/repo/src/a.ts");
|
|
61
64
|
expect(normalizeSourcePath("a.ts", "/app/src")).toBe("/app/src/a.ts");
|
|
62
65
|
expect(normalizeSourcePath("file:///app/src/a.ts")).toBe("/app/src/a.ts");
|
|
@@ -119,21 +119,26 @@ export function decodeVlq(segment: string): number[] {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* Normalise a source-map `sources` entry
|
|
122
|
+
* Normalise a source-map `sources` entry without discarding its identity. Bundlers prefix
|
|
123
123
|
* their own scheme (`webpack:///./src/a.ts`), dev servers serve absolute
|
|
124
124
|
* URLs paths (`/src/a.ts`), builds write relative ones (`../src/a.ts`).
|
|
125
|
-
* The server
|
|
126
|
-
*
|
|
125
|
+
* The server validates file identity against the repository. Preserve
|
|
126
|
+
* virtual namespaces and external URLs; losing them makes foreign
|
|
127
|
+
* sources indistinguishable from project files.
|
|
127
128
|
*/
|
|
128
129
|
export function normalizeSourcePath(src: string, sourceRoot?: string): string {
|
|
129
130
|
let s = src;
|
|
130
131
|
if (sourceRoot && !/^[a-z]+:/i.test(s)) {
|
|
131
132
|
s = sourceRoot.replace(/\/?$/, "/") + s;
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
// Keep virtual source identity intact. Stripping the scheme turned
|
|
135
|
+
// webpack://_N_E/../src/utils.ts (a foreign source) into a plausible
|
|
136
|
+
// project path; a suffix match then attributed its lines to lib/utils.ts.
|
|
137
|
+
// Do not use URL here: it collapses the traversal we need to preserve.
|
|
138
|
+
if (/^(webpack|turbopack):\/\//.test(s)) return s;
|
|
139
|
+
s = s.replace(/^file:\/\//, "");
|
|
140
|
+
// External URLs keep their identity; Vite's /@fs is an explicit file path.
|
|
141
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(s)) return s;
|
|
137
142
|
s = s.replace(/^\/@fs\//, "/");
|
|
138
143
|
s = s.replace(/\?.*$/, "");
|
|
139
144
|
// Turbopack (Next.js) roots every source at the `[project]` token —
|
package/src/index.ts
CHANGED
|
@@ -1272,8 +1272,7 @@ const BUILD_TARGET_RE = /^[^\s]+$/;
|
|
|
1272
1272
|
* Runs in `defineEnvironment`, and in the daemon's runtime `startService`
|
|
1273
1273
|
* twin, inside the VM, where the repo sits at the project root. Existence
|
|
1274
1274
|
* checks go through the project-file resolver, so the same rules as
|
|
1275
|
-
* `ctx.readProjectFile` apply
|
|
1276
|
-
* instead of read stale).
|
|
1275
|
+
* `ctx.readProjectFile` apply.
|
|
1277
1276
|
*/
|
|
1278
1277
|
export function validateServiceImage(serviceName: string, image: ServiceImage): ServiceImage {
|
|
1279
1278
|
if (image.type !== "dockerfile") return image;
|
package/src/project-files.ts
CHANGED
|
@@ -9,23 +9,16 @@
|
|
|
9
9
|
// on EVERY start, warm ones included.
|
|
10
10
|
//
|
|
11
11
|
// A warm start happens only when the warm-template hash matches, so /workspace
|
|
12
|
-
// is correct for every file that is IN that hash. It can be behind for the
|
|
13
|
-
//
|
|
14
|
-
// edit keeps the fast start)
|
|
15
|
-
// `spectest/.specignore`.
|
|
12
|
+
// is correct for every file that is IN that hash. It can be behind for the one
|
|
13
|
+
// kind of file the hash excludes: `spectest/tests/**` (excluded so a test-only
|
|
14
|
+
// edit keeps the fast start).
|
|
16
15
|
//
|
|
17
16
|
// Hence the rule below: a path under `spectest/` resolves against the app copy
|
|
18
17
|
// first, because that copy is always current — this is what lets a fixture live
|
|
19
18
|
// in `spectest/tests/fixtures/` and still be found after it was added. Any
|
|
20
19
|
// other path resolves against /workspace, which the hash keeps current.
|
|
21
|
-
//
|
|
22
|
-
// The remaining hole is a file that `.specignore` excludes AND that sits outside
|
|
23
|
-
// `spectest/`: /workspace holds whatever the cold start uploaded, so a later
|
|
24
|
-
// edit is invisible. Nothing can repair those bytes at read time, so we refuse
|
|
25
|
-
// to read them instead of returning stale content. The control plane writes the
|
|
26
|
-
// exact path list it excluded (env.rs) into ENV_IGNORED_FILE.
|
|
27
20
|
|
|
28
|
-
import { existsSync
|
|
21
|
+
import { existsSync } from "node:fs";
|
|
29
22
|
import path from "node:path";
|
|
30
23
|
|
|
31
24
|
/** The extracted repo — `ctx.projectRoot`. */
|
|
@@ -33,25 +26,6 @@ export const WORKSPACE = process.env.SPECTEST_WORKSPACE ?? "/workspace";
|
|
|
33
26
|
/** The app dir; the user's `spectest/` sits directly under it. */
|
|
34
27
|
export const APP_DIR = process.env.SPECTEST_APP_DIR ?? "/opt/spectest/app";
|
|
35
28
|
|
|
36
|
-
/** Paths (repo-relative) the warm-template hash skipped because of
|
|
37
|
-
* `spectest/.specignore`. Written by the control plane at env start; absent
|
|
38
|
-
* when the project ships no `.specignore`. */
|
|
39
|
-
const ENV_IGNORED_FILE = "/run/spectest-env-ignored.json";
|
|
40
|
-
|
|
41
|
-
let _envIgnored: Set<string> | undefined;
|
|
42
|
-
function envIgnored(): Set<string> {
|
|
43
|
-
if (_envIgnored) return _envIgnored;
|
|
44
|
-
let paths: string[] = [];
|
|
45
|
-
try {
|
|
46
|
-
const raw = JSON.parse(readFileSync(ENV_IGNORED_FILE, "utf8")) as { paths?: string[] };
|
|
47
|
-
paths = raw.paths ?? [];
|
|
48
|
-
} catch {
|
|
49
|
-
/* No file (no .specignore, or an older env) — nothing to refuse. */
|
|
50
|
-
}
|
|
51
|
-
_envIgnored = new Set(paths);
|
|
52
|
-
return _envIgnored;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
29
|
/** Project files resolved since the last take — what a test read
|
|
56
30
|
* through the SDK. Module memory: forks with the environment; the
|
|
57
31
|
* coverage capture takes and clears it after every case, so a forked
|
|
@@ -92,13 +66,6 @@ export function resolveProjectPath(p: string, opts: { record?: boolean } = {}):
|
|
|
92
66
|
const app = path.join(APP_DIR, rel);
|
|
93
67
|
if (existsSync(app)) return app;
|
|
94
68
|
}
|
|
95
|
-
if (envIgnored().has(rel)) {
|
|
96
|
-
throw new Error(
|
|
97
|
-
`project file "${p}" is excluded by the environment cache ignore rules, so the copy in the VM ` +
|
|
98
|
-
`is whatever a cold start uploaded and can be out of date. Move it under ` +
|
|
99
|
-
`spectest/tests/ (still cache-free, and always re-uploaded), or drop the pattern.`,
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
69
|
return path.join(WORKSPACE, rel);
|
|
103
70
|
}
|
|
104
71
|
|