import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import test from "node:test"; const migration = readFileSync( new URL("../supabase/migrations/20260906020000_adopted_credible_range.sql", import.meta.url), "utf8", ); test("accept RPC gains an optional credible-range argument and never rewrites the opening window", () => { assert.match(migration, /add column if not exists adopted_credible_range jsonb/); assert.match( migration, /drop function if exists public\.accept_agentic_rectification_candidate_for_case_v2\(uuid, uuid, uuid, uuid, uuid\);/, ); assert.match( migration, /create or replace function public\.accept_agentic_rectification_candidate_for_case_v2\(\s*p_user_id uuid,\s*p_case_id uuid,\s*p_result_id uuid,\s*p_candidate_id uuid,\s*p_request_id uuid,\s*p_credible_range jsonb default null/, ); assert.match(migration, /adopted_credible_range = coalesce\(v_adopted, adopted_credible_range\)/); assert.doesNotMatch(migration, /candidate_range\s*=\s*v_adopted/); assert.match( migration, /grant execute on function public\.accept_agentic_rectification_candidate_for_case_v2\(uuid, uuid, uuid, uuid, uuid, jsonb\)\s+to service_role/, ); }); test("read_report_candidate_range prefers adopted_credible_range then the opening window", () => { assert.match(migration, /when c\.adopted_credible_range is not null/); assert.match(migration, /then c\.adopted_credible_range/); assert.match(migration, /else c\.candidate_range/); assert.match(migration, /jsonb_build_object\('start_time', v_start, 'end_time', v_end\)/); assert.match( migration, /grant execute on function public\.read_report_candidate_range\(uuid, uuid\)\s+to service_role/, ); });