Codex commited on
Commit
dee661e
·
1 Parent(s): 122b842

Release v0.4.1 public dataset explorer

Browse files
CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
  # Changelog
2
 
 
 
 
 
 
 
 
3
  ## Unreleased — Viewer metadata hotfix
4
 
5
  - Limited the mutable `main` dataset card to one interactive `research_view` configuration after Hugging Face's 26-way conversion fan-out repeatedly hit shared-branch locks. All 26 canonical CSV and Parquet tables remain unchanged and directly downloadable.
 
1
  # Changelog
2
 
3
+ ## 0.4.1 — 2026-08-18
4
+
5
+ - Make all 1,087 canonical rows searchable in the default Hugging Face Data Studio view.
6
+ - Add coherent `case_catalog`, `research_view`, and `claim_evidence` configurations.
7
+ - Mark the 10-row research split as `orientation_only` to prevent it being mistaken for the full dataset.
8
+ - Keep all 26 canonical CSV and Parquet tables byte-identical to v0.4.0.
9
+
10
  ## Unreleased — Viewer metadata hotfix
11
 
12
  - Limited the mutable `main` dataset card to one interactive `research_view` configuration after Hugging Face's 26-way conversion fan-out repeatedly hit shared-branch locks. All 26 canonical CSV and Parquet tables remain unchanged and directly downloadable.
CITATION.cff CHANGED
@@ -7,14 +7,14 @@ authors:
7
  - given-names: "Miguel"
8
  family-names: "Guerrero"
9
  website: "https://miguelguerrero.eu"
10
- version: 0.4.0
11
- date-released: 2026-08-15
12
  license: CC-BY-4.0
13
  repository-code: "https://huggingface.co/datasets/apol/ai-election-manipulation-cases"
14
- url: "https://huggingface.co/datasets/apol/ai-election-manipulation-cases/tree/v0.4.0"
15
  identifiers:
16
  - type: url
17
- value: "https://huggingface.co/datasets/apol/ai-election-manipulation-cases/tree/v0.4.0"
18
  description: "Versioned Hugging Face revision; record the exact commit hash used."
19
  keywords:
20
  - elections
 
7
  - given-names: "Miguel"
8
  family-names: "Guerrero"
9
  website: "https://miguelguerrero.eu"
10
+ version: 0.4.1
11
+ date-released: 2026-08-18
12
  license: CC-BY-4.0
13
  repository-code: "https://huggingface.co/datasets/apol/ai-election-manipulation-cases"
14
+ url: "https://huggingface.co/datasets/apol/ai-election-manipulation-cases/tree/v0.4.1"
15
  identifiers:
16
  - type: url
17
+ value: "https://huggingface.co/datasets/apol/ai-election-manipulation-cases/tree/v0.4.1"
18
  description: "Versioned Hugging Face revision; record the exact commit hash used."
19
  keywords:
20
  - elections
README.md CHANGED
@@ -11,16 +11,24 @@ tags:
11
  - agency-transfer
12
  - evidence-index
13
  configs:
14
- - config_name: research_view
15
  default: true
16
- data_files: [{split: data, path: parquet/research_view.parquet}]
 
 
 
 
 
 
17
  ---
18
 
19
  # AI, Elections and Agency Transfer Evidence Index
20
 
21
- **Version 0.4.0 · released 15 August 2026 · research cutoff 12 August 2026**
 
 
22
 
23
- **Viewer hotfix on `main`, 15 August 2026:** Data Studio now exposes one orientation view. The frozen `v0.4.0` tag, its 26 tables, ZIP, workbook and checksums are unchanged.
24
 
25
  This is a **purposive, exploratory evidence index**. It makes claims, sources, counterevidence, uncertainty, mechanisms, and selected measurements easier to inspect. It does **not** empirically prove the agency-transfer hypothesis, estimate how common election manipulation is, or identify votes or election outcomes caused by AI.
26
 
