在 engine 的 src/workflows/roles/ 下新建一个 meta-gate.test.ts 文件。
This commit is contained in:
parent
ab7ca6328c
commit
c37cf73ab7
@ -41,7 +41,7 @@ export function createMetaCheckerRole(opts: {
|
||||
let changedFiles: string[] = [];
|
||||
try {
|
||||
// Get all uncommitted changes + last commit changes
|
||||
const diffOutput = exec('git diff --name-only HEAD~1 HEAD 2>/dev/null || git diff --name-only');
|
||||
const diffOutput = exec('git diff --name-only HEAD 2>/dev/null || git diff --name-only');
|
||||
changedFiles = diffOutput.split('\n').filter(Boolean);
|
||||
} catch {
|
||||
// No git history — check working tree
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
/**
|
||||
* Meta Gate role tests.
|
||||
* Meta Gate role tests — createMetaGateRole 的三项预检。
|
||||
*
|
||||
* 小橘 🍊 (NEKO Team)
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import type { WorkflowMessage } from '@uncaged/pulse';
|
||||
@ -25,47 +24,38 @@ function startChain(content: string): WorkflowMessage[] {
|
||||
];
|
||||
}
|
||||
|
||||
describe('meta-gate role', () => {
|
||||
it('passes for a normal engine-scoped task', async () => {
|
||||
describe('createMetaGateRole', () => {
|
||||
it('engine-dir-exists: pass when engineDir exists', async () => {
|
||||
const gate = createMetaGateRole({ engineDir: engineRoot });
|
||||
const r = await gate(
|
||||
startChain('Add feature under src/workflows/foo.ts'),
|
||||
startChain('Change src/workflows/foo.ts only'),
|
||||
't1',
|
||||
{} as any,
|
||||
);
|
||||
expect(r.meta?.pass).toBe(true);
|
||||
expect(r.meta?.checks?.every((c) => c.pass)).toBe(true);
|
||||
const c = r.meta?.checks?.find((x) => x.name === 'engine-dir-exists');
|
||||
expect(c?.pass).toBe(true);
|
||||
});
|
||||
|
||||
it('fails when task references core package path', async () => {
|
||||
it('workflows-dir-exists: pass when src/workflows exists under engineDir', async () => {
|
||||
const gate = createMetaGateRole({ engineDir: engineRoot });
|
||||
const r = await gate(
|
||||
startChain('Change src/workflows/foo.ts only'),
|
||||
't1',
|
||||
{} as any,
|
||||
);
|
||||
const c = r.meta?.checks?.find((x) => x.name === 'workflows-dir-exists');
|
||||
expect(c?.pass).toBe(true);
|
||||
});
|
||||
|
||||
it('no-core-package-paths: fail when prompt mentions core package path', async () => {
|
||||
const gate = createMetaGateRole({ engineDir: engineRoot });
|
||||
const r = await gate(
|
||||
startChain('Edit packages/pulse/src/store.ts'),
|
||||
't1',
|
||||
{} as any,
|
||||
);
|
||||
const c = r.meta?.checks?.find((x) => x.name === 'no-core-package-paths');
|
||||
expect(c?.pass).toBe(false);
|
||||
expect(r.meta?.pass).toBe(false);
|
||||
expect(r.meta?.reason).toContain('packages/pulse/src/');
|
||||
});
|
||||
|
||||
it('fails when engine directory does not exist', async () => {
|
||||
const badDir = join(tmpdir(), `missing-engine-${Date.now()}`);
|
||||
const gate = createMetaGateRole({ engineDir: badDir });
|
||||
const r = await gate(
|
||||
startChain('Only touch src/workflows/x.ts'),
|
||||
't1',
|
||||
{} as any,
|
||||
);
|
||||
expect(r.meta?.pass).toBe(false);
|
||||
expect(r.meta?.checks?.some((c) => c.name === 'engine-dir-exists' && !c.pass)).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('fails when task content is empty', async () => {
|
||||
const gate = createMetaGateRole({ engineDir: engineRoot });
|
||||
const r = await gate(startChain(' '), 't1', {} as any);
|
||||
expect(r.meta?.pass).toBe(false);
|
||||
expect(r.meta?.reason).toBe('任务内容为空');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user