feat(research): isolate candidates and add reviewed paper promotion

This commit is contained in:
Boki 2026-10-24 18:46:55 -04:00
parent 26b97265c6
commit 25b5cbf481
128 changed files with 13038 additions and 1388 deletions

View file

@ -236,6 +236,84 @@ function http(f: Fixture) {
});
}
describe.skipIf(!url)('authoritative research principals and budgets', () => {
test('owned project links advance only revision metadata after additive migration; project authority stays operator-only', async () => {
const f = await fixture(),
p = await provision(f);
const actor = p.agent.id as `agent:${string}`;
const clone = await f.catalog.cloneVersion(
f.version.id,
{ name: 'Owned link candidate' },
actor,
randomUUID()
);
const before = await f.research.getProject(p.project.id);
await expect(f.research.linkStrategy(p.project.id, clone.strategy.id, actor)).rejects.toThrow(
'Only an operator'
);
expect(await f.research.listProjectStrategies(p.project.id)).toEqual([]);
const migration = readFileSync(
new URL('../../database/postgres/init/31-research-agent-project-links.sql', import.meta.url),
'utf8'
);
await f.pool.query(migration);
await f.research.linkStrategy(p.project.id, clone.strategy.id, actor);
const after = await f.research.getProject(p.project.id);
expect(after.revision).toBe(before.revision + 1);
expect(after.updatedBy).toBe(actor);
expect(after.ownerPrincipal).toBe(before.ownerPrincipal);
expect(after.title).toBe(before.title);
expect((await f.research.listProjectStrategies(p.project.id)).map(s => s.id)).toEqual([
clone.strategy.id,
]);
await f.pool.query(migration);
await f.research.linkStrategy(p.project.id, clone.strategy.id, actor);
expect(await f.research.getProject(p.project.id)).toEqual(after);
const update = (fragment: string, id = p.project.id) =>
f.pool.query(
`UPDATE research_projects SET revision=revision+1,updated_by=$2,updated_at=NOW(),${fragment} WHERE id=$1`,
[id, actor]
);
for (const fragment of [
"title='changed'",
"description='changed'",
"owner_principal='service'",
'archived_at=NOW()',
"created_at=created_at-INTERVAL '1 day'",
]) {
await expect(update(fragment)).rejects.toThrow('Only owned strategy links');
}
await expect(
f.pool.query('UPDATE research_projects SET revision=revision+2,updated_by=$2 WHERE id=$1', [
p.project.id,
actor,
])
).rejects.toThrow('Only owned strategy links');
await expect(
f.research.createProject({ title: 'Unauthorized provisioning' }, actor)
).rejects.toThrow('Only an operator');
const foreign = await f.research.createProject({ title: 'Ungranted' }, 'operator');
await expect(update('description=description', foreign.id)).rejects.toThrow(
'Only owned strategy links'
);
await expect(f.research.linkStrategy(foreign.id, clone.strategy.id, actor)).rejects.toThrow(
'not permitted'
);
await expect(
f.research.linkStrategy(p.project.id, f.version.strategyId, actor)
).rejects.toThrow('not permitted');
expect(await f.research.getProject(p.project.id)).toEqual(after);
expect(
(
await f.pool.query(
"SELECT count(*)::int n FROM research_agent_audit WHERE agent_id=$1 AND operation='research_projects-link-revision'",
[actor]
)
).rows[0].n
).toBe(1);
await f.agents.update(actor, { expectedRevision: 1, enabled: false });
await expect(update('description=description')).rejects.toThrow('disabled');
expect(await f.research.getProject(p.project.id)).toEqual(after);
});
test('operator provisioning stores only a hash; real mounted authentication, AI authorship and scoped writes', async () => {
const f = await fixture(1),
p = await provision(f);