Files
eleith 67cb29b7f6
ci/woodpecker/pr/config Pipeline was successful
ci/woodpecker/pr/hledger Pipeline was successful
ci/woodpecker/pr/jobs Pipeline was successful
ci/woodpecker/pr/snapshots Pipeline was successful
ci/woodpecker/pr/web Pipeline was successful
ci/woodpecker/pr/worker Pipeline was successful
ci/woodpecker/push/config Pipeline was successful
ci/woodpecker/push/hledger Pipeline was successful
ci/woodpecker/push/jobs Pipeline was successful
ci/woodpecker/push/snapshots Pipeline was successful
ci/woodpecker/push/web Pipeline was successful
ci/woodpecker/push/worker Pipeline was successful
test: generate small fixtures and simplify CI setup
2026-11-06 16:38:05 -08:00

57 lines
2.1 KiB
JavaScript

import { chown, chmod, lstat, readFile, readdir } from 'node:fs/promises';
import { join } from 'node:path';
// Standalone root-container entry point, inside /app's explicit ES module package.
// No configurable targets: this can touch only the marked owned /fixture mount.
async function main() {
if (process.argv.length !== 2 || process.getuid?.() !== 0) {
throw new Error('Fixture permissions require a root container without arguments.');
}
const root = '/fixture';
const marker = 'hledger-browser-fixture\n';
if (!(await lstat(root)).isDirectory()) throw new Error('Fixture mount must be a directory.');
const markerPath = join(root, '.fixture');
const markerStat = await lstat(markerPath);
if (
!markerStat.isFile() ||
markerStat.size !== Buffer.byteLength(marker) ||
(await readFile(markerPath, 'utf8')) !== marker
) {
throw new Error('Fixture ownership marker is missing or invalid.');
}
/** @type {{ path: string, directory: boolean }[]} */
const entries = [];
/** @param {string} path */
async function walk(path) {
const stat = await lstat(path);
if (!stat.isDirectory() && !stat.isFile()) {
throw new Error('Fixture contains a symlink or nonregular entry.');
}
entries.push({ path, directory: stat.isDirectory() });
if (stat.isDirectory()) {
for (const name of await readdir(path)) await walk(join(path, name));
}
}
// Validate the entire tree before changing any ownership or permissions.
await walk(root);
const data = join(root, 'data');
if (!(await lstat(data)).isDirectory() || (await readdir(data)).length !== 0) {
throw new Error('Fixture data must be an empty directory.');
}
for (const { path, directory } of entries) {
// Keep host-owned parents traversable by Compose when it resolves file mounts.
if (path !== root && path !== join(root, 'config')) await chown(path, 1000, 1000);
await chmod(path, directory ? 0o700 : 0o600);
}
}
try {
await main();
} catch {
console.error(
'Browser fixture permissions failed. Require a completed marked /fixture mount with empty data and no symlinks or nonregular entries, in a root container without arguments.'
);
process.exitCode = 1;
}