Clear remaining M0/M1 bugs on master (T-22, T-25, T-27, T-31, T-35)
This commit is contained in:
parent
9e259ca43b
commit
b20fc28e45
8 changed files with 245 additions and 252 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import { randomUUID } from 'node:crypto';
|
||||
import { expect, mock, test } from 'bun:test';
|
||||
import { Hono } from 'hono';
|
||||
import {
|
||||
|
|
@ -14,7 +13,8 @@ import { researchAgentDatabaseError } from '../../apps/stock/web-api/src/service
|
|||
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
||||
import { ResearchService } from '../../apps/stock/web-api/src/services/research.service';
|
||||
|
||||
const agent = `agent:${randomUUID()}` as const;
|
||||
const fixtureUuid = (n: number) => `00000000-0000-4000-8000-${String(n).padStart(12, '0')}`;
|
||||
const agent = `agent:${fixtureUuid(1)}` as const;
|
||||
const token = 'sb-research.fixture-token';
|
||||
const adminToken = 'operator-test-secret-12345678901234567890';
|
||||
const serviceToken = 'service-test-secret-123456789012345678901';
|
||||
|
|
@ -156,9 +156,9 @@ test('resolver denies all dataset operations including canonical dataset exports
|
|||
});
|
||||
|
||||
test('resolver exact write capabilities refuse trading, operators, foreign evidence and ownership impersonation', async () => {
|
||||
const projectId = randomUUID(),
|
||||
experimentId = randomUUID(),
|
||||
familyId = randomUUID();
|
||||
const projectId = fixtureUuid(2),
|
||||
experimentId = fixtureUuid(3),
|
||||
familyId = fixtureUuid(4);
|
||||
const query = mock(async (sql: string) => ({
|
||||
rows: sql.includes('token_hash')
|
||||
? [{ id: agent, enabled: true, policy: { allowedProjectIds: [projectId] } }]
|
||||
|
|
@ -183,7 +183,7 @@ test('resolver exact write capabilities refuse trading, operators, foreign evide
|
|||
'/api/v2/runs/' + experimentId + '/reproduce',
|
||||
`/api/v2/experiments/${experimentId}/cancel`,
|
||||
`/api/v2/strategies/${familyId}/versions`,
|
||||
`/api/v2/research-projects/${randomUUID()}/hypotheses`,
|
||||
`/api/v2/research-projects/${fixtureUuid(5)}/hypotheses`,
|
||||
]) {
|
||||
expect(await check(path)).toBeInstanceOf(Response);
|
||||
expect(((await check(path)) as Response).status).toBe(403);
|
||||
|
|
@ -199,26 +199,26 @@ test('resolver exact write capabilities refuse trading, operators, foreign evide
|
|||
});
|
||||
|
||||
test('resolver scopes GET and HEAD reads to granted projects, templates and owned resources', async () => {
|
||||
const grantedProject = randomUUID(),
|
||||
ungrantedProject = randomUUID(),
|
||||
grantedBacktest = randomUUID(),
|
||||
ungrantedBacktest = randomUUID(),
|
||||
grantedHypothesis = randomUUID(),
|
||||
ungrantedHypothesis = randomUUID(),
|
||||
missingHypothesis = randomUUID(),
|
||||
grantedArtifact = randomUUID(),
|
||||
ungrantedArtifact = randomUUID(),
|
||||
ownedExperiment = randomUUID(),
|
||||
ownedExperiment2 = randomUUID(),
|
||||
foreignExperiment = randomUUID(),
|
||||
ownedWalkForward = randomUUID(),
|
||||
foreignWalkForward = randomUUID(),
|
||||
ownedRun = randomUUID(),
|
||||
foreignRun = randomUUID(),
|
||||
permittedStrategy = randomUUID(),
|
||||
unpermittedStrategy = randomUUID(),
|
||||
permittedVersion = randomUUID(),
|
||||
unpermittedVersion = randomUUID();
|
||||
const grantedProject = fixtureUuid(10),
|
||||
ungrantedProject = fixtureUuid(11),
|
||||
grantedBacktest = fixtureUuid(12),
|
||||
ungrantedBacktest = fixtureUuid(13),
|
||||
grantedHypothesis = fixtureUuid(14),
|
||||
ungrantedHypothesis = fixtureUuid(15),
|
||||
missingHypothesis = fixtureUuid(16),
|
||||
grantedArtifact = fixtureUuid(17),
|
||||
ungrantedArtifact = fixtureUuid(18),
|
||||
ownedExperiment = fixtureUuid(19),
|
||||
ownedExperiment2 = fixtureUuid(20),
|
||||
foreignExperiment = fixtureUuid(21),
|
||||
ownedWalkForward = fixtureUuid(22),
|
||||
foreignWalkForward = fixtureUuid(23),
|
||||
ownedRun = fixtureUuid(24),
|
||||
foreignRun = fixtureUuid(25),
|
||||
permittedStrategy = fixtureUuid(26),
|
||||
unpermittedStrategy = fixtureUuid(27),
|
||||
permittedVersion = fixtureUuid(28),
|
||||
unpermittedVersion = fixtureUuid(29);
|
||||
|
||||
const query = mock(async (sql: string, values?: unknown[]) => {
|
||||
if (sql.includes('FROM research_agents WHERE token_hash=')) {
|
||||
|
|
@ -451,16 +451,16 @@ test('quota diagnostics remain distinguishable from arbitrary database failures;
|
|||
});
|
||||
|
||||
test('artifact reads check run ownership before resolving evidence for research agents while preserving operator access', async () => {
|
||||
const projectId = randomUUID(),
|
||||
artifactId = randomUUID(),
|
||||
revisionId = randomUUID(),
|
||||
foreignRunId = randomUUID(),
|
||||
const projectId = fixtureUuid(30),
|
||||
artifactId = fixtureUuid(31),
|
||||
revisionId = fixtureUuid(32),
|
||||
foreignRunId = fixtureUuid(33),
|
||||
now = new Date().toISOString();
|
||||
|
||||
const resolveAll = mock(async () => [
|
||||
{
|
||||
runId: foreignRunId,
|
||||
backtestId: randomUUID(),
|
||||
backtestId: fixtureUuid(34),
|
||||
metricsVersion: 'canonical-analytics/v1' as const,
|
||||
metricPath: 'analytics.metrics.sharpeRatio' as const,
|
||||
strategyVersionId: null,
|
||||
|
|
|
|||
|
|
@ -279,6 +279,26 @@ describe('Environment safety & multi-env isolation', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('allows MongoDB Unix domain socket (.sock) URIs in production env-safety guard (T-27)', () => {
|
||||
const prodUnixCfg = makeConfig({
|
||||
environment: 'production',
|
||||
pgPassword: 'strong-prod-pg-password',
|
||||
mongoUri: 'mongodb://prod_user:strong-prod-mongo-pass@%2Fvar%2Frun%2Fmongodb%2Fmongod.sock/stock',
|
||||
mongoDatabase: 'stock',
|
||||
});
|
||||
expect(() => assertEnvironmentSafety(prodUnixCfg, 'webApi', {})).not.toThrow();
|
||||
|
||||
const prodUnixDevPassCfg = makeConfig({
|
||||
environment: 'production',
|
||||
pgPassword: 'strong-prod-pg-password',
|
||||
mongoUri: 'mongodb://prod_user:trading_mongo_dev@%2Fvar%2Frun%2Fmongodb%2Fmongod.sock/stock',
|
||||
mongoDatabase: 'stock',
|
||||
});
|
||||
expect(() => assertEnvironmentSafety(prodUnixDevPassCfg, 'webApi', {})).toThrow(
|
||||
/cannot use a default dev\/qa credential/
|
||||
);
|
||||
});
|
||||
|
||||
test('blocks multi-host MongoDB seed lists targeting QA loopback :27017 for dataIngestion and dataPipeline', () => {
|
||||
const qaFirstIngestion = makeConfig({
|
||||
environment: 'development',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue