mirror of
https://github.com/Matysh/houseplan-card
synced 2026-09-29 03:09:36 +00:00
test: spawn CLI scripts via fileURLToPath, not URL.pathname
Owner's Windows run after #496 (2338 pass, 2 fail): both remaining failures are tests building the script path as `new URL(...).pathname`, which is `/C:/Users/...` on Windows and makes Node look for `C:\C:\Users\...`. check-inputs and classify-changes CLI tests now use fileURLToPath; the portability test forbids `import.meta.url).pathname` in test/**. Issue: #496 User-Visible: no
This commit is contained in:
@@ -2,6 +2,7 @@ import test from 'node:test';
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { execFileSync } from 'node:child_process';
|
import { execFileSync } from 'node:child_process';
|
||||||
|
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
import {
|
import {
|
||||||
CHECKS, CHECK_NAMES, NOT_AN_INPUT, REUSE_JOBS, checksAffectedBy, closure, coverage, globToRegExp,
|
CHECKS, CHECK_NAMES, NOT_AN_INPUT, REUSE_JOBS, checksAffectedBy, closure, coverage, globToRegExp,
|
||||||
inputsOf, isDeclaredNotAnInput, isExecutableInput, manifest, referencesOf, stripComments,
|
inputsOf, isDeclaredNotAnInput, isExecutableInput, manifest, referencesOf, stripComments,
|
||||||
@@ -214,7 +215,8 @@ test('неизвестный вход расширяет до всех пров
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('CLI: --check печатает входы, --why объясняет цепочку, --coverage зелёный на текущем дереве', () => {
|
test('CLI: --check печатает входы, --why объясняет цепочку, --coverage зелёный на текущем дереве', () => {
|
||||||
const script = new URL('../scripts/check-inputs.mjs', import.meta.url).pathname;
|
// fileURLToPath, не URL.pathname (#496): на Windows pathname даёт «/C:/…», Node ищет C:\C:\… .
|
||||||
|
const script = fileURLToPath(new URL('../scripts/check-inputs.mjs', import.meta.url));
|
||||||
const backend = execFileSync('node', [script, '--check=backend'], { encoding: 'utf8' }).trim().split('\n');
|
const backend = execFileSync('node', [script, '--check=backend'], { encoding: 'utf8' }).trim().split('\n');
|
||||||
assert.ok(backend.includes('scripts/support-relay/relay.py'));
|
assert.ok(backend.includes('scripts/support-relay/relay.py'));
|
||||||
const why = execFileSync('node', [script, '--check=backend', '--why=scripts/sh3d-convert/convert.mjs'], { encoding: 'utf8' });
|
const why = execFileSync('node', [script, '--check=backend', '--why=scripts/sh3d-convert/convert.mjs'], { encoding: 'utf8' });
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
CHECK_OF_OUTPUT, CLASSIFIERS, OUTPUTS, PERF_PROFILES, classifyAll, classifyChanges, formatOutputs,
|
CHECK_OF_OUTPUT, CLASSIFIERS, OUTPUTS, PERF_PROFILES, classifyAll, classifyChanges, formatOutputs,
|
||||||
} from '../scripts/classify-changes.mjs';
|
} from '../scripts/classify-changes.mjs';
|
||||||
import { manifest } from '../scripts/check-inputs.mjs';
|
import { manifest } from '../scripts/check-inputs.mjs';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
// Классификация идёт из единого manifest входов (#492 §5.2) на РЕАЛЬНОМ
|
// Классификация идёт из единого manifest входов (#492 §5.2) на РЕАЛЬНОМ
|
||||||
// дереве репозитория: тест доказывает решения job `changes` для настоящих
|
// дереве репозитория: тест доказывает решения job `changes` для настоящих
|
||||||
@@ -106,7 +107,8 @@ test('fallback --all выставляет каждый известный вых
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('CLI пишет формат $GITHUB_OUTPUT: stdin — список файлов, --all — всё true', () => {
|
test('CLI пишет формат $GITHUB_OUTPUT: stdin — список файлов, --all — всё true', () => {
|
||||||
const script = new URL('../scripts/classify-changes.mjs', import.meta.url).pathname;
|
// fileURLToPath, не URL.pathname (#496): на Windows pathname даёт «/C:/…», Node ищет C:\C:\… .
|
||||||
|
const script = fileURLToPath(new URL('../scripts/classify-changes.mjs', import.meta.url));
|
||||||
const doc = p('docs', 'SUN.md');
|
const doc = p('docs', 'SUN.md');
|
||||||
const fromStdin = execFileSync('node', [script], { input: `src/iso-overlays.ts\n${doc}\n`, encoding: 'utf8' });
|
const fromStdin = execFileSync('node', [script], { input: `src/iso-overlays.ts\n${doc}\n`, encoding: 'utf8' });
|
||||||
assert.equal(fromStdin, formatOutputs(classify(['src/iso-overlays.ts', doc])));
|
assert.equal(fromStdin, formatOutputs(classify(['src/iso-overlays.ts', doc])));
|
||||||
|
|||||||
@@ -51,3 +51,12 @@ test('тесты с временным git-репозиторием изолир
|
|||||||
const text = readFileSync(new URL('./rebase-on-dev.test.mjs', import.meta.url), 'utf8');
|
const text = readFileSync(new URL('./rebase-on-dev.test.mjs', import.meta.url), 'utf8');
|
||||||
assert.match(text, /GIT_CONFIG_KEY_0: 'core\.autocrlf', GIT_CONFIG_VALUE_0: 'false'/);
|
assert.match(text, /GIT_CONFIG_KEY_0: 'core\.autocrlf', GIT_CONFIG_VALUE_0: 'false'/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('тесты не запускают скрипты по URL.pathname — на Windows это /C:/… → C:\\C:\\… (#496)', () => {
|
||||||
|
const TESTS = fileURLToPath(new URL('./', import.meta.url));
|
||||||
|
const offenders = readdirSync(TESTS)
|
||||||
|
.filter((name) => name.endsWith('.test.mjs'))
|
||||||
|
.filter((name) => /import\.meta\.url\)\.pathname/.test(readFileSync(new URL(name, `file://${TESTS}`), 'utf8')))
|
||||||
|
.filter((name) => name !== 'windows-portability.test.mjs');
|
||||||
|
assert.deepEqual(offenders, [], 'путь для execSync/spawn — только через fileURLToPath');
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user