Files
softharbor/scripts/fixture.ts
T
poli0981andClaude Opus 5.5 981e625ca1
CI / build (push) Successful in 3m19s
CI / gates (push) Successful in 1m5s
CI / record (push) Skipped
Reusable / Qodana / Qodana (push) Successful in 3m7s
Qodana / qodana (push) Successful in 3m7s
Reusable / Security / Secrets (gitleaks) (push) Successful in 10s
Reusable / Security / Rust (cargo-deny) (push) Skipped
Reusable / Security / .NET (NuGetAudit) (push) Skipped
Reusable / Security / SAST (Opengrep) (push) Successful in 24s
Reusable / Security / Dependencies (osv-scanner) (push) Successful in 17s
Security / security (push) Successful in 52s
CI / deploy (push) Successful in 1m9s
chore: move the repository to Gitea (D38) (#1)
- ci: move the workflows to Gitea Actions (D38)
- feat(site): source on Gitea, issues and bug reports on the GitLab mirror
- docs: where the project lives now — Gitea, the GitLab mirror, e-mail
- docs: the suite on Gitea — D38, CI/CD rewritten, every GitHub-era claim synced
- fix(ci): what the first Gitea runs found — Qodana and gitleaks
- fix(ci): .gitleaksignore describes the Sonar key instead of quoting it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 05:29:57 +00:00

85 lines
3.0 KiB
TypeScript

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 (SkullMute)
//
// Test kit for the build scripts. Every script resolves its inputs from
// process.cwd() (dist/, src/i18n/, src/data/…), so a test writes a throwaway
// project tree and runs the REAL script in it as a child process — the same
// way `pnpm build` and CI invoke it, exit code and all.
import { spawn, spawnSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { onTestFinished } from 'vitest';
const SCRIPTS = dirname(fileURLToPath(import.meta.url));
/** A temporary project root holding `files` (path → contents), removed after the test. */
export function project(files: Record<string, string>): string {
const root = mkdtempSync(join(tmpdir(), 'sh-script-'));
onTestFinished(() => {
rmSync(root, { recursive: true, force: true });
});
write(root, files);
return root;
}
export function write(root: string, files: Record<string, string>): void {
for (const [path, contents] of Object.entries(files)) {
mkdirSync(dirname(join(root, path)), { recursive: true });
writeFileSync(join(root, path), contents);
}
}
export interface Run {
code: number | null;
stdout: string;
/** stdout + stderr, for assertions that do not care which stream. */
out: string;
}
export function run(
script: string,
root: string,
opts: { args?: string[]; input?: string; env?: Record<string, string> } = {},
): Run {
// Never inherit GITHUB_OUTPUT: under Actions, quarantine.mjs would append to
// the CI job's real output file.
const env = { ...process.env };
Reflect.deleteProperty(env, 'GITHUB_OUTPUT');
const r = spawnSync(process.execPath, [join(SCRIPTS, script), ...(opts.args ?? [])], {
cwd: root,
input: opts.input ?? '',
encoding: 'utf8',
env: { ...env, ...opts.env },
});
return { code: r.status, stdout: r.stdout, out: r.stdout + r.stderr };
}
/**
* `run`, without blocking the event loop: for a script that talks to a server
* the test itself runs (scripts/gitea.test.ts), which spawnSync would starve.
*/
export function runAsync(
script: string,
root: string,
opts: { args?: string[]; env?: Record<string, string> } = {},
): Promise<Run> {
const env = { ...process.env };
Reflect.deleteProperty(env, 'GITHUB_OUTPUT');
return new Promise((resolve, reject) => {
const child = spawn(process.execPath, [join(SCRIPTS, script), ...(opts.args ?? [])], {
cwd: root,
env: { ...env, ...opts.env },
stdio: ['ignore', 'pipe', 'pipe'],
});
let stdout = '';
let stderr = '';
child.stdout.setEncoding('utf8').on('data', (d: string) => (stdout += d));
child.stderr.setEncoding('utf8').on('data', (d: string) => (stderr += d));
child.on('error', reject);
child.on('close', (code) => resolve({ code, stdout, out: stdout + stderr }));
});
}