Files
MrAlders0n 94b4b40f9b planguard: plan and result regression checks, fixture tier in CI, read-only mode (#240)
* feat(planguard): read sqlc statement text and load a strict plan corpus

* fix(planguard): fail on unextracted statements, keep fragments mode-neutral

* feat(planguard): plan assertions, scoped sort exemptions and narrow retired-index verdicts

* fix(planguard): an errored run always fails

* fix(planguard): keep subplan conds off their parent scan; fail on unanalyzed budgets

* feat(planguard): read-only plan runner, reports and the run command

* fix(planguard): validate identifiers in emitted scripts; prove read-only runs

* feat(planguard): end-state corpus, planted regressions and the generated cached-plan policy

* fix(planguard): derive observer cases from data; mark legacy generic plans

* fix(planguard): bound the dense-region route resolvers; test policy refusals

* fix(planguard): re-measure the dense-region route cases; cover every policy refusal

* feat(planguard): synthetic fixture built through the migrations, checked in CI

* ci(planguard): build the fixture once; guard fixture data for identifiers

* fix(planguard): hash every fixture generator input; harden the fixture guard

* feat(planguard): snapshot diff over every column, named result classes and cursor walks

* fix(planguard): bound the relaxed diff classes; derive the cursor tie from data

* fix(planguard): refuse multi-statement text in the corpus runner

* feat: read-only server mode and an HTTP page diff between two builds

* fix(planguard): refuse escape strings and psql meta-commands in corpus text

* fix: storediff follows each build's own cursor; prove read-only gates via the log

* fix(planguard): match the PostgreSQL lexer on high-bit bytes; check every emitted line

* feat(admin): daily read-only plan check on the maintenance pool, its metric and report

* feat(planguard): daily prod check behind planguard.daily_check

* fix(planguard): cancel fresh runs at shutdown; expose a never-ran check

* ci(planguard): pin the fixture server and collation; refresh baselines

* fix(planguard): calibrate route budgets on one dataset; skip entries whose index is absent
2026-10-19 13:45:39 -04:00

35 lines
2.6 KiB
SQL

-- Copyright 2026 Beacon Contributors
-- SPDX-License-Identifier: AGPL-3.0-or-later
-- Fixture step 60: insert the staged channels, packets, observations and messages once each, in time order, then
-- drop the staging tables. Every row references rows built in this build, so where the role may, the foreign-key
-- triggers are switched off for the load (session_replication_role = replica) and on again after it.
DO $$ BEGIN SET LOCAL session_replication_role = replica; EXCEPTION WHEN insufficient_privilege THEN NULL; END $$;
INSERT INTO channels (id, channel_hash, key_fingerprint, name, hashtag, is_hashtag, is_public, key_known, first_seen, last_seen, message_count)
SELECT ch.id, ch.channel_hash, ch.key_fingerprint, ch.name, ch.hashtag, ch.is_hashtag, ch.is_public, ch.key_known, ch.first_seen,
ch.last_seen, coalesce(m.n, 0)
FROM planguard_src.ch LEFT JOIN (SELECT channel_id, count(*) n FROM planguard_src.cm GROUP BY 1) m ON m.channel_id = ch.id
ORDER BY ch.id;
SELECT setval('channels_id_seq', (SELECT max(id) FROM channels));
INSERT INTO packets (packet_hash, payload_type, payload_version, route_type, transport_codes_present, scope_id, origin_pubkey,
raw_payload, raw_header, parsed_payload, decrypted, channel_hash, trace_tag, first_heard_at, last_heard_at,
observation_count)
SELECT packet_hash, payload_type, payload_version, route_type, transport_codes_present, scope_id, origin_pubkey, raw_payload,
'\x01', NULL, false, channel_hash, trace_tag, first_heard_at, last_heard_at, observation_count
FROM planguard_src.pk ORDER BY last_heard_at, packet_hash;
INSERT INTO packet_observations (id, packet_hash, observer_id, iata, heard_at, path_length_byte, hash_size, hop_count, path_bytes,
rssi, snr, payload_type)
SELECT id, packet_hash, observer_id, iata, heard_at, path_length_byte, hash_size, hop_count, path_bytes, rssi, snr, payload_type
FROM planguard_src.po ORDER BY id;
SELECT setval('packet_observations_id_seq', (SELECT max(id) FROM packet_observations));
INSERT INTO channel_messages (id, channel_id, packet_hash, sender_name, content, sent_at)
SELECT id, channel_id, packet_hash, sender_name, 'message ' || id, sent_at FROM planguard_src.cm ORDER BY id;
SELECT setval('channel_messages_id_seq', (SELECT max(id) FROM channel_messages));
DO $$ BEGIN SET LOCAL session_replication_role = origin; EXCEPTION WHEN insufficient_privilege THEN NULL; END $$;
DROP TABLE planguard_src.pk0, planguard_src.pk, planguard_src.po, planguard_src.cm, planguard_src.pk_sites, planguard_src.kr0,
planguard_src.kr1;