587ff2cf47
Publish snapshot / snapshot (push) Failing after 1m58s
Publishing infrastructure - Three Gitea workflows: ci.yml (PRs, non-main pushes), publish-snapshot.yml (main -> Gitea under dist-tag @main) and release.yml (tags -> Gitea + npmjs) - Tag-driven releases as <package-dir>-v<version>; the manifest stays the source of truth and release.yml refuses to run if tag and manifest disagree - Every publish is idempotent: each step checks the registry first, so a run that fails on the second registry can simply be re-run - Hard coverage gate (85% branches) shared by CI, the pre-push hook and local runs, since the thresholds live in vitest.config.ts rather than a CI flag - README.PUBLISH.md documents the whole mechanism Toolchain - TypeScript 7 native compiler; drop tsgo and ts-node, use tsx for dev runs - Biome 1.9 -> 2.x, Vitest 1 -> 4, zod 3 -> 4, inquirer 8 -> 14, pnpm 11.17.0 - Replace inquirer-checkbox-plus-prompt, which is peer-capped at inquirer <9, with enquirer's AutoComplete; the CubeSelection contract is unchanged - Stand in for zod 4's removed z.AnyZodObject with a local AnyObjectSchema Repo hygiene - Stop tracking dist/; ignore coverage/, *.tsbuildinfo, .npmrc* and release.json - Drop package-lock.json in favour of pnpm-lock.yaml Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
128 lines
4.4 KiB
TypeScript
128 lines
4.4 KiB
TypeScript
/**
|
|
* Tests for cubes/dependencies module (BuildContext)
|
|
*/
|
|
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { z } from 'zod';
|
|
import { BuildContext } from '../src/cubes/dependencies.js';
|
|
import { Cube, Manifest } from '../src/cubes/types.js';
|
|
import { Variables } from '../src/nopy.common.js';
|
|
|
|
// Mock VariableAssignment to avoid hanging on prompts
|
|
vi.mock('../src/nopy.prompts.js', async () => {
|
|
const actual = await vi.importActual('../src/nopy.prompts.js');
|
|
return {
|
|
...actual,
|
|
VariableAssignment: vi.fn(),
|
|
};
|
|
});
|
|
|
|
/**
|
|
* Helper to create a minimal cube for testing
|
|
*/
|
|
function createTestCube(id: string, dependencies?: (vars: any) => any[]): Cube {
|
|
const manifest = Manifest.create({
|
|
id,
|
|
name: `Test ${id}`,
|
|
schema: z.object({}),
|
|
dependencies,
|
|
});
|
|
return new Cube(manifest, `/test/${id}`, 'deploy.py');
|
|
}
|
|
|
|
describe('BuildContext.resolveCube', () => {
|
|
it('resolves a single cube with no dependencies', async () => {
|
|
const cubeA = createTestCube('cube-a');
|
|
const cubes = { 'cube-a': cubeA };
|
|
const vars = new Variables();
|
|
const context = new BuildContext(cubes, vars, { cubes: [] } as any, { env: {} } as any, {
|
|
method: 'ssh',
|
|
});
|
|
|
|
await context.resolveCube('cube-a', 'host1');
|
|
|
|
expect(context.deployCalls).toHaveLength(1);
|
|
expect(context.deployCalls[0].cube).toBe('cube-a');
|
|
expect(context.deployCalls[0].host).toBe('host1');
|
|
});
|
|
|
|
it('resolves dependencies recursively', async () => {
|
|
const cubeA = createTestCube('cube-a');
|
|
const cubeB = createTestCube('cube-b', () => ['cube-a']);
|
|
const cubes = { 'cube-a': cubeA, 'cube-b': cubeB };
|
|
const vars = new Variables();
|
|
const context = new BuildContext(cubes, vars, { cubes: [] } as any, { env: {} } as any, {
|
|
method: 'ssh',
|
|
});
|
|
|
|
await context.resolveCube('cube-b', 'host1');
|
|
|
|
expect(context.deployCalls).toHaveLength(2);
|
|
// Dependencies should be resolved BEFORE the cube that depends on them
|
|
expect(context.deployCalls[0].cube).toBe('cube-a');
|
|
expect(context.deployCalls[1].cube).toBe('cube-b');
|
|
});
|
|
|
|
it('resolves dynamic dependencies based on variables', async () => {
|
|
const cubeA = createTestCube('cube-a');
|
|
const cubeB = createTestCube('cube-b');
|
|
const cubeC = createTestCube('cube-c', (vars) => (vars.USE_A ? ['cube-a'] : ['cube-b']));
|
|
|
|
cubeC.manifest.schema = z.object({ USE_A: z.boolean().default(true) });
|
|
|
|
const cubes = { 'cube-a': cubeA, 'cube-b': cubeB, 'cube-c': cubeC };
|
|
|
|
// Test with USE_A = true
|
|
const vars1 = new Variables();
|
|
const context1 = new BuildContext(cubes, vars1, { cubes: [] } as any, { env: {} } as any, {
|
|
method: 'ssh',
|
|
});
|
|
await context1.resolveCube('cube-c', 'host1');
|
|
expect(context1.deployCalls.map((c) => c.cube)).toEqual(['cube-a', 'cube-c']);
|
|
|
|
// Test with USE_A = false
|
|
const vars2 = new Variables();
|
|
vars2.assign('cube-c', 'params', { USE_A: false });
|
|
const context2 = new BuildContext(cubes, vars2, { cubes: [] } as any, { env: {} } as any, {
|
|
method: 'ssh',
|
|
});
|
|
await context2.resolveCube('cube-c', 'host1');
|
|
expect(context2.deployCalls.map((c) => c.cube)).toEqual(['cube-b', 'cube-c']);
|
|
});
|
|
|
|
it('passes variables to dependencies', async () => {
|
|
const cubeA = createTestCube('cube-a');
|
|
cubeA.manifest.schema = z.object({ VAR: z.string() });
|
|
|
|
const cubeB = createTestCube('cube-b', () => [['cube-a', { VAR: 'from-b' }]]);
|
|
|
|
const cubes = { 'cube-a': cubeA, 'cube-b': cubeB };
|
|
const vars = new Variables();
|
|
const context = new BuildContext(cubes, vars, { cubes: [] } as any, { env: {} } as any, {
|
|
method: 'ssh',
|
|
});
|
|
|
|
await context.resolveCube('cube-b', 'host1');
|
|
|
|
expect(context.deployCalls[0].cube).toBe('cube-a');
|
|
expect(context.deployCalls[0].env.VAR).toBe('from-b');
|
|
});
|
|
|
|
it('avoids duplicate calls for the same cube on the same host', async () => {
|
|
const cubeA = createTestCube('cube-a');
|
|
const cubeB = createTestCube('cube-b', () => ['cube-a']);
|
|
const cubeC = createTestCube('cube-c', () => ['cube-a', 'cube-b']);
|
|
|
|
const cubes = { 'cube-a': cubeA, 'cube-b': cubeB, 'cube-c': cubeC };
|
|
const vars = new Variables();
|
|
const context = new BuildContext(cubes, vars, { cubes: [] } as any, { env: {} } as any, {
|
|
method: 'ssh',
|
|
});
|
|
|
|
await context.resolveCube('cube-c', 'host1');
|
|
|
|
// Execution order: cube-a, cube-b, cube-c
|
|
expect(context.deployCalls.map((c) => c.cube)).toEqual(['cube-a', 'cube-b', 'cube-c']);
|
|
});
|
|
});
|