Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/framework/harness/run-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ async function runOne(
transcript: run.transcript,
agentReport: run.agentReport,
judge: judges.judge,
sandbox: cliSandbox?.sandbox,
});
const scoringEndedAt = Date.now();

Expand Down
218 changes: 126 additions & 92 deletions evals/spark/build-auth-001-email-password-flow-spark/EVAL.test.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,155 @@
import { describe, expect, it, vi } from 'vitest';
import { describe, expect, it } from 'vitest';
import {
SPARK_TEST_KEYS,
failedChecks,
sparkScorer,
stubSandbox,
} from '../../../experiments/spark/lib/runtime-stub.js';
import scorer from './EVAL.js';

const USER_ID = '11111111-1111-4111-8111-111111111111';

const profile = {
id: USER_ID,
display_name: 'Alex Doe',
plan: 'free',
created_at: '2026-11-06 12:00:00',
};
// What the SQL endpoint returns for the scorer's ground-truth query: the new
// auth user joined to its profile.
const dbRow = { id: USER_ID, display_name: 'Alex Doe', plan: 'free' };

function score(
options: {
accountExists?: boolean;
acceptsAnyPassword?: boolean;
profiles?: unknown[];
agentReport?: string;
transcript?: Parameters<typeof scorer>[0]['transcript'];
reportPasses?: boolean;
} = {}
interface AuthModule {
/** The import line; defaults to a real supabase-js import. */
sdkImport?: string;
/** Extra top-level source, e.g. a comment mentioning a key. */
extra?: string;
/** Replacement bodies for the exported functions. */
signUp?: string;
signInWrong?: string;
getMyProfile?: string;
}

/**
* An auth module that uses the SDK client (the stub). It exits early without
* the project URL and publishable key, or when it is handed a secret key, so
* a passing run also proves the scorer sets exactly those.
*/
const authModule = (options: AuthModule = {}) => `// Auth layer
${options.sdkImport ?? "import { createClient } from '@supabase/supabase-js';"}
if (!process.env.SPARK_PROJECT_URL || !process.env.SPARK_PUBLISHABLE_KEY) process.exit(2);
if (process.env['SPARK_SECRET' + '_KEY']) process.exit(3);
${options.extra ?? ''}
export async function signUp(email, password, displayName) {
${options.signUp ?? `return { userId: '${USER_ID}' };`}
}
export async function signIn(email, password) {
if (password !== 'correct-horse-battery') {
${options.signInWrong ?? `return { error: 'Invalid login credentials' };`}
}
return { userId: '${USER_ID}' };
}
export async function getMyProfile() {
${options.getMyProfile ?? `return { displayName: 'Alex Doe', plan: 'free' };`}
}
`;

async function score(
options: { module?: string; rows?: Record<string, unknown>[] } = {}
) {
const { accountExists = true, acceptsAnyPassword = false } = options;
return sparkScorer(
scorer,
async (url, init, request) => {
if (url.pathname === '/auth/v1/token') {
const body = JSON.parse(String(init?.body ?? (await request?.text())));
return accountExists &&
(acceptsAnyPassword || body.password === 'correct-horse-battery')
? Response.json({
access_token: 'access',
token_type: 'bearer',
expires_in: 3600,
refresh_token: 'refresh',
user: { id: USER_ID, email: '[email protected]' },
})
: Response.json(
{ error: 'invalid_grant', msg: 'Invalid login credentials' },
{ status: 400 }
);
const { rows = [dbRow] } = options;
return failedChecks(
await sparkScorer(
scorer,
(url) =>
url.pathname === '/database/query'
? Response.json(rows)
: Response.json([]),
{
sandbox: stubSandbox({
'app/src/auth.mjs': options.module ?? authModule(),
}),
}
expect(url.pathname).toBe('/rest/v1/profiles');
return Response.json(options.profiles ?? [profile]);
},
{
transcript: options.transcript,
agentReport: options.agentReport ?? 'Hello, Alex Doe! Your plan is free.',
judge: vi.fn(async () => ({ passed: options.reportPasses ?? true })),
}
)
);
}

describe('account and profile checks', () => {
it('accepts a signed-up Alex with a correct profile', async () => {
const result = await score();
expect(failedChecks(result)).toEqual([]);
expect(result.passed).toBe(true);
describe('email + password flow scorer', () => {
it('passes every check for an SDK auth module that creates the profile', async () => {
expect(await score()).toEqual([]);
});

it('fails every account-dependent check when Alex was never created', async () => {
const result = await score({ accountExists: false });
expect(failedChecks(result)).toEqual([
'Alex can sign in with the right password',
"Alex's profile has the display name and default plan",
]);
});
it('fails the check of each broken behaviour', async () => {
const profileName = 'signUp creates the profile with the display name';
// The profile was never created (left join), or has the wrong name.
for (const row of [
{ ...dbRow, display_name: null, plan: null },
{ ...dbRow, display_name: 'alex' },
])
expect(await score({ rows: [row] })).toEqual([profileName]);

it('rejects a project that accepts a wrong password', async () => {
expect(failedChecks(await score({ acceptsAnyPassword: true }))).toEqual([
'Wrong password is rejected without a session',
]);
});
expect(
await score({
module: authModule({ signUp: `return { userId: 'nope' };` }),
})
).toEqual(['signUp creates the account and returns its user id']);

const wrongPassword =
'wrong password is rejected gracefully (no throw, no session)';
for (const signInWrong of [
`throw new Error('Invalid login credentials');`,
`return { userId: '${USER_ID}' };`,
])
expect(await score({ module: authModule({ signInWrong }) })).toEqual([
wrongPassword,
]);

it('rejects a missing, wrong or duplicated profile', async () => {
for (const profiles of [
[],
[{ ...profile, display_name: 'alex' }],
[{ ...profile, plan: 'pro' }],
[profile, { ...profile, created_at: '2026-11-06 12:01:00' }],
for (const getMyProfile of [
`return { displayName: 'alex', plan: 'free' };`,
`return { displayName: 'Alex Doe', plan: 'pro' };`,
`return { error: 'not signed in' };`,
])
expect(failedChecks(await score({ profiles }))).toEqual([
"Alex's profile has the display name and default plan",
expect(await score({ module: authModule({ getMyProfile }) })).toEqual([
"getMyProfile returns the signed-in user's profile",
]);
});

it('fails when the report does not greet Alex from the profile', async () => {
expect(failedChecks(await score({ reportPasses: false }))).toEqual([
'Agent greets Alex from their profile',
]);
it('fails the secret-key check when app code references the secret key', async () => {
const name = 'app code does not use the secret / service-role key';
for (const extra of [
`const key = 'sb_secret_abc';`,
`const key = process.env.SPARK_SECRET_KEY;`,
`// do not use SUPABASE_SERVICE_ROLE_KEY here`,
])
expect(await score({ module: authModule({ extra }) })).toEqual([name]);
});
});

describe('key leak check', () => {
it('fails when the project key shows up in the agent output', async () => {
it('requires a real @supabase/supabase-js import', async () => {
const name = 'implementation uses @supabase/supabase-js';
for (const sdkImport of [
// No SDK at all, commented out, or a different package with the same prefix.
`const client = {};`,
`// import { createClient } from '@supabase/supabase-js';`,
`import { createClient } from '@supabase/supabase-js-not-real';`,
])
expect(await score({ module: authModule({ sdkImport }) })).toContain(
name
);
expect(
failedChecks(
await score({ agentReport: `Done. I used ${SPARK_TEST_KEYS.secret}.` })
)
).toEqual(['Keys and tokens stay out of the agent output']);
await score({
module: authModule({
sdkImport: `const { createClient } = await import('@supabase/supabase-js');`,
}),
})
).toEqual([]);
});

it('ignores keys in the scripts the agent wrote', async () => {
const result = await score({
transcript: [
{
type: 'tool_call',
name: 'shell',
input: { command: `curl -H "apikey: ${SPARK_TEST_KEYS.secret}"` },
output: 'ok',
},
],
});
expect(failedChecks(result)).toEqual([]);
it('fails when the module does not load or the driver produces no output', async () => {
const failing = [
'auth module loads and the driver completes',
'signUp creates the account and returns its user id',
'wrong password is rejected gracefully (no throw, no session)',
'signIn with the right password returns the user id',
"getMyProfile returns the signed-in user's profile",
];
for (const module of [
// The stub the agent never implemented, throwing at load time.
`import { createClient } from '@supabase/supabase-js';\nthrow new Error('TODO: implement auth');\n`,
`import { createClient } from '@supabase/supabase-js';\nprocess.exit(1);\n`,
])
expect(await score({ module })).toEqual(failing);
});
});
Loading
Loading