@@ -28,7 +36,10 @@ The repository slug is inherited. The canonical title is the one above: the inde
28
 
29
  ## Start here
30
 
31
- - [Open the 10-row research view](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/viewer/research_view/data) — fastest orientation.
 
 
 
32
  - [Read the Spanish quick guide](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/main/docs/guia-rapida-es.md) — concise interpretation guide.
33
  - [Read the methodology](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/main/docs/methodology.md) — units, coding and limitations.
34
  - [Read the v0.4.0 red-team report](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/main/docs/red-team-v0.4.0.md) — findings, fixes and residual limits.
@@ -41,9 +52,9 @@ The repository slug is inherited. The canonical title is the one above: the inde
41
 
42
  The coded tables and field values are in English. Spanish is limited to the quick guide and selected descriptive metadata; this is not a bilingual corpus.
43
 
44
- ## What is in v0.4.0
45
 
46
- These counts describe the generated v0.4.0 build and must be refreshed if that build changes.
47
 
48
  | Layer | Rows | What the count means |
49
  |---|---:|---|
@@ -74,7 +85,7 @@ The strongest pathway conclusion is deliberately limited: 4 records show an obse
74
 
75
  All 26 canonical tables are available as CSV in [`data/`](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/tree/v0.4.0/data) and as native Parquet in [`parquet/`](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/tree/v0.4.0/parquet). Relational types, keys and foreign keys are declared in [`data/datapackage.json`](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/v0.4.0/data/datapackage.json).
76
 
77
- Only `research_view` is declared as an interactive Data Studio configuration. This keeps the public preview small and avoids conversion-lock contention among 26 unrelated schemas. It does not remove or merge any table; load the other 25 directly from their CSV or Parquet files.
78
 
79
  Files under `research/` are transparent build inputs and historical working ledgers, not canonical v0.4.0 tables. Some retain superseded draft annotations; see [`research/README.md`](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/main/research/README.md) before using them.
80
 
@@ -88,8 +99,8 @@ from datasets import load_dataset
88
  view = load_dataset(
89
  "apol/ai-election-manipulation-cases",
90
  "research_view",
91
- revision="v0.4.0",
92
- split="data",
93
  )
94
  ```
95
 
@@ -204,6 +215,6 @@ Do not run `build:package` to overwrite an already tagged version from mutable `
204
 
205
  The Excel workbook is a convenience artifact, not the canonical analytic source. Its builder requires the `@oai/artifact-tool` runtime, which is not part of the public `package.json`; use CSV or Parquet unless that environment is available. The ZIP and workbook should be verified against the release manifest, not assumed equivalent merely because their filenames contain the same version.
206
 
207
- `main` is mutable. Use the `v0.4.0` revision for a fixed citation and record the exact commit hash used. No DOI has been assigned; none should be inferred from the repository URL. A DOI can be added only after a frozen revision is deposited and its identity is reconciled with the tag, citation metadata and release manifest.
208
 
209
  The CC BY 4.0 license covers the original coding and synthesis. Source materials remain under their publishers' or issuing institutions' terms. Cite both this index and the original evidence sources for substantive claims.
 
11
  - agency-transfer
12
  - evidence-index
13
  configs:
14
+ - config_name: record_index
15
  default: true
16
+ data_files: [{split: data, path: record_index.csv}]
17
+ - config_name: case_catalog
18
+ data_files: [{split: data, path: parquet/case_catalog.parquet}]
19
+ - config_name: research_view
20
+ data_files: [{split: orientation_only, path: parquet/research_view.parquet}]
21
+ - config_name: claim_evidence
22
+ data_files: [{split: data, path: parquet/claim_evidence.parquet}]
23
  ---
24
 
25
  # AI, Elections and Agency Transfer Evidence Index
26
 
27
+ **Version 0.4.1 · released 18 August 2026 · research cutoff 12 August 2026**
28
+
29
+ **The public Data Studio exposes all 1,087 canonical rows.** Use `record_index` to search every table, then switch to `case_catalog`, `research_view`, or `claim_evidence` for coherent analytic units. The 26 canonical tables remain unchanged from `v0.4.0`.
30
 
