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

62 lines
2.3 KiB
JavaScript

import { mkdir, rm, writeFile } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { lotsJournal } from '../../worker/fixtures/journal.ts';
import { ownedAuthSecret, ownedCredentials } from './auth-fixture.js';
import { categoryAllocationJournal } from './fixtures/category-allocation.js';
/**
* Materialize one fictional deployment, never an operator's config or data.
* The caller must supply an absent directory whose parent already exists.
* @param {string} directory
* @param {{ journal?: string, auth?: { secret: string, credentials: { username: string, password: string } } }} [options]
*/
export async function prepareBrowserFixture(
directory,
{ journal, auth = { secret: ownedAuthSecret, credentials: ownedCredentials } } = {}
) {
directory = resolve(directory);
// This must stay outside the cleanup block: an existing directory is not ours.
await mkdir(directory, { mode: 0o700 });
try {
for (const part of ['config', 'journal', 'journal/parts', 'data']) {
await mkdir(join(directory, part), { mode: 0o700 });
}
const sourceJournal = join(directory, 'journal', 'main.journal');
const configPath = join(directory, 'config', 'hledger-reports.yaml');
const files = [
[join(directory, 'journal', 'parts', 'base.journal'), lotsJournal],
[
join(directory, 'journal', 'parts', 'category-allocation.journal'),
categoryAllocationJournal
],
[sourceJournal, 'include parts/*.journal\n'],
[
configPath,
JSON.stringify({
version: 1,
journal: journal ?? sourceJournal,
accounts: [
{ account: 'assets:bank:checking', label: 'Everyday checking', register: 'cash' },
{ account: 'assets:investments:brokerage', label: 'Brokerage', register: 'investment' },
{ account: 'assets:investments:retirement', register: 'investment' }
],
url: { app: 'http://127.0.0.1:3000' },
auth
}) + '\n'
]
];
for (const [path, content] of files) {
await writeFile(path, content, { flag: 'wx', mode: 0o600 });
}
// Written last: permissions tooling accepts only a completed owned deployment.
await writeFile(join(directory, '.fixture'), 'hledger-browser-fixture\n', {
flag: 'wx',
mode: 0o600
});
return { directory, configPath };
} catch (error) {
await rm(directory, { recursive: true, force: true });
throw error;
}
}