mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 11:24:08 +01:00
Merge commit '69c14b17d57d5eef537dacbd533ee88865a0a00a' into capy/gsta240-flaky
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> # Conflicts: # test/helpers/restamp-fixture.ts
This commit is contained in:
commit
bc873cbb11
352 files changed
+14646
-1746
No files matched your search
@@ -10,7 +10,8 @@ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { BASE_POLICY, cleanup, copyFixtureRepo, makeFixtureRepo, makePr, recordAndBundle, restamp, runBin, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
import { gitFixtureTemplate, rebindFile, rebindGitDir, type GitFixtureTemplate } from './helpers/git-fixture-template';
|
||||
import { BASE_POLICY, cleanup, fixtureRepoAt, makePr, recordAndBundle, restamp, runBin, seedFixtureRepo, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
@@ -44,8 +45,9 @@ const TESTS_LANE: Lanes = [{ label: 'tests', command: 'true' }];
|
||||
const DIGEST_LANES: Lanes = [...TESTS_LANE, { label: 'digest', command: 'cat generated/digest.md' }];
|
||||
|
||||
/** pr-a adds migration v240, is stamped 1.2.4.0 and gated (lanes recorded and bundled); then restamped to 1.2.5.0. */
|
||||
function buildGated(lanes: Lanes) {
|
||||
const repo = makeFixtureRepo({ prefix: 'pregate-regate-', policy: POLICY });
|
||||
function buildGated(root: string, lanes: Lanes) {
|
||||
seedFixtureRepo(root, { policy: POLICY });
|
||||
const repo = fixtureRepoAt(root);
|
||||
makePr(repo, 'pr-a', { expects: '1.2.4.0' });
|
||||
fs.mkdirSync(path.join(repo.work, 'migrations'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, 'migrations', 'v240-add-index.sql'), 'create index a;\n');
|
||||
@@ -57,18 +59,37 @@ function buildGated(lanes: Lanes) {
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
expect(restamp(repo, ['--version', '1.2.5.0']).status).toBe(EXIT.ok);
|
||||
repo.git('commit', '-qam', 'stamp 1.2.5.0');
|
||||
return { repo, head, current: repo.git('rev-parse', 'HEAD') };
|
||||
return { head, current: repo.git('rev-parse', 'HEAD') };
|
||||
}
|
||||
|
||||
// Each fixture costs four gstack bin runs (two restamps, an evidence run and a bundle); build each lane set once
|
||||
// and give every test its own copy instead of rebuilding it per test.
|
||||
const templates = new Map<Lanes, ReturnType<typeof buildGated>>();
|
||||
beforeAll(() => { for (const lanes of [TESTS_LANE, DIGEST_LANES]) templates.set(lanes, buildGated(lanes)); }, 60_000);
|
||||
afterAll(() => { for (const t of templates.values()) cleanup(t.repo); });
|
||||
const templates = new Map<Lanes, GitFixtureTemplate<ReturnType<typeof buildGated>>>();
|
||||
beforeAll(() => {
|
||||
for (const lanes of [TESTS_LANE, DIGEST_LANES]) {
|
||||
const template = gitFixtureTemplate({
|
||||
prefix: 'pregate-regate-',
|
||||
build: root => buildGated(root, lanes),
|
||||
rebind: (copy, tpl) => {
|
||||
rebindGitDir(path.join(copy, 'work', '.git'), tpl, copy);
|
||||
rebindFile(path.join(copy, 'bundle.json'), tpl, copy);
|
||||
const projects = path.join(copy, 'home', 'projects');
|
||||
for (const slug of fs.existsSync(projects) ? fs.readdirSync(projects) : []) {
|
||||
const dir = path.join(projects, slug.split(path.basename(tpl)).join(path.basename(copy)));
|
||||
if (dir !== path.join(projects, slug)) fs.renameSync(path.join(projects, slug), dir);
|
||||
for (const file of fs.readdirSync(dir, { recursive: true, withFileTypes: true })) if (file.isFile()) rebindFile(path.join(file.parentPath, file.name), tpl, copy);
|
||||
}
|
||||
fs.rmSync(path.join(copy, 'home', '.capy'), { recursive: true, force: true });
|
||||
},
|
||||
});
|
||||
template.copy().root && templates.set(lanes, template);
|
||||
}
|
||||
}, 60_000);
|
||||
afterAll(() => { for (const t of templates.values()) t.dispose(); });
|
||||
|
||||
function gatedThenRestamped(lanes: Lanes = TESTS_LANE) {
|
||||
const { repo: template, head, current } = templates.get(lanes)!;
|
||||
const repo = copyFixtureRepo(template, 'pregate-regate-');
|
||||
const { root, meta: { head, current } } = templates.get(lanes)!.copy();
|
||||
const repo = fixtureRepoAt(root);
|
||||
repos.push(repo);
|
||||
return { repo, head, bundle: path.join(repo.root, 'bundle.json'), current };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user