31
+ `v0.4.1` is a public-exploration and citation release. The frozen v0.4.0 ZIP, workbook, checksums and 26 canonical table files remain the evidence package; v0.4.1 adds no new factual records or coded conclusions.
32
 
33
  This is a **purposive, exploratory evidence index**. It makes claims, sources, counterevidence, uncertainty, mechanisms, and selected measurements easier to inspect. It does **not** empirically prove the agency-transfer hypothesis, estimate how common election manipulation is, or identify votes or election outcomes caused by AI.
34
 
 
36
 
37
  ## Start here
38
 
39
+ - [Explore all 1,087 canonical rows](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/viewer/record_index/data) — searchable index across all 26 tables.
40
+ - [Open the 64-row case catalogue](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/viewer/case_catalog/data) — incidents, preparedness records and screening leads.
41
+ - [Open the 10-row research view](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/viewer/research_view/orientation_only) — orientation only, not the full dataset.
42
+ - [Trace 124 claim–evidence relations](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/viewer/claim_evidence/data) — inspect support, premises and counterevidence.
43
  - [Read the Spanish quick guide](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/main/docs/guia-rapida-es.md) — concise interpretation guide.
44
  - [Read the methodology](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/main/docs/methodology.md) — units, coding and limitations.
45
  - [Read the v0.4.0 red-team report](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/main/docs/red-team-v0.4.0.md) — findings, fixes and residual limits.
 
52
 
53
  The coded tables and field values are in English. Spanish is limited to the quick guide and selected descriptive metadata; this is not a bilingual corpus.
54
 
55
+ ## What is in v0.4.1
56
 
57
+ These counts describe the v0.4.1 public exploration layer over the unchanged v0.4.0 canonical evidence tables.
58
 
59
  | Layer | Rows | What the count means |
60
  |---|---:|---|
 
85
 
86
  All 26 canonical tables are available as CSV in [`data/`](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/tree/v0.4.0/data) and as native Parquet in [`parquet/`](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/tree/v0.4.0/parquet). Relational types, keys and foreign keys are declared in [`data/datapackage.json`](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/v0.4.0/data/datapackage.json).
87
 
88
+ Data Studio provides four deliberate configurations instead of 26 competing conversions. `record_index` contains one searchable envelope for every canonical row; its `record_json` field preserves the full source row without pretending that unlike tables share one scientific unit. `case_catalog`, `research_view`, and `claim_evidence` expose the three most useful coherent views. The canonical CSV and Parquet files remain the authoritative relational data.
89
 
90
  Files under `research/` are transparent build inputs and historical working ledgers, not canonical v0.4.0 tables. Some retain superseded draft annotations; see [`research/README.md`](https://huggingface.co/datasets/apol/ai-election-manipulation-cases/blob/main/research/README.md) before using them.
91
 
 
99
  view = load_dataset(
100
  "apol/ai-election-manipulation-cases",
101
  "research_view",
102
+ revision="v0.4.1",
103
+ split="orientation_only",
104
  )
105
  ```
106
 
 
215
 
216
  The Excel workbook is a convenience artifact, not the canonical analytic source. Its builder requires the `@oai/artifact-tool` runtime, which is not part of the public `package.json`; use CSV or Parquet unless that environment is available. The ZIP and workbook should be verified against the release manifest, not assumed equivalent merely because their filenames contain the same version.
217
 
218
+ `main` is mutable. Use `v0.4.1` to cite the public exploration layer or `v0.4.0` to cite the frozen evidence package, and record the exact commit hash used. No DOI has been assigned; none should be inferred from the repository URL. A DOI can be added only after a frozen revision is deposited and its identity is reconciled with the tag and citation metadata.
219
 
220
  The CC BY 4.0 license covers the original coding and synthesis. Source materials remain under their publishers' or issuing institutions' terms. Cite both this index and the original evidence sources for substantive claims.
package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
  {
2
  "name": "agency-transfer-election-cases",
3
- "version": "0.4.0",
4
  "lockfileVersion": 3,
5
  "requires": true,
6
  "packages": {
7
  "": {
8
  "name": "agency-transfer-election-cases",
9
- "version": "0.4.0",
10
  "dependencies": {
11
  "parquetjs-lite": "0.8.7"
12
  },
 
1
  {
2
  "name": "agency-transfer-election-cases",
3
+ "version": "0.4.1",
4
  "lockfileVersion": 3,
5
  "requires": true,
6
  "packages": {
7
  "": {
8
  "name": "agency-transfer-election-cases",
9
+ "version": "0.4.1",
10
  "dependencies": {
11
  "parquetjs-lite": "0.8.7"
12
  },
package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "agency-transfer-election-cases",
3
- "version": "0.4.0",
4
  "private": true,
5
  "type": "module",
6
  "engines": {
@@ -13,6 +13,8 @@
13
  "validate": "node scripts/validate-data.mjs",
14
  "validate:source": "node scripts/validate-data.mjs --source-only",
15
  "build:parquet": "node scripts/build-parquet.mjs",
 
 
16
  "build:package": "node scripts/build-package.mjs",
17
  "verify:package": "node scripts/verify-package.mjs",
18
  "verify:package:checkout": "node scripts/verify-package.mjs --checkout-parity",
 
1
  {
2
  "name": "agency-transfer-election-cases",
3
+ "version": "0.4.1",
4
  "private": true,
5
  "type": "module",
6
  "engines": {
 
13
  "validate": "node scripts/validate-data.mjs",
14
  "validate:source": "node scripts/validate-data.mjs --source-only",
15
  "build:parquet": "node scripts/build-parquet.mjs",
16
+ "build:viewer": "node scripts/build-viewer-index.mjs",
17
+ "validate:viewer": "node scripts/validate-viewer.mjs",
18
  "build:package": "node scripts/build-package.mjs",
19
  "verify:package": "node scripts/verify-package.mjs",
20
  "verify:package:checkout": "node scripts/verify-package.mjs --checkout-parity",
record_index.csv ADDED
The diff for this file is too large to render. See raw diff
 
record_index.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72c9dbecb561302068b7daf83d17429f44c28bf5ac11ac519f7fb59bdb1ac778
3
+ size 835901
scripts/build-viewer-index.mjs ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import parquet from "parquetjs-lite";
7
+
8
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
9
+ const dataDir = path.join(root, "data");
10
+ const outDir = root;
11
+
12
+ function parseCsv(text, filename) {
13
+ const input = text.replace(/^\uFEFF/, "");
14
+ const records = [];
15
+ let record = [];
16
+ let field = "";
17
+ let quoted = false;
18
+ for (let index = 0; index < input.length; index += 1) {
19
+ const char = input[index];
20
+ if (quoted) {
21
+ if (char === '"' && input[index + 1] === '"') { field += '"'; index += 1; }
22
+ else if (char === '"') quoted = false;
23
+ else field += char;
24
+ } else if (char === '"' && field === "") quoted = true;
25
+ else if (char === ",") { record.push(field); field = ""; }
26
+ else if (char === "\n") { record.push(field.replace(/\r$/, "")); records.push(record); record = []; field = ""; }
27
+ else if (char === '"') throw new Error(`${filename}: quote inside unquoted field`);
28
+ else field += char;
29
+ }
30
+ if (quoted) throw new Error(`${filename}: unclosed quoted field`);
31
+ if (field || record.length) { record.push(field.replace(/\r$/, "")); records.push(record); }
32
+ while (records.length && records.at(-1).every((value) => value === "")) records.pop();
33
+ const headers = records.shift() || [];
34
+ const rows = records.filter((row) => row.some((value) => value !== ""));
35
+ for (const [index, row] of rows.entries()) {
36
+ if (row.length !== headers.length) throw new Error(`${filename}:${index + 2}: invalid width`);
37
+ }
38
+ return { headers, rows: rows.map((row) => Object.fromEntries(headers.map((header, index) => [header, row[index]]))) };
39
+ }
40
+
41
+ function csvValue(value) {
42
+ const text = String(value ?? "");
43
+ return /[",\r\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
44
+ }
45
+
46
+ function firstValue(row, fields) {
47
+ for (const field of fields) if (row[field]) return row[field];
48
+ return "";
49
+ }
50
+
51
+ const tableFiles = fs.readdirSync(dataDir)
52
+ .filter((name) => name.endsWith(".csv"))
53
+ .sort((a, b) => a.localeCompare(b));
54
+
55
+ const idPriority = [
56
+ "case_id", "claim_id", "source_id", "event_id", "candidate_id", "watch_id",
57
+ "election_id", "turnout_id", "result_id", "official_source_id", "metric_id",
58
+ "pathway_id", "observation_id", "evaluation_id", "content_id", "actor_id",
59
+ "technology_use_id", "sampling_id", "coverage_id"
60
+ ];
61
+ const labelPriority = [
62
+ "title", "case_title", "claim_text", "description", "election_name", "candidate_or_option",
63
+ "source_title", "observable_indicator", "metric_code", "system_or_model", "summary", "notes"
64
+ ];
65
+
66
+ const indexed = [];
67
+ for (const filename of tableFiles) {
68
+ const table = filename.slice(0, -4);
69
+ const parsed = parseCsv(fs.readFileSync(path.join(dataDir, filename), "utf8"), filename);
70
+ for (const [index, row] of parsed.rows.entries()) {
71
+ const recordId = firstValue(row, idPriority) || `${table}:${index + 1}`;
72
+ const label = firstValue(row, labelPriority) || recordId;
73
+ indexed.push({
74
+ table_name: table,
75
+ row_number: index + 1,
76
+ record_id: recordId,
77
+ label,
78
+ country: firstValue(row, ["country", "jurisdiction", "geographic_unit_name"]),
79
+ case_id: row.case_id || "",
80
+ claim_id: row.claim_id || "",
81
+ source_id: row.source_id || row.official_source_id || "",
82
+ record_json: JSON.stringify(row)
83
+ });
84
+ }
85
+ }
86
+
87
+ if (indexed.length !== 1087) throw new Error(`Expected 1087 canonical rows; found ${indexed.length}`);
88
+
89
+ fs.mkdirSync(outDir, { recursive: true });
90
+ const columns = ["table_name", "row_number", "record_id", "label", "country", "case_id", "claim_id", "source_id", "record_json"];
91
+ const csv = [columns.join(","), ...indexed.map((row) => columns.map((column) => csvValue(row[column])).join(","))].join("\n") + "\n";
92
+ fs.writeFileSync(path.join(outDir, "record_index.csv"), csv);
93
+
94
+ const schema = new parquet.ParquetSchema({
95
+ table_name: { type: "UTF8" },
96
+ row_number: { type: "INT64" },
97
+ record_id: { type: "UTF8" },
98
+ label: { type: "UTF8" },
99
+ country: { type: "UTF8", optional: true },
100
+ case_id: { type: "UTF8", optional: true },
101
+ claim_id: { type: "UTF8", optional: true },
102
+ source_id: { type: "UTF8", optional: true },
103
+ record_json: { type: "UTF8" }
104
+ });
105
+ const target = path.join(outDir, "record_index.parquet");
106
+ const temporary = `${target}.tmp`;
107
+ fs.rmSync(temporary, { force: true });
108
+ const writer = await parquet.ParquetWriter.openFile(schema, temporary);
109
+ try {
110
+ for (const row of indexed) await writer.appendRow(row);
111
+ } finally {
112
+ await writer.close();
113
+ }
114
+ fs.renameSync(temporary, target);
115
+
116
+ process.stdout.write(`${JSON.stringify({ rows: indexed.length, tables: tableFiles.length, output: "record_index.parquet" })}\n`);
scripts/validate-data.mjs CHANGED
@@ -1,10 +1,10 @@
1
  #!/usr/bin/env node
2
 
3
  /**
4
- * Deterministic v0.4.0 release validator.
5
  *
6
  * Default mode verifies source CSV/stat manifests, the stored/live semantic
7
- * audit, all Parquet files and any v0.4.0 release artifacts. --source-only
8
  * omits derived Parquet/release checks so builders can validate inputs first.
9
  */
10
 
@@ -15,9 +15,12 @@ import { createRequire } from "node:module";
15
  import { spawnSync } from "node:child_process";
16
  import { fileURLToPath } from "node:url";
17
 
 
 
18
  const RELEASE_VERSION = "0.4.0";
 
19
  const AUDITOR_ID = `agency-transfer-election-cases-v${RELEASE_VERSION}/audit-v04`;
20
- const VALIDATOR_ID = `agency-transfer-election-cases-v${RELEASE_VERSION}/validate-data`;
21
  const here = path.dirname(fileURLToPath(import.meta.url));
22
  const packageRoot = path.resolve(here, "..");
23
  const positional = process.argv.slice(2).filter((arg) => !arg.startsWith("--"));
@@ -214,22 +217,22 @@ for (const [filename, expectedHash] of Object.entries(isPlainObject(fileHashes)
214
  // Release version identity across public metadata and package managers.
215
  const packageJson = readJson(path.join(packageRoot, "package.json"), "package.json", "PACKAGE_JSON");
216
  const packageLock = readJson(path.join(packageRoot, "package-lock.json"), "package-lock.json", "PACKAGE_LOCK");
217
- if (packageJson && packageJson.version !== RELEASE_VERSION) fileError("PACKAGE_VERSION_MISMATCH", "package.json", `Expected ${RELEASE_VERSION}; found ${packageJson.version ?? "missing"}`);
218
- if (packageLock && packageLock.version !== RELEASE_VERSION) fileError("LOCK_VERSION_MISMATCH", "package-lock.json", `Expected ${RELEASE_VERSION}; found ${packageLock.version ?? "missing"}`);
219
- if (packageLock && packageLock.packages?.[""]?.version !== RELEASE_VERSION) {
220
- fileError("LOCK_ROOT_VERSION_MISMATCH", "package-lock.json", `Expected root package ${RELEASE_VERSION}; found ${packageLock.packages?.[""]?.version ?? "missing"}`);
221
  }
222
  const readmePath = path.join(packageRoot, "README.md");
223
  if (!fs.existsSync(readmePath)) fileError("README_MISSING", "README.md", "README.md is missing");
224
- else if (!new RegExp(`Version\\s+(?:\\x60|'|")?${RELEASE_VERSION.replaceAll(".", "\\.")}`).test(fs.readFileSync(readmePath, "utf8"))) {
225
- fileError("README_VERSION_MISMATCH", "README.md", `README must declare Version ${RELEASE_VERSION}`);
226
  }
227
  const citationPath = path.join(packageRoot, "CITATION.cff");
228
  if (!fs.existsSync(citationPath)) fileError("CITATION_MISSING", "CITATION.cff", "CITATION.cff is missing");
229
  else {
230
  const citation = fs.readFileSync(citationPath, "utf8");
231
  const match = /^version:\s*["']?([^\s"']+)["']?\s*$/m.exec(citation);
232
- if (!match || match[1] !== RELEASE_VERSION) fileError("CITATION_VERSION_MISMATCH", "CITATION.cff", `CITATION must declare version ${RELEASE_VERSION}`);
233
  }
234
 
235
  // Stored audits must be identical and must exactly match a fresh deterministic run.
@@ -455,7 +458,8 @@ const integrityFailed = fileErrors.length > 0 || auditIntegrity?.status !== "pas
455
  const semanticFailed = !auditReport || semanticAudit?.status !== "pass";
456
  const report = {
457
  validator: VALIDATOR_ID,
458
- version: RELEASE_VERSION,
 
459
  mode: sourceOnly ? "source-only" : "full-release",
460
  status: integrityFailed || semanticFailed ? "fail" : "pass",
461
  integrity: {
 
1
  #!/usr/bin/env node
2
 
3
  /**
4
+ * Deterministic repository validator.
5
  *
6
  * Default mode verifies source CSV/stat manifests, the stored/live semantic
7
+ * audit, all Parquet files and the frozen v0.4.0 release artifacts. --source-only
8
  * omits derived Parquet/release checks so builders can validate inputs first.
9
  */
10
 
 
15
  import { spawnSync } from "node:child_process";
16
  import { fileURLToPath } from "node:url";
17
 
18
+ // v0.4.1 changes only the public exploration layer. The canonical relational
19
+ // data, native Parquet files and packaged artifacts remain frozen at v0.4.0.
20
  const RELEASE_VERSION = "0.4.0";
21
+ const REPOSITORY_VERSION = "0.4.1";
22
  const AUDITOR_ID = `agency-transfer-election-cases-v${RELEASE_VERSION}/audit-v04`;
23
+ const VALIDATOR_ID = `agency-transfer-election-cases-v${REPOSITORY_VERSION}/validate-data`;
24
  const here = path.dirname(fileURLToPath(import.meta.url));
25
  const packageRoot = path.resolve(here, "..");
26
  const positional = process.argv.slice(2).filter((arg) => !arg.startsWith("--"));
 
217
  // Release version identity across public metadata and package managers.
218
  const packageJson = readJson(path.join(packageRoot, "package.json"), "package.json", "PACKAGE_JSON");
219
  const packageLock = readJson(path.join(packageRoot, "package-lock.json"), "package-lock.json", "PACKAGE_LOCK");
220
+ if (packageJson && packageJson.version !== REPOSITORY_VERSION) fileError("PACKAGE_VERSION_MISMATCH", "package.json", `Expected ${REPOSITORY_VERSION}; found ${packageJson.version ?? "missing"}`);
221
+ if (packageLock && packageLock.version !== REPOSITORY_VERSION) fileError("LOCK_VERSION_MISMATCH", "package-lock.json", `Expected ${REPOSITORY_VERSION}; found ${packageLock.version ?? "missing"}`);
222
+ if (packageLock && packageLock.packages?.[""]?.version !== REPOSITORY_VERSION) {
223
+ fileError("LOCK_ROOT_VERSION_MISMATCH", "package-lock.json", `Expected root package ${REPOSITORY_VERSION}; found ${packageLock.packages?.[""]?.version ?? "missing"}`);
224
  }
225
  const readmePath = path.join(packageRoot, "README.md");
226
  if (!fs.existsSync(readmePath)) fileError("README_MISSING", "README.md", "README.md is missing");
227
+ else if (!new RegExp(`Version\\s+(?:\\x60|'|")?${REPOSITORY_VERSION.replaceAll(".", "\\.")}`).test(fs.readFileSync(readmePath, "utf8"))) {
228
+ fileError("README_VERSION_MISMATCH", "README.md", `README must declare Version ${REPOSITORY_VERSION}`);
229
  }
230
  const citationPath = path.join(packageRoot, "CITATION.cff");
231
  if (!fs.existsSync(citationPath)) fileError("CITATION_MISSING", "CITATION.cff", "CITATION.cff is missing");
232
  else {
233
  const citation = fs.readFileSync(citationPath, "utf8");
234
  const match = /^version:\s*["']?([^\s"']+)["']?\s*$/m.exec(citation);
235
+ if (!match || match[1] !== REPOSITORY_VERSION) fileError("CITATION_VERSION_MISMATCH", "CITATION.cff", `CITATION must declare version ${REPOSITORY_VERSION}`);
236
  }
237
 
238
  // Stored audits must be identical and must exactly match a fresh deterministic run.
 
458
  const semanticFailed = !auditReport || semanticAudit?.status !== "pass";
459
  const report = {
460
  validator: VALIDATOR_ID,
461
+ version: REPOSITORY_VERSION,
462
+ canonical_data_version: RELEASE_VERSION,
463
  mode: sourceOnly ? "source-only" : "full-release",
464
  status: integrityFailed || semanticFailed ? "fail" : "pass",
465
  integrity: {
scripts/validate-viewer.mjs ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import parquet from "parquetjs-lite";
7
+
8
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
9
+ const expected = new Map([
10
+ ["record_index", 1087],
11
+ ["case_catalog", 64],
12
+ ["research_view", 10],
13
+ ["claim_evidence", 124]
14
+ ]);
15
+ const targets = new Map([
16
+ ["record_index", "record_index.csv"],
17
+ ["case_catalog", "parquet/case_catalog.parquet"],
18
+ ["research_view", "parquet/research_view.parquet"],
19
+ ["claim_evidence", "parquet/claim_evidence.parquet"]
20
+ ]);
21
+
22
+ async function countRows(relativePath) {
23
+ if (relativePath.endsWith(".csv")) {
24
+ const input = fs.readFileSync(path.join(root, relativePath), "utf8").replace(/^\uFEFF/, "");
25
+ let rows = 0;
26
+ let quoted = false;
27
+ for (let index = 0; index < input.length; index += 1) {
28
+ if (input[index] === '"' && quoted && input[index + 1] === '"') index += 1;
29
+ else if (input[index] === '"') quoted = !quoted;
30
+ else if (input[index] === "\n" && !quoted) rows += 1;
31
+ }
32
+ if (quoted) throw new Error(`${relativePath}: unclosed quoted field`);
33
+ return Math.max(0, rows - 1);
34
+ }
35
+ const reader = await parquet.ParquetReader.openFile(path.join(root, relativePath));
36
+ const cursor = reader.getCursor();
37
+ let count = 0;
38
+ try {
39
+ while (await cursor.next()) count += 1;
40
+ } finally {
41
+ await reader.close();
42
+ }
43
+ return count;
44
+ }
45
+
46
+ const readme = fs.readFileSync(path.join(root, "README.md"), "utf8");
47
+ const frontmatter = readme.match(/^---\n([\s\S]*?)\n---/)?.[1] || "";
48
+ for (const [config, rows] of expected) {
49
+ if (!frontmatter.includes(`config_name: ${config}`)) throw new Error(`README is missing ${config}`);
50
+ const actual = await countRows(targets.get(config));
51
+ if (actual !== rows) throw new Error(`${config}: expected ${rows} rows; found ${actual}`);
52
+ }
53
+ if (!/config_name: record_index\n\s+default: true/.test(frontmatter)) throw new Error("record_index must be the default configuration");
54
+ if (!/config_name: research_view\n\s+data_files: \[\{split: orientation_only,/.test(frontmatter)) {
55
+ throw new Error("research_view must use the orientation_only split");
56
+ }
57
+
58
+ const reader = await parquet.ParquetReader.openFile(path.join(root, "record_index.parquet"));
59
+ const cursor = reader.getCursor();
60
+ const tableCounts = new Map();
61
+ try {
62
+ let row;
63
+ while ((row = await cursor.next())) {
64
+ JSON.parse(row.record_json);
65
+ tableCounts.set(row.table_name, (tableCounts.get(row.table_name) || 0) + 1);
66
+ }
67
+ } finally {
68
+ await reader.close();
69
+ }
70
+ if (tableCounts.size !== 26) throw new Error(`record_index: expected 26 tables; found ${tableCounts.size}`);
71
+
72
+ process.stdout.write(`${JSON.stringify({ status: "pass", configurations: Object.fromEntries(expected), indexed_tables: tableCounts.size })}\n`);