scripts: the opencode2 and proc tests pass on Windows
unisong reported in #1206 that tests under scripts/ fail on Windows on main. Reproduced on the Windows box at origin/main (bun test scripts): 23 pass, 8 fail. - opencode2.test.mjs took the packages folder from a file URL's pathname, "/C:/…", and join made it "\C:\…", so seven imports failed ("Cannot find module"). It is fileURLToPath now. - scripts/sync-proc.mjs had the same pathname root. proc.test.mjs imports it, so the whole file failed to load (the eighth red). - With it loading, proc.test.mjs showed five more on Windows: its fake readFile matched "/fake-proc/123/stat" while proc.mjs joins with the system's separator, and the kill(pid, 0) walk's skip list (written with "/") skipped nothing, so it walked test folders and passed its 5s bound. The fake now matches join()'s path, and the walk compares "/" paths. proc.mjs itself is unchanged: it reads /proc on Linux only. Only scripts/ changes; no package's files, so no version. Run: - win-run (Windows 11) bun test scripts: 39 pass, 0 fail (origin/main: 23 pass, 8 fail). - mica-run (macOS) bun test scripts: 39 pass; node scripts/sync-proc.mjs ok, and on Windows too. Not tried: Linux (CI runs it).
This commit is contained in:
@@ -7,8 +7,11 @@
|
||||
import { afterAll, beforeAll, expect, test } from "bun:test"
|
||||
import { readFileSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
const packages = new URL("../packages/", import.meta.url).pathname
|
||||
// a path, not a URL's pathname: on Windows that is "/C:/…", and
|
||||
// join made it "\C:\…", which no import finds
|
||||
const packages = fileURLToPath(new URL("../packages/", import.meta.url))
|
||||
// no request leaves these tests; fetch is put back after them, since a
|
||||
// root `bun test` runs every package's files in this one process
|
||||
const realFetch = globalThis.fetch
|
||||
|
||||
@@ -3,6 +3,7 @@ const require = createRequire(import.meta.url);
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { test } from "node:test";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { processAlive, processExists, processProbe, processStatus, processZombie } from "./proc.mjs";
|
||||
import { procTargets } from "./sync-proc.mjs";
|
||||
@@ -17,7 +18,8 @@ const deps = (content, killImpl = () => {}) => ({
|
||||
platform: "linux",
|
||||
readFile: (file) => {
|
||||
if (content === undefined) err("EACCES");
|
||||
if (file === "/fake-proc/123/stat") return content;
|
||||
// proc.mjs joins with the system's separator, "\" on Windows
|
||||
if (file === join("/fake-proc", "123", "stat")) return content;
|
||||
err("ENOENT");
|
||||
},
|
||||
kill: killImpl,
|
||||
@@ -125,13 +127,14 @@ test("runtime proc copies match the canonical implementation", () => {
|
||||
// package that asks whether a pid lives goes through its proc.mjs copy.
|
||||
test("no package asks kill(pid, 0) beside its proc.mjs", () => {
|
||||
const { readdirSync } = require("node:fs");
|
||||
const { join, relative } = require("node:path");
|
||||
const { relative, sep } = require("node:path");
|
||||
const skip = /(^|\/)(node_modules|dist|test|tests|scripts|\.git)(\/|$)|\.test\.|(^|\/)proc\.mjs$|\.min\.js$|vendor/;
|
||||
const found = [];
|
||||
const walk = (dir) => {
|
||||
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
||||
const path = join(dir, entry.name);
|
||||
const rel = relative(root, path);
|
||||
// the skip list is written with "/", as relative() gives off Windows
|
||||
const rel = relative(root, path).split(sep).join("/");
|
||||
if (skip.test(rel)) continue;
|
||||
if (entry.isDirectory()) walk(path);
|
||||
else if (/\.(mjs|js|cjs|ts|mts)$/.test(entry.name) && /process\.kill\(\s*[\w.$]+\s*,\s*0\s*\)/.test(readFileSync(path, "utf8"))) found.push(rel);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
import { copyFileSync, mkdirSync, readFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(new URL("..", import.meta.url).pathname);
|
||||
const root = resolve(fileURLToPath(new URL("..", import.meta.url)));
|
||||
const source = "scripts/proc.mjs";
|
||||
export const procTargets = [
|
||||
"packages/agent-console/lib/proc.mjs",
|
||||
|
||||
Reference in New Issue
Block a user