From acadd3600f048651f1cdb886368906f2dc6c332e Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 13:29:55 -0700 Subject: [PATCH 01/30] polis-api: a typed read route for a Delphi job's log, behind its own switch (#3229) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rust read route only, off by default (POLIS_API_DELPHI_LOGS_READS=1 plus the delphiLogs arm of RUST_API_ROUTES); no Node handler, schema or write change. GET /api/v3/delphi/logs?job_id=… served by polis-api with the run-record route's moderator rule (never an identity inferred from an unverified token), byte-faithful to Node against the Postgres-mode recording baseline, including stored log text carrying lone UTF-16 surrogate escapes, which Node accepts. A 502 hands the request to Node. Reviewed independently: publish as-is with the correction (folded in). Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- file-server/nginx/docker-entrypoint.sh | 8 +- .../delphiLogs.location.conf.template | 17 + polis-cli/tests/differential/routes.json | 10 + queue-rs/polis-api/README.md | 37 ++ .../conformance/delphi-logs-check.cjs | 89 ++++ .../conformance/delphi-logs-compose.yml | 65 +++ .../polis-api/conformance/delphi-logs-run.sh | 26 ++ .../polis-api/conformance/nginx-routing.sh | 23 ++ queue-rs/polis-api/src/delphi_logs.rs | 388 ++++++++++++++++++ queue-rs/polis-api/src/main.rs | 50 +++ queue-rs/polis-api/src/next_comment.rs | 10 + queue-rs/polis-api/src/route.rs | 104 +++++ queue-rs/polis-contracts/src/delphi_logs.rs | 66 +++ queue-rs/polis-contracts/src/lib.rs | 1 + server/characterization/delphi/main.cjs | 13 +- 15 files changed, 904 insertions(+), 3 deletions(-) create mode 100644 file-server/nginx/rust-api/delphiLogs.location.conf.template create mode 100644 queue-rs/polis-api/conformance/delphi-logs-check.cjs create mode 100644 queue-rs/polis-api/conformance/delphi-logs-compose.yml create mode 100755 queue-rs/polis-api/conformance/delphi-logs-run.sh create mode 100644 queue-rs/polis-api/src/delphi_logs.rs create mode 100644 queue-rs/polis-contracts/src/delphi_logs.rs diff --git a/file-server/nginx/docker-entrypoint.sh b/file-server/nginx/docker-entrypoint.sh index 51a80ba44..4ecf4d35a 100644 --- a/file-server/nginx/docker-entrypoint.sh +++ b/file-server/nginx/docker-entrypoint.sh @@ -204,6 +204,12 @@ for route in $(echo "${RUST_API_ROUTES:-}" | tr ',' ' '); do " rust_api_locations="${rust_api_locations} topicStats" ;; + delphiLogs) + case " $rust_api_locations " in *" delphiLogs "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/logs ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} delphiLogs" + ;; delphiRun) case " $rust_api_locations " in *" delphiRun "*) continue ;; esac RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/run ${RUST_API_UPSTREAM}; @@ -343,7 +349,7 @@ for route in $(echo "${RUST_API_ROUTES:-}" | tr ',' ' '); do done export RUST_API_RESOLVER=${RUST_API_RESOLVER:-127.0.0.11} if [ -n "$rust_api_unknown" ]; then - echo "ERROR RUST_API_ROUTES: unknown route(s):${rust_api_unknown} (known: pca2 owner-conversations comments nextComment testConnection testDatabase contexts domainWhitelist metadataQuestions metadataAnswers metadataRead metadataChoices recentStarted recentActivity legacyPca treeviteWaves treeviteInvites treeviteCsv conversationPreload participationRead allConversations reportsRead bidToPid conversationStats statementImportance topicSelections treeviteMyInvites treeviteMe topicPrioritize xidReport opsCatchall opsPage opsWhoami collectiveStatement topicStats delphiRun delphiResult delphiVisualizations delphiReports delphiRead otherConversationsPage integratePage adminPage userLogoutPage settingsPage userLoginPage userCreatePage createPage einvitesRead legacyConversations robots about). Every route stays on Node." >&2 + echo "ERROR RUST_API_ROUTES: unknown route(s):${rust_api_unknown} (known: pca2 owner-conversations comments nextComment testConnection testDatabase contexts domainWhitelist metadataQuestions metadataAnswers metadataRead metadataChoices recentStarted recentActivity legacyPca treeviteWaves treeviteInvites treeviteCsv conversationPreload participationRead allConversations reportsRead bidToPid conversationStats statementImportance topicSelections treeviteMyInvites treeviteMe topicPrioritize xidReport opsCatchall opsPage opsWhoami collectiveStatement topicStats delphiLogs delphiRun delphiResult delphiVisualizations delphiReports delphiRead otherConversationsPage integratePage adminPage userLogoutPage settingsPage userLoginPage userCreatePage createPage einvitesRead legacyConversations robots about). Every route stays on Node." >&2 elif [ -n "$RUST_API_MAP_ENTRIES" ] && ! echo "$RUST_API_UPSTREAM" | grep -Eqx '[A-Za-z0-9._-]+:[0-9]{1,5}'; then echo "ERROR RUST_API_UPSTREAM: '${RUST_API_UPSTREAM}' is not host:port. Every route stays on Node." >&2 diff --git a/file-server/nginx/rust-api/delphiLogs.location.conf.template b/file-server/nginx/rust-api/delphiLogs.location.conf.template new file mode 100644 index 000000000..6c41dbcc2 --- /dev/null +++ b/file-server/nginx/rust-api/delphiLogs.location.conf.template @@ -0,0 +1,17 @@ +# Legacy logs: both switches are off by default; unavailable reads hand back to Node. +location = /api/v3/delphi/logs { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 3s; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/polis-cli/tests/differential/routes.json b/polis-cli/tests/differential/routes.json index 5d8e92c7f..f1734bd2a 100644 --- a/polis-cli/tests/differential/routes.json +++ b/polis-cli/tests/differential/routes.json @@ -442,5 +442,15 @@ "expected_requests": 1, "expected_node_handoffs": 0, "scope": "Rust-only public importance counts. The generated report case precedes all votes: both participant-visible statements must have zero counts. Node-off display retains statements with explicitly unavailable null counts; the named contract check preserves every other field." + }, + "delphiLogs": { + "path": "/api/v3/delphi/logs", + "minimum_rust_successes": 0, + "expected_requests": 1, + "expected_node_handoffs": 1, + "commands": [ + "delphi logs" + ], + "scope": "The shared differential uses DynamoDB job fixtures, so this Postgres-only route remains disabled and the request hands back to Node. Dedicated Postgres conformance proves archived and native authorized logs and counts every Rust-served case." } } diff --git a/queue-rs/polis-api/README.md b/queue-rs/polis-api/README.md index f1dab678e..9ba73aab5 100644 --- a/queue-rs/polis-api/README.md +++ b/queue-rs/polis-api/README.md @@ -1359,3 +1359,40 @@ isolated aggregate-only metadata fixture; it is not a Node parity recording. The nginx suite covers default-off, opt-in, deduplication, method/body admission and the 502-to-Node-404 path. The database suite covers query bounds, real lock shedding, read-only enforcement and independent writer/next-statement resources. + + +### Legacy Delphi job logs + +`POLIS_API_DELPHI_LOGS_READS=1` and `RUST_API_ROUTES=delphiLogs` opt in to +`GET`/`HEAD /api/v3/delphi/logs?job_id=…`. Both are off by default. This route +requires `DELPHI_RESULT_BACKEND=postgres`, `DELPHI_RESULT_ENV` and +`POLIS_API_DELPHI_LOGS_DATABASE_URL` (a primary read login with the existing +result views and queue read functions). `DELPHI_RESULT_SCOPE`, when set, must +match Node. Identity reads use `POLIS_API_DELPHI_LOGS_AUTH_DATABASE_URL`, falling +back to the ordinary read DSN, through a separate pool. OIDC JWKS, participant +verification and `ADMIN_UIDS` must match Node as for the run-record route. + +The result pool has two slots, 15 ms acquire and 200 ms statement bounds. The +identity pool has one slot, 15 ms acquire and 50 ms statement bounds. The whole +request has a 750 ms deadline. Neither pool shares participation connections; +all sessions are read-only. Native rows take precedence over archived controls; +job lookup and latest-attempt logs use one repeatable-read snapshot. Native logs +retain the first 1,000 entries before filtering stdout/stderr, as Node does. + +The existing response fields and moderator rule are preserved. A complete +legacy archive is limited to 4 MiB and the response to 1 MiB. Unsupported archive +attributes, date grammars, credentials, bounds and database failures hand back +to Node with 502; no partial logs are returned. Naive legacy ISO timestamps are +handled only with explicit `TZ=UTC`; other time zones hand back to Node. No +writer, schema, result contract or production switch changes. + + +Run `queue-rs/polis-api/conformance/delphi-logs-run.sh result.json` with a unique +`COMPOSE_PROJECT_NAME`, `POLIS_RECOVERY_PG_PORT`, and local +`DELPHI_LOGS_NODE_IMAGE`, `DELPHI_LOGS_POSTGRES_IMAGE`, and +`DELPHI_LOGS_API_IMAGE` (built with `fixture-clock`). It replays all 272 +Postgres baseline cases unchanged and compares every log case through Rust, +then adds native attempts, moderator controls, archive precedence and the +pre-filter entry limit. Its reader login has only the existing executor role. +The shared CLI differential retains its DynamoDB fixture and therefore checks +this route's disabled fallback; it does not claim Postgres log-serving coverage. diff --git a/queue-rs/polis-api/conformance/delphi-logs-check.cjs b/queue-rs/polis-api/conformance/delphi-logs-check.cjs new file mode 100644 index 000000000..e341e1c2a --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-logs-check.cjs @@ -0,0 +1,89 @@ +"use strict"; +const fs = require("node:fs"); +const path = require("node:path"); +exports.start = async function({keys,jwks,publicKey,request,serialize,oidc,database}) { + const {createRequire}=require("node:module"); + const {Client}=createRequire(path.resolve(process.cwd(),"package.json"))("pg"); + const permissions=new Client({connectionString:database});await permissions.connect(); + await permissions.query("CREATE ROLE generated_logs_reader LOGIN; GRANT polis_queue_executor TO generated_logs_reader"); + await permissions.end(); + fs.mkdirSync(keys,{recursive:true}); + fs.writeFileSync(path.join(keys,"jwks.json"),JSON.stringify(jwks)); + fs.writeFileSync(path.join(keys,"participant.pem"),publicKey); + fs.writeFileSync(path.join(keys,"ready"),"ready\n"); + const port=Number(process.env.P2ZERO_RUST_PORT||5100); + let ready=false; + for(let i=0;i<120;i++) { + try { const r=await request("/health",null,port); if(r.status===200){ready=true;break;} } catch {} + await new Promise(resolve=>setTimeout(resolve,250)); + } + if(!ready) throw Error("Rust logs readiness deadline"); + const captures=[]; + const handoffs=[]; + return { + async compare(c,token,node) { + const r=await request(c.path,token,port); + const rust=serialize(c,r); + captures.push({case:c.id,node:JSON.parse(node),rust:JSON.parse(rust),equal:node===rust}); + }, + async finish() { + // Native rows and attempts use the release SQL, after the baseline reads. + // No worker or model runs, and no vote is inserted by this fixture. + const {createRequire}=require("node:module"); + const {Client}=createRequire(path.resolve(process.cwd(),"package.json"))("pg"); + const db=new Client({connectionString:database}); await db.connect(); + const owner=oidc("p2zero|owner","owner@example.invalid"); + const other=oidc("p2zero|other","other@example.invalid"); + async function check(id,query,token,status,verify) { + const c={id:`supplemental/${id}`,state:"supplemental",route:"GET /api/v3/delphi/logs",path:query,auth:token===owner?"owner":token===other?"other":token?"moderator":"none"}; + const n=await request(query,token);const r=await request(query,token,port); + const node=serialize(c,n),rust=serialize(c,r); + if(n.status!==status) throw Error(`${id}: fixture Node status ${n.status}, want ${status}`); + if(verify)verify(JSON.parse(n.body)); + captures.push({case:c.id,node:JSON.parse(node),rust:JSON.parse(rust),equal:node===rust}); + } + const job="00000000-0000-4000-8000-00000000f001"; + const run="00000000-0000-4000-8000-00000000f002"; + const attempt="00000000-0000-4000-8000-00000000f003"; + const worker="00000000-0000-4000-8000-00000000f004"; + const query=`/api/v3/delphi/logs?job_id=${job}`; + await db.query("SELECT pd_writer_admit('p2zero',105,'delphi','generated-logs','native-logs',repeat('a',64),$1,$2,'delphi_full_pipeline',NULL,'{}',repeat('b',40))",[job,run]); + await check("native-no-attempt",query,owner,200,b=>{if(b.length)throw Error("expected no attempt logs");}); + const q=(await db.query("SELECT priority,worker_class FROM polis_queue_jobs WHERE env='p2zero' AND job_id=$1",[job])).rows[0]; + const claim=(await db.query("SELECT pq_claim('p2zero',$1::smallint,$2::uuid,$3::uuid,900,$4::text) AS claim",[q.priority,worker,attempt,q.worker_class])).rows[0].claim; + if(claim.job_id!==job)throw Error("native claim was not the generated job"); + await db.query(`INSERT INTO polis_queue_logs(env,attempt_id,seq,ts,stream,line) VALUES + ('p2zero',$1,1,'2023-11-14T20:21:00.123456Z','stdout','generated stdout'), + ('p2zero',$1,2,'2023-11-14T20:21:01Z','manifest','{}'), + ('p2zero',$1,3,'2023-11-14T20:21:02.999999Z','stderr','generated stderr'), + ('p2zero',$1,4,'2023-11-14T20:21:03Z','truncated','generated truncation')`,[attempt]); + await check("native-streams",query,owner,200,b=>{if(b.length!==2||b[0].timestamp!==1699993260123||!b[1].message.includes("ERROR: generated stderr"))throw Error("native stream fixture");}); + await check("native-foreign-owner",query,other,403); + await check("native-no-token",query,null,401); + await check("missing-job-id","/api/v3/delphi/logs",owner,400); + // Limit is applied before stdout/stderr filtering, not after it. + await db.query("INSERT INTO polis_queue_logs(env,attempt_id,seq,ts,stream,line) SELECT 'p2zero',$1,i,'2023-11-14T20:21:04Z','manifest','{}' FROM generate_series(5,1000) i",[attempt]); + await db.query("INSERT INTO polis_queue_logs(env,attempt_id,seq,ts,stream,line) VALUES('p2zero',$1,1001,'2023-11-14T20:21:05Z','stdout','must not appear')",[attempt]); + await check("native-limit-before-filter",query,owner,200,b=>{if(b.length!==2)throw Error("first 1000 then filter");}); + await db.query("INSERT INTO oidc_user_mappings(oidc_sub,uid) VALUES('p2zero|admin',2)"); + await check("native-admin",query,oidc("p2zero|admin","admin@example.invalid"),200); + await db.query("INSERT INTO users(uid,hname,email,is_owner,site_id) VALUES(200,'Generated Site Moderator','sitemod@example.invalid',true,'p2zero-owner'); INSERT INTO oidc_user_mappings(oidc_sub,uid) VALUES('p2zero|sitemod',200)"); + await check("native-site-moderator",query,oidc("p2zero|sitemod","sitemod@example.invalid"),200); + const archived="00000068-0000-4000-8000-000000000001"; + await db.query("SELECT pd_writer_admit('p2zero',104,'delphi','generated-logs','archive-precedence',repeat('c',64),$1,gen_random_uuid(),'delphi_full_pipeline',NULL,'{}',repeat('b',40))",[archived]); + await check("active-row-hides-archive",`/api/v3/delphi/logs?job_id=${archived}`,owner,200,b=>{if(b.length)throw Error("active row did not hide historical logs");}); + await db.query("UPDATE polis_queue_logs SET line=repeat('x',600000) WHERE env='p2zero' AND attempt_id=$1 AND seq IN (1,3)",[attempt]); + const oversized=await request(query,owner,port); + const nodeOversized=await request(query,owner); + if(oversized.status!==502||nodeOversized.status!==200||nodeOversized.body.length<=1024*1024)throw Error("native input cap does not hand back complete logs"); + handoffs.push({case:"native-input-cap",rustStatus:oversized.status,nodeStatus:nodeOversized.status,nodeBytes:nodeOversized.body.length}); + await db.end(); + const health=await request("/health",null,port); + const counters=JSON.parse(health.body); + const failures=captures.filter(c=>!c.equal); + fs.writeFileSync(path.join(keys,"results.json"),JSON.stringify({cases:captures.length,equal:captures.length-failures.length,failures:failures.length,counters,captures,handoffs},null,2)+"\n"); + console.log(`Rust logs: ${captures.length} cases, ${failures.length} differences`); + if(failures.length) throw Error(`Rust logs byte differences: ${failures.map(c=>c.case).join(", ")}`); + } + }; +}; diff --git a/queue-rs/polis-api/conformance/delphi-logs-compose.yml b/queue-rs/polis-api/conformance/delphi-logs-compose.yml new file mode 100644 index 000000000..64ad21742 --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-logs-compose.yml @@ -0,0 +1,65 @@ +services: + postgres: + image: ${DELPHI_LOGS_POSTGRES_IMAGE:?set a fixture Postgres image} + environment: {POSTGRES_HOST_AUTH_METHOD: trust} + ports: ["127.0.0.1:${POLIS_RECOVERY_PG_PORT:?set a unique port}:5432"] + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 2s + timeout: 2s + retries: 30 + dynamodb: + image: amazon/dynamodb-local:3.3.1@sha256:ff89bd48ff32cd8d9be5fee8873b65b8854dc408f1afe881be6eb00247bc0dab + command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-inMemory"] + recorder: + image: ${DELPHI_LOGS_NODE_IMAGE:?set a Node image} + working_dir: /app + entrypoint: [sh, -c] + command: ["cp -a /candidate/. /app/; exec node characterization/delphi/main.cjs replay"] + volumes: + - ${DELPHI_LOGS_SOURCE}/server:/candidate:ro + - ${DELPHI_LOGS_SOURCE}/delphi:/delphi + - ${DELPHI_LOGS_SOURCE}/queue-rs:/queue-rs:ro + - ${DELPHI_LOGS_SCRATCH}:/proof + environment: + P2ZERO_PG_ADMIN_URL: postgres://postgres@postgres:5432/postgres + DYNAMODB_ENDPOINT: http://dynamodb:8000 + DELPHI_RESULT_BACKEND: postgres + P2ZERO_RUST_KEYS: /proof + TZ: UTC + depends_on: + postgres: {condition: service_healthy} + dynamodb: {condition: service_started} + polis-api: + image: ${DELPHI_LOGS_API_IMAGE:?set a fixture-clock API image} + network_mode: service:recorder + entrypoint: [sh, -c] + command: ["while [ ! -f /proof/ready ]; do sleep 1; done; exec /usr/local/bin/polis-api"] + volumes: ["${DELPHI_LOGS_SCRATCH}:/proof:ro"] + environment: + DATABASE_URL: postgres://postgres@postgres:5432/p2zero + DATABASE_SSL: 'false' + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + MATH_ENV: p2zero + DEV_MODE: 'true' + POLIS_API_DELPHI_LOGS_DATABASE_URL: postgres://generated_logs_reader@postgres:5432/p2zero + POLIS_API_DELPHI_LOGS_AUTH_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_LOGS_READS: '1' + DELPHI_RESULT_BACKEND: postgres + DELPHI_RESULT_ENV: p2zero + DELPHI_RESULT_SCOPE: delphi + POLIS_API_READ_JWKS_FILE: /proof/jwks.json + POLIS_API_PARTICIPANT_READS: '1' + POLIS_API_PARTICIPANT_PUBLIC_KEY_FILE: /proof/participant.pem + POLIS_API_FIXTURE_CLOCK: '1700000000000' + AUTH_ISSUER: https://oidc.p2zero.invalid/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ + POLIS_JWT_ISSUER: https://pol.is/ + POLIS_JWT_AUDIENCE: participants + ADMIN_UIDS: '[2]' + DOMAIN_OVERRIDE: localhost + SERVICE_URL: http://localhost + NODE_ENV: production + TZ: UTC diff --git a/queue-rs/polis-api/conformance/delphi-logs-run.sh b/queue-rs/polis-api/conformance/delphi-logs-run.sh new file mode 100755 index 000000000..e1cd6e54e --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-logs-run.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Postgres baseline and native queue logs; all services are disposable fixtures. +# Requires three local images (Node, migration Postgres, fixture-clock polis-api). +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:?provide a results JSON path} +: "${COMPOSE_PROJECT_NAME:?set a unique project}" +: "${POLIS_RECOVERY_PG_PORT:?set a unique port}" +export RECOVERY_PG_PORT="$POLIS_RECOVERY_PG_PORT" +export DELPHI_LOGS_SOURCE="$root" +export DELPHI_LOGS_SCRATCH=${DELPHI_LOGS_SCRATCH:-$(mktemp -d)} +mkdir -p "$DELPHI_LOGS_SCRATCH" +[[ -z $(ls -A "$DELPHI_LOGS_SCRATCH") ]] || { echo "scratch must be empty" >&2; exit 2; } +compose=(docker compose -f "$root/queue-rs/polis-api/conformance/delphi-logs-compose.yml") +[[ -z $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]] || { echo "project already exists" >&2; exit 2; } +cleanup() { + "${compose[@]}" logs --no-color >"${out%.json}-services.log" 2>&1 || true + "${compose[@]}" down -v --remove-orphans >/dev/null 2>&1 || true +} +trap cleanup EXIT INT TERM +"${compose[@]}" up -d --pull never postgres dynamodb recorder polis-api +cid=$("${compose[@]}" ps -aq recorder) +result=$(docker wait "$cid") +"${compose[@]}" logs --no-color recorder +docker cp "$cid:/proof/results.json" "$out" +exit "$result" diff --git a/queue-rs/polis-api/conformance/nginx-routing.sh b/queue-rs/polis-api/conformance/nginx-routing.sh index 9dfabb506..3a3ef9e78 100755 --- a/queue-rs/polis-api/conformance/nginx-routing.sh +++ b/queue-rs/polis-api/conformance/nginx-routing.sh @@ -1310,3 +1310,26 @@ handback=$(docker exec "$p-proxy" wget -S -qO- 'http://127.0.0.1/api/v3/statemen docker rm -f "$p-node" >/dev/null stub "$p-node" server 5000 200 node echo "ok 61 Statement importance off/on/deduplicated; method/body guards; 502 hands back to Node, whose 404 answers (no Node handler)" + + +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +expect /api/v3/delphi/logs node "Logs off" +start delphiLogs,delphiLogs +expect '/api/v3/delphi/logs?job_id=x' rust "Logs on" +expect /api/v3/delphi/run node "Logs leave run record alone" +expect /api/v3/delphi/logs/ node "Logs path is exact" +expect /api/v3/comments node "Logs leave comments alone" +expect /api/v3/votes node "Logs leave votes alone" +[[ $(included | grep -c 'location = /api/v3/delphi/logs') == 1 ]] || fail "Logs duplicated" +expect_upstream polis-api GET /api/v3/delphi/logs $'Authorization: Bearer generated\r\n' +expect_upstream polis-api HEAD /api/v3/delphi/logs +expect_upstream server OPTIONS /api/v3/delphi/logs +expect_upstream server POST /api/v3/delphi/logs $'Content-Length: 2\r\n' '{}' +expect_upstream server GET /api/v3/delphi/logs $'Content-Length: 2\r\n' '{}' +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 "handoff" +sleep 6 +expect /api/v3/delphi/logs node "Logs handoff" +echo "ok 62 Logs off/on/deduplicated; method/body guards; 502 hands back to Node" diff --git a/queue-rs/polis-api/src/delphi_logs.rs b/queue-rs/polis-api/src/delphi_logs.rs new file mode 100644 index 000000000..6006b7d8f --- /dev/null +++ b/queue-rs/polis-api/src/delphi_logs.rs @@ -0,0 +1,388 @@ +//! Legacy logs on dedicated bounded pools. Unsupported values and unavailable +//! reads return 502 so Node remains the authority for their response bytes. +use crate::{ + http::{Outgoing, Request}, + js::{self, Js}, + route::{self, App, Res}, +}; +use anyhow::{Result, ensure}; +use postgres::{Client, IsolationLevel}; +use serde_json::Value; +#[path = "../../polis-contracts/src/delphi_logs.rs"] +mod contract; +pub use contract::PATH; + +pub struct Parsed { + authorization: Option, + request: contract::Request, +} +pub fn parse(app: &App, req: &Request) -> Option { + if app.delphi_logs_db.is_none() + || app.delphi_logs_auth_db.is_none() + || req.path() != PATH + || !matches!(req.method.as_str(), "GET" | "HEAD") + || !req.body.is_empty() + || req.headers.get("transfer-encoding").is_some() + || req.headers.get("content-length").is_some_and(|v| v != "0") + { + return None; + } + let raw = req.query().unwrap_or(""); + if raw.len() > 1024 { + return None; + } + let mut job_id = None; + let mut seen = false; + for (k, v) in url::form_urlencoded::parse(raw.as_bytes()) { + if k != "job_id" || seen || v.len() > 100 { + return None; + } + seen = true; + if !v.is_empty() { + job_id = Some(v.into_owned()); + } + } + Some(Parsed { + authorization: req.headers.get("authorization").map(str::to_owned), + request: contract::Request { job_id }, + }) +} +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 2, + acquire_timeout: std::time::Duration::from_millis(15), + statement_timeout: std::time::Duration::from_millis(200), + max_lifetime: std::time::Duration::from_secs(300), + } +} +pub fn auth_pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 1, + statement_timeout: std::time::Duration::from_millis(50), + ..pool_limits() + } +} + +pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { + let Some(parsed) = parse(app, req) else { + return route::bad_gateway(); + }; + match tokio::time::timeout(std::time::Duration::from_millis(750), answer(app, parsed)).await { + Ok(Some((status, body))) => route::json_text(req, res, status, body), + _ => route::bad_gateway(), + } +} +fn refusal(status: u16, body: impl serde::Serialize) -> Option<(u16, String)> { + Some((status, crate::wire::to_json(&body).ok()?)) +} +async fn answer(app: &App, parsed: Parsed) -> Option<(u16, String)> { + let auth = app.delphi_logs_auth_db.as_ref()?; + let raw = match parsed + .authorization + .as_deref() + .filter(|s| s.starts_with("Bearer ")) + { + Some(raw) => raw, + None => return refusal(401, contract::Unauthenticated::no_token()), + }; + let uid = crate::hybrid_read::resolve( + Some(raw), + app.participant_verifier.as_deref(), + app.read_oidc.as_deref(), + auth, + ) + .await? + .uid()?; + let Some(job_id) = parsed.request.job_id else { + return refusal(400, contract::Refusal::missing()); + }; + let env = app.delphi_logs_env.clone(); + let scope = app.delphi_logs_scope.clone(); + let job = job_id.clone(); + let found = app + .delphi_logs_db + .as_ref()? + .with(move |c| read(c, &env, scope.as_deref(), &job)) + .await + .ok()?; + let Some((conversation, events)) = found else { + return refusal(404, contract::Refusal::not_found()); + }; + let admins = app.legacy_admin_uids.clone(); + let permitted = auth + .with(move |c| { + let zid = + if !conversation.is_empty() && conversation.bytes().all(|b| b.is_ascii_digit()) { + conversation.parse::().ok() + } else { + crate::db::zid_for_conversation_id(c, &conversation)? + }; + zid.map(|zid| crate::treevite_read::permits(c, zid, uid, &admins)) + .transpose() + }) + .await + .ok()?; + match permitted { + None => refusal(404, contract::Refusal::not_found()), + Some(false) => refusal(403, contract::Refusal::denied()), + Some(true) => refusal(200, events), + } +} + +/// The same snapshot and active-row precedence as Node's GetCommand adapter. +fn read( + c: &mut Client, + env: &str, + scope: Option<&str>, + job: &str, +) -> Result)>> { + let mut tx = c + .build_transaction() + .isolation_level(IsolationLevel::RepeatableRead) + .read_only(true) + .start()?; + let rows=tx.query("SELECT conversation_id FROM public.delphi_result_jobs WHERE env=$1 AND ($2::text IS NULL OR scope_key=$2) AND job_id=$3", &[&env,&scope,&job])?; + ensure!(rows.len() <= 1, "ambiguous active job"); + if let Some(row) = rows.first() { + let conversation: String = row.try_get(0)?; + let status: Option = tx + .query_one( + "SELECT public.pq_job_status($1::text,($2::text)::uuid)::text", + &[&env, &job], + )? + .try_get(0)?; + let status: Value = serde_json::from_str(status.as_deref().unwrap_or("null"))?; + let mut events = Vec::new(); + if let Some(attempt) = status.get("attempt_id").and_then(Value::as_str) { + let bytes: i64 = tx.query_one("SELECT coalesce(sum(octet_length(line)),0)::bigint FROM public.pq_attempt_logs($1::text,($2::text)::uuid,NULL,1000) WHERE stream IN ('stdout','stderr')", &[&env,&attempt])?.try_get(0)?; + ensure!(bytes <= 1024 * 1024, "native log input cap"); + for row in tx.query("SELECT floor(extract(epoch FROM ts)*1000)::bigint, CASE stream WHEN 'stderr' THEN 'ERROR' ELSE 'INFO' END, line FROM public.pq_attempt_logs($1::text,($2::text)::uuid,NULL,1000) WHERE stream IN ('stdout','stderr')", &[&env,&attempt])? { + let timestamp=row.try_get(0)?; let level: String=row.try_get(1)?; let line: String=row.try_get(2)?; + events.push(contract::Event {timestamp:Some(timestamp),message:format!("[DELPHI JOB {job}] {level}: {line}")}); + } + } + ensure!( + crate::wire::to_json(&events)?.len() <= 1024 * 1024, + "log response cap" + ); + return Ok(Some((conversation, events))); + } + // A Get for an unknown native id scans the current legacy controls. Bound + // the complete scan before allocation; never return a partial archive. + let size: i64=tx.query_one("SELECT coalesce(sum(octet_length(codec_wire)),0)::bigint FROM public.delphi_result_legacy_controls WHERE env=$1 AND family='Delphi_JobQueue' AND ($2::text IS NULL OR scope_key=$2)", &[&env,&scope])?.try_get(0)?; + ensure!(size <= 4 * 1024 * 1024, "legacy archive cap"); + let mut found: Option = None; + let mut all = std::collections::BTreeMap::::new(); + for row in tx.query("SELECT codec_wire FROM public.delphi_result_legacy_controls WHERE env=$1 AND family='Delphi_JobQueue' AND ($2::text IS NULL OR scope_key=$2) ORDER BY zid,scope_key", &[&env,&scope])? { + let wire: String=row.try_get(0)?; + let mut lines=wire.lines(); + let header: Value=serde_json::from_str(lines.next().unwrap_or(""))?; + ensure!(header["codec"]=="delphi-storage-codec/1" && header["family"]=="Delphi_JobQueue","archive family"); + for line in lines { + let tag: Value=serde_json::from_str(line)?; + let id = tag["job_id"]["S"].as_str().ok_or_else(||anyhow::anyhow!("unsupported archived job id"))?; + if let Some(previous)=all.insert(id.to_owned(),tag.clone()) {ensure!(previous==tag,"ambiguous archive");} + if id!=job { continue; } + if let Some(previous)=&found { ensure!(previous==&tag,"ambiguous archived job"); } + found=Some(tag); + } + } + let Some(tag) = found else { + return Ok(None); + }; + let Some(conversation) = tag["conversation_id"]["S"] + .as_str() + .filter(|s| !s.is_empty()) + else { + // Other JavaScript coercions are Node-owned, including numeric metadata. + anyhow::bail!("unsupported archived conversation"); + }; + let logs = tag + .get("logs") + .map(attribute) + .transpose()? + .unwrap_or(Js::Null); + let events = log_events(logs, job) + .ok_or_else(|| anyhow::anyhow!("unsupported archived log timestamp"))?; + ensure!( + crate::wire::to_json(&events)?.len() <= 1024 * 1024, + "log response cap" + ); + Ok(Some((conversation.to_owned(), events))) +} +fn attribute(v: &Value) -> Result { + if let Some(s) = v.get("S").and_then(Value::as_str) { + return Ok(Js::Str(s.into())); + } + if let Some(b) = v.get("BOOL").and_then(Value::as_bool) { + return Ok(Js::Bool(b)); + } + if v.get("NULL") == Some(&Value::Bool(true)) { + return Ok(Js::Null); + } + if let Some(list) = v.get("L").and_then(Value::as_array) { + return Ok(Js::Arr(list.iter().map(attribute).collect::>()?)); + } + if let Some(map) = v.get("M").and_then(Value::as_object) { + let mut obj = js::Obj::new(); + for (key, value) in map { + obj.set(key, attribute(value)?); + } + return Ok(Js::Obj(obj)); + } + // Set, binary and numeric coercions stay with the legacy adapter. + anyhow::bail!("unsupported archived log attribute") +} +fn log_events(raw: Js, job: &str) -> Option> { + let parsed = match raw { + // JavaScript accepts lone surrogate escapes; the UTF-8 parser does + // not. Such valid JSON must hand back, never become an empty log list. + Js::Str(s) if s.to_ascii_lowercase().contains("\\ud") => return None, + Js::Str(s) => js::parse(&s).unwrap_or(Js::Null), + other => other, + }; + let Some(Js::Arr(entries)) = parsed.as_obj().and_then(|o| o.get("entries")) else { + return Some(Vec::new()); + }; + if entries.len() > 1000 { + return None; + } + entries + .iter() + .map(|entry| { + let field = |key| entry.as_obj().and_then(|o| o.get(key)); + let timestamp = match field("timestamp") { + None | Some(Js::Null) => None, + Some(Js::Str(s)) if s.is_empty() => None, + Some(Js::Str(s)) => Some(iso_millis(s)?), + _ => return None, + }; + let level = field("level") + .filter(|v| v.truthy()) + .map(Js::to_js_string) + .unwrap_or_else(|| "INFO".into()); + let message = field("message") + .filter(|v| !matches!(v, Js::Null)) + .map(Js::to_js_string) + .unwrap_or_default(); + Some(contract::Event { + timestamp, + message: format!("[DELPHI JOB {job}] {level}: {message}"), + }) + }) + .collect() +} +/// ISO timestamps only. Date.parse's other grammars stay with Node. Legacy +/// Python timestamps without a zone are admitted only under explicit UTC. +fn iso_millis(s: &str) -> Option { + let s = if let Some(s) = s.strip_suffix('Z') { + s + } else { + if std::env::var("TZ").ok().as_deref() != Some("UTC") { + return None; + } + s + }; + let b = s.as_bytes(); + if b.len() < 19 + || b[4] != b'-' + || b[7] != b'-' + || b[10] != b'T' + || b[13] != b':' + || b[16] != b':' + { + return None; + } + let num = |a: usize, z: usize| -> Option { + let p = b.get(a..z)?; + if !p.iter().all(u8::is_ascii_digit) { + return None; + } + std::str::from_utf8(p).ok()?.parse().ok() + }; + let y = num(0, 4)?; + let m = num(5, 7)?; + let d = num(8, 10)?; + let h = num(11, 13)?; + let min = num(14, 16)?; + let sec = num(17, 19)?; + if !(1..=12).contains(&m) || !(1..=31).contains(&d) || h > 23 || min > 59 || sec > 59 { + return None; + } + let leap = y % 4 == 0 && (y % 100 != 0 || y % 400 == 0); + let days = [ + 31, + if leap { 29 } else { 28 }, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31, + ]; + if d > days[(m - 1) as usize] { + return None; + } + let ms = if b.len() == 19 { + 0 + } else { + if b[19] != b'.' || b.len() == 20 || !b[20..].iter().all(u8::is_ascii_digit) { + return None; + } + let mut f = 0; + for i in 20..23 { + f = f * 10 + i64::from(b.get(i).copied().unwrap_or(b'0') - b'0'); + } + f + }; + let year = y - i64::from(m <= 2); + let era = year.div_euclid(400); + let yo = year - era * 400; + let mp = m + if m > 2 { -3 } else { 9 }; + let doy = (153 * mp + 2) / 5 + d - 1; + let days = era * 146097 + yo * 365 + yo / 4 - yo / 100 + doy - 719468; + Some(((days * 24 + h) * 60 + min) * 60000 + sec * 1000 + ms) +} +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn iso_dates_keep_node_millisecond_truncation() { + assert_eq!(iso_millis("1970-01-01T00:00:00Z"), Some(0)); + assert_eq!(iso_millis("1969-12-31T23:59:59.999999Z"), Some(-1)); + assert_eq!( + iso_millis("2023-11-14T20:21:00.123456Z"), + Some(1699993260123) + ); + assert!(iso_millis("2023-02-29T00:00:00Z").is_none()); + assert!(iso_millis("2024-02-29T00:00:00Z").is_some()); + assert!(iso_millis("Tue, 14 Nov 2023 00:00:00 GMT").is_none()); + } + #[test] + fn log_projection_preserves_order_and_javascript_strings() { + assert!( + log_events( + Js::Str(r#"{"entries":[{"message":"\ud800"}]}"#.into()), + "job" + ) + .is_none() + ); + + let raw=js::parse(r#"{"entries":[{"timestamp":"1970-01-01T00:00:00Z","level":false,"message":{"x":1}},null,{"level":["WARN",3],"message":["x",null,2]}]}"#).unwrap(); + assert_eq!( + crate::wire::to_json(&log_events(raw, "job").unwrap()).unwrap(), + r#"[{"timestamp":0,"message":"[DELPHI JOB job] INFO: [object Object]"},{"message":"[DELPHI JOB job] INFO: "},{"message":"[DELPHI JOB job] WARN,3: x,,2"}]"# + ); + assert!( + log_events( + js::parse(r#"{"entries":[{"timestamp":"not a date"}]}"#).unwrap(), + "job" + ) + .is_none() + ); + } +} diff --git a/queue-rs/polis-api/src/main.rs b/queue-rs/polis-api/src/main.rs index 48130feb9..a13b80aa8 100644 --- a/queue-rs/polis-api/src/main.rs +++ b/queue-rs/polis-api/src/main.rs @@ -33,6 +33,7 @@ mod delphi_job_result; #[rustfmt::skip] #[path = "../../polis-contracts/src/delphi_run.rs"] mod delphi_run; +mod delphi_logs; mod delphi_read; mod delphi_reports; mod delphi_result_read; @@ -182,6 +183,14 @@ async fn health(app: &route::App) -> Outgoing { "topicStatsFallback", js::Js::Num(app.topic_stats_fallback.load(Ordering::Relaxed) as f64), ); + body.set( + "delphiLogsServed", + js::Js::Num(app.delphi_logs_served.load(Ordering::Relaxed) as f64), + ); + body.set( + "delphiLogsFallback", + js::Js::Num(app.delphi_logs_fallback.load(Ordering::Relaxed) as f64), + ); body.set( "delphiRunServed", js::Js::Num(app.delphi_run_served.load(Ordering::Relaxed) as f64), @@ -558,6 +567,7 @@ async fn dispatch_at_clock( | delphi_read::PATH | collective_statement::PATH | topic_stats::PATH + | delphi_logs::PATH | delphi_run_read::PATH | delphi_visualizations::PATH | delphi_reports::PATH @@ -744,6 +754,46 @@ async fn main() -> Result<()> { topic_stats::pool_limits(), )); } + if std::env::var("POLIS_API_DELPHI_LOGS_READS").ok().as_deref() == Some("1") { + anyhow::ensure!( + std::env::var("DELPHI_RESULT_BACKEND").ok().as_deref() == Some("postgres"), + "Delphi logs require the Postgres result backend" + ); + state.delphi_logs_scope = std::env::var("DELPHI_RESULT_SCOPE") + .ok() + .filter(|s| !s.is_empty()); + // The record function's login: a member of polis_queue_executor. + let dsn = std::env::var("POLIS_API_DELPHI_LOGS_DATABASE_URL") + .context("POLIS_API_DELPHI_LOGS_DATABASE_URL is required for Delphi log reads")?; + // Identity and the moderator rule read Node's tables with Node's read + // login unless a dedicated one is given. + let auth_dsn = [ + "POLIS_API_DELPHI_LOGS_AUTH_DATABASE_URL", + "READ_ONLY_DATABASE_URL", + ] + .iter() + .find_map(|k| std::env::var(k).ok().filter(|s| !s.is_empty())) + .or_else(|| std::env::var("DATABASE_URL").ok()) + .context("a database for Delphi log identity reads is required")?; + state.delphi_logs_env = std::env::var("DELPHI_RESULT_ENV") + .ok() + .filter(|s| !s.is_empty()) + .context("DELPHI_RESULT_ENV is required for Delphi log reads")?; + state.delphi_logs_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-delphi-logs/1")?, + delphi_logs::pool_limits(), + )); + state.delphi_logs_auth_db = Some(db::Pool::new( + config::connector_for_dsn(&auth_dsn, "polis-api-delphi-logs-auth/1")?, + delphi_logs::auth_pool_limits(), + )); + state.read_oidc = hybrid_read::Oidc::from_env()?; + let admins = std::env::var("ADMIN_UIDS") + .ok() + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| "[]".into()); + state.legacy_admin_uids = recent_started::admin_uids(&admins)?; + } if std::env::var("POLIS_API_DELPHI_RUN_READS").ok().as_deref() == Some("1") { // The record function's login: a member of polis_queue_executor. let dsn = std::env::var("POLIS_API_DELPHI_RUN_DATABASE_URL") diff --git a/queue-rs/polis-api/src/next_comment.rs b/queue-rs/polis-api/src/next_comment.rs index cecb7ab05..7989ff75c 100644 --- a/queue-rs/polis-api/src/next_comment.rs +++ b/queue-rs/polis-api/src/next_comment.rs @@ -565,6 +565,14 @@ mod tests { Connector::Plain(Box::new(pg.clone())), crate::delphi_result_read::auth_pool_limits(), )); + app.delphi_logs_db = Some(db::Pool::new( + Connector::Plain(Box::new(pg.clone())), + crate::delphi_logs::pool_limits(), + )); + app.delphi_logs_auth_db = Some(db::Pool::new( + Connector::Plain(Box::new(pg.clone())), + crate::delphi_logs::auth_pool_limits(), + )); let app = Arc::new(app); async fn park( pool: Arc, @@ -669,6 +677,7 @@ mod tests { app.comments_db.as_ref().unwrap(), app.comments_count_db.as_ref().unwrap(), app.delphi_result_db.as_ref().unwrap(), + app.delphi_logs_db.as_ref().unwrap(), ] { for _ in 0..2 { held.push(park(pool.clone()).await); @@ -678,6 +687,7 @@ mod tests { for _ in 0..crate::statement_importance::pool_limits().size { held.push(park(app.statement_importance_db.as_ref().unwrap().clone()).await); } + held.push(park(app.delphi_logs_auth_db.as_ref().unwrap().clone()).await); let guarded = observe(app.clone()).await; eprintln!( "next statement isolation: deadline_ms={} control={control_sample:?} guarded={guarded:?} guarded/control={:.3}", diff --git a/queue-rs/polis-api/src/route.rs b/queue-rs/polis-api/src/route.rs index 3223ee229..aad6c94f3 100644 --- a/queue-rs/polis-api/src/route.rs +++ b/queue-rs/polis-api/src/route.rs @@ -149,6 +149,12 @@ pub struct App { pub topic_stats_db: Option>, pub topic_stats_served: AtomicU64, pub topic_stats_fallback: AtomicU64, + pub delphi_logs_db: Option>, + pub delphi_logs_auth_db: Option>, + pub delphi_logs_env: String, + pub delphi_logs_served: AtomicU64, + pub delphi_logs_fallback: AtomicU64, + pub delphi_logs_scope: Option, pub delphi_run_db: Option>, pub delphi_run_auth_db: Option>, pub delphi_run_env: String, @@ -340,6 +346,12 @@ impl App { topic_stats_db: None, topic_stats_served: AtomicU64::new(0), topic_stats_fallback: AtomicU64::new(0), + delphi_logs_db: None, + delphi_logs_auth_db: None, + delphi_logs_env: String::new(), + delphi_logs_served: AtomicU64::new(0), + delphi_logs_fallback: AtomicU64::new(0), + delphi_logs_scope: None, delphi_run_db: None, delphi_run_auth_db: None, delphi_run_env: String::new(), @@ -1204,6 +1216,13 @@ pub async fn handle(app: Arc, req: Request) -> Outgoing { app.topic_stats_served.fetch_add(1, Ordering::Relaxed); } } + if req.path() == crate::delphi_logs::PATH { + if out.status == 502 { + app.delphi_logs_fallback.fetch_add(1, Ordering::Relaxed); + } else { + app.delphi_logs_served.fetch_add(1, Ordering::Relaxed); + } + } if req.path() == crate::delphi_run_read::PATH { if out.status == 502 { app.delphi_run_fallback.fetch_add(1, Ordering::Relaxed); @@ -1556,6 +1575,9 @@ async fn serve(app: &App, req: &Request) -> Outgoing { if req.path() == crate::topic_stats::PATH && crate::topic_stats::parse(app, req).is_none() { return bad_gateway(); } + if req.path() == crate::delphi_logs::PATH && crate::delphi_logs::parse(app, req).is_none() { + return bad_gateway(); + } if req.path() == crate::delphi_run_read::PATH && crate::delphi_run_read::parse(app, req).is_none() { @@ -1730,6 +1752,9 @@ async fn serve(app: &App, req: &Request) -> Outgoing { if req.path() == crate::topic_stats::PATH { return crate::topic_stats::handle(app, req, res).await; } + if req.path() == crate::delphi_logs::PATH { + return crate::delphi_logs::handle(app, req, res).await; + } if req.path() == crate::delphi_run_read::PATH { return crate::delphi_run_read::handle(app, req, res).await; } @@ -5904,6 +5929,85 @@ mod tests { assert_eq!(state.ops_catchall_fallback.load(Ordering::Relaxed), 6); } #[tokio::test] + async fn delphi_logs_gate_boundaries_and_refusals_without_database() { + let mut state = app(true); + let req = |target: &str, headers: &[(&str, &str)]| { + let mut r = request("GET", headers); + r.target = target.into(); + r + }; + let host = ("host", "localhost"); + let run = "/api/v3/delphi/logs?job_id=00000000-0000-4000-8000-000000000001"; + // Off by default: every request is Node's. + assert_eq!(handle(state.clone(), req(run, &[host])).await.status, 502); + let pool = state.db.clone(); + { + let app = Arc::get_mut(&mut state).unwrap(); + app.delphi_logs_db = Some(pool.clone()); + app.delphi_logs_auth_db = Some(pool); + app.delphi_logs_env = "local".into(); + } + // No bearer token: hybridAuth's 401, before any read (this database + // is unreachable), with or without a job id. + for (target, auth) in [ + (run, None), + ("/api/v3/delphi/logs", None), + ("/api/v3/delphi/logs?job_id=", None), + (run, Some("Basic eDp4")), + (run, Some("bearer x.y.z")), + ] { + let mut headers = vec![host]; + if let Some(a) = auth { + headers.push(("authorization", a)); + } + let out = handle(state.clone(), req(target, &headers)).await; + assert_eq!(out.status, 401, "{target} {auth:?}"); + assert!( + matches!(out.body, Body::Fixed(ref b) if b == br#"{"error":"No authentication token found"}"#) + ); + } + let mut head = req(run, &[host]); + head.method = "HEAD".into(); + // The writer drops a HEAD answer's body on the wire (http.rs). + assert_eq!(handle(state.clone(), head).await.status, 401); + // A token this process cannot verify builds no identity: Node's. + let out = handle( + state.clone(), + req(run, &[host, ("authorization", "Bearer x.y.z")]), + ) + .await; + assert_eq!(out.status, 502); + // Query shapes, bodies and methods the route does not model: Node's. + for target in [ + &format!("{run}&report_id=r"), + &format!("{run}&job_id=00000000-0000-4000-8000-000000000001"), + "/api/v3/delphi/logs?job_id[]=x", + "/api/v3/delphi/logs?jobid=x", + &format!("/api/v3/delphi/logs?job_id={}", "a".repeat(101)), + ] { + assert_eq!( + handle(state.clone(), req(target, &[host])).await.status, + 502, + "{target}" + ); + } + for header in [("content-length", "1"), ("transfer-encoding", "chunked")] { + assert_eq!( + handle(state.clone(), req(run, &[host, header])) + .await + .status, + 502 + ); + } + for method in ["POST", "OPTIONS", "PUT"] { + let mut r = req(run, &[host]); + r.method = method.into(); + assert_eq!(handle(state.clone(), r).await.status, 502, "{method}"); + } + assert_eq!(state.delphi_logs_served.load(Ordering::Relaxed), 6); + assert_eq!(state.delphi_logs_fallback.load(Ordering::Relaxed), 12); + } + #[tokio::test] async fn delphi_run_gate_boundaries_and_refusals_without_database() { let mut state = app(true); let req = |target: &str, headers: &[(&str, &str)]| { diff --git a/queue-rs/polis-contracts/src/delphi_logs.rs b/queue-rs/polis-contracts/src/delphi_logs.rs new file mode 100644 index 000000000..79494e2a2 --- /dev/null +++ b/queue-rs/polis-contracts/src/delphi_logs.rs @@ -0,0 +1,66 @@ +//! Legacy Delphi job logs, preserving the Node response fields and order. +use serde::{Deserialize, Serialize}; +pub const PATH: &str = "/api/v3/delphi/logs"; +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] +#[serde(deny_unknown_fields)] +pub struct Request { + /// `None` when the parameter is absent or empty. + pub job_id: Option, +} +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(rename_all = "lowercase")] +pub enum Status { + Error, +} +/// A refusal after authentication, in the shape of `/delphi/logs`'s. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(deny_unknown_fields)] +pub struct Refusal { + pub status: Status, + pub message: String, +} +/// The refusal of a request without a bearer token, as `hybridAuth` writes it. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(deny_unknown_fields)] +pub struct Unauthenticated { + pub error: String, +} +impl Refusal { + fn new(message: &str) -> Self { + Self { + status: Status::Error, + message: message.into(), + } + } + /// 400: no `job_id`. + pub fn missing() -> Self { + Self::new("job_id is required") + } + /// 404: no such job in this deployment. + pub fn not_found() -> Self { + Self::new("Job not found") + } + /// 403: the caller is not a moderator of the job's conversation. + pub fn denied() -> Self { + Self::new(DENIED) + } +} +impl Unauthenticated { + /// 401: no `Authorization: Bearer` header. + pub fn no_token() -> Self { + Self { + error: "No authentication token found".into(), + } + } +} +/// The 403 code, named for this route as `/delphi/logs` names its own. +pub const DENIED: &str = "polis_err_delphi_logs_auth"; + +/// One authorized log line. Invalid or absent timestamps are omitted by Node. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(deny_unknown_fields)] +pub struct Event { + #[serde(skip_serializing_if = "Option::is_none")] + pub timestamp: Option, + pub message: String, +} diff --git a/queue-rs/polis-contracts/src/lib.rs b/queue-rs/polis-contracts/src/lib.rs index 51a32a042..ae1082282 100644 --- a/queue-rs/polis-contracts/src/lib.rs +++ b/queue-rs/polis-contracts/src/lib.rs @@ -13,6 +13,7 @@ pub mod database; pub mod delphi_input_bundle; pub mod delphi_input_bundle_schema; pub mod delphi_job_result; +pub mod delphi_logs; pub mod delphi_read; pub mod delphi_reports; pub mod delphi_result_read; diff --git a/server/characterization/delphi/main.cjs b/server/characterization/delphi/main.cjs index d8b7788cf..11e3c5935 100644 --- a/server/characterization/delphi/main.cjs +++ b/server/characterization/delphi/main.cjs @@ -273,12 +273,12 @@ function oidcSigner() { // ------------------------------------------------------------------ requests -function request(p, token) { +function request(p, token, port = APP_PORT) { return new Promise((resolve, reject) => { const req = http.request( { host: "127.0.0.1", - port: APP_PORT, + port, path: p, method: "GET", agent: false, @@ -436,6 +436,13 @@ async function main() { return issueAnonymousJWT(m.conversation_id, 9 + pid, pid); }; + // Optional Rust conformance uses the unchanged fixture and recording oracle. + const rust = process.env.P2ZERO_RUST_KEYS + ? await require("../../../queue-rs/polis-api/conformance/delphi-logs-check.cjs").start({ + keys: process.env.P2ZERO_RUST_KEYS, jwks: signer.jwks, + publicKey: pair.publicKey, request, serialize, oidc, + database: pgApp.toString(), + }) : null; const cases = allCases(); const index = { format: FORMAT, @@ -456,6 +463,7 @@ async function main() { const r = await request(c.path, token); statusCounts[r.status] = (statusCounts[r.status] || 0) + 1; const text = serialize(c, r); + if (rust && c.route === "GET /api/v3/delphi/logs") await rust.compare(c, token, text); const file = path.join(RECORDINGS, `${c.id}.json`); index.cases.push({ id: c.id, @@ -493,6 +501,7 @@ async function main() { "index.json differs (case list, fixtures, codec or pins changed)" ); } + if (rust) await rust.finish(); server.close(); stub.server.close(); console.log( From 93f17e290ea207d8dfa54d8dce42f0179f774635 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 13:58:13 -0700 Subject: [PATCH 02/30] polis-api: a typed read route for the Delphi visualizations list, behind its own switch (#3230) Rust read route only, off by default (its own switch plus a RUST_API_ROUTES arm); stacked on the job-log route PR (merge that first; retargeted to edge after). GET /api/v3/delphi/visualizations with the job filter, order, archived and live-work behaviours byte-faithful to Node against the Postgres-mode baseline. When the liveness query fails, the route hands the request back to Node instead of answering with live-work true (the reviewer's required edit, with its test), so a Rust statement timeout can never report a run as live where Node says otherwise. Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- ...elphiVisualizations.location.conf.template | 3 +- polis-cli/tests/differential/routes.json | 2 +- queue-rs/polis-api/README.md | 57 ++-- .../delphi-visualizations-pg-check.cjs | 108 ++++++ .../delphi-visualizations-pg-compose.yml | 69 ++++ .../delphi-visualizations-pg-run.sh | 26 ++ .../polis-api/conformance/nginx-routing.sh | 5 + .../polis-api/src/delphi_visualizations.rs | 320 +++++++++++++++--- .../src/delphi_visualizations_liveness.sql | 31 ++ queue-rs/polis-api/src/main.rs | 15 + queue-rs/polis-api/src/next_comment.rs | 10 + queue-rs/polis-api/src/route.rs | 6 + .../src/delphi_visualizations.rs | 29 ++ server/characterization/delphi/main.cjs | 6 +- 14 files changed, 621 insertions(+), 66 deletions(-) create mode 100644 queue-rs/polis-api/conformance/delphi-visualizations-pg-check.cjs create mode 100644 queue-rs/polis-api/conformance/delphi-visualizations-pg-compose.yml create mode 100755 queue-rs/polis-api/conformance/delphi-visualizations-pg-run.sh create mode 100644 queue-rs/polis-api/src/delphi_visualizations_liveness.sql diff --git a/file-server/nginx/rust-api/delphiVisualizations.location.conf.template b/file-server/nginx/rust-api/delphiVisualizations.location.conf.template index eb3b17b36..51229e483 100644 --- a/file-server/nginx/rust-api/delphiVisualizations.location.conf.template +++ b/file-server/nginx/rust-api/delphiVisualizations.location.conf.template @@ -23,7 +23,8 @@ location = /api/v3/delphi/visualizations { proxy_set_header Host $host; proxy_connect_timeout 100ms; proxy_send_timeout 100ms; - proxy_read_timeout 100ms; + # PostgreSQL job metadata has its own 750 ms request deadline. + proxy_read_timeout 1s; proxy_buffering off; proxy_request_buffering off; } diff --git a/polis-cli/tests/differential/routes.json b/polis-cli/tests/differential/routes.json index f1734bd2a..d5552739f 100644 --- a/polis-cli/tests/differential/routes.json +++ b/polis-cli/tests/differential/routes.json @@ -364,7 +364,7 @@ "delphi status", "delphi visualization view" ], - "scope": "Existing-report visualizations and DynamoDB/S3 results remain Node; only missing/unknown report validation is staged. Raw replay provides positive serving proof." + "scope": "The shared fixture uses DynamoDB, so existing reports and S3 results hand to Node. Dedicated Postgres conformance proves archived/native job metadata, filtering, liveness and serving counts." }, "topicStats": { "path": "/api/v3/topicStats", diff --git a/queue-rs/polis-api/README.md b/queue-rs/polis-api/README.md index 9ba73aab5..7f3deabd9 100644 --- a/queue-rs/polis-api/README.md +++ b/queue-rs/polis-api/README.md @@ -1111,25 +1111,44 @@ Node/Rust byte replay on the generated fixture stack. This slice does not serve narrative reports or claim DynamoDB/provider parity. -### Delphi visualization validation - -`GET`/`HEAD /api/v3/delphi/visualizations` is staged behind `POLIS_API_DELPHI_VISUALIZATIONS_READS=1` -and nginx `RUST_API_ROUTES=delphiVisualizations`, both off by default. Set -`POLIS_API_DELPHI_VISUALIZATIONS_DATABASE_URL` to Node's read replica. Only missing/empty -report IDs (HTTP 400) and absent reports (HTTP 404) are served, using the shared -`polis-contracts::delphi_visualizations` request/response types. Existing reports and -DynamoDB responses remain Node, as do identity, body, duplicate/structured -query, job-filter and unsupported report-ID shapes. Accepted nonempty IDs -are at most 100 ASCII alphanumeric, underscore or hyphen characters. -The uncached report lookup has its own one-slot read-only pool: 15 ms acquire, -50 ms statement and 75 ms caller deadline. It never borrows a participation -pool or holds a connection over a remote service call. Database errors and -contention hand back to Node; cancellation retains the slot until the query -finishes. `delphiVisualizationsServed` and `delphiVisualizationsFallback` count the outcomes. -Run `queue-rs/polis-api/conformance/delphi-visualizations-run.sh result.json` for raw -Node/Rust byte replay on the generated fixture stack. This slice does not -serve visualizations or claim DynamoDB/S3/provider parity. - +### Delphi visualization jobs + +`GET`/`HEAD /api/v3/delphi/visualizations` remains behind +`POLIS_API_DELPHI_VISUALIZATIONS_READS=1` and nginx +`RUST_API_ROUTES=delphiVisualizations`, both off by default. The existing +`POLIS_API_DELPHI_VISUALIZATIONS_DATABASE_URL` pool resolves reports (one slot, +15 ms acquire, 50 ms statement). Without the Postgres result backend, only +missing/unknown report validation is served and its 75 ms deadline is unchanged; +existing reports, credentials and S3 work stay with Node. + +With `DELPHI_RESULT_BACKEND=postgres`, set `DELPHI_RESULT_ENV`, the same optional +`DELPHI_RESULT_SCOPE` as Node, and the primary +`POLIS_API_DELPHI_VISUALIZATIONS_RESULTS_DATABASE_URL`. Its independent read-only +pool has two slots, 15 ms acquisition and 200 ms statement bounds. It reads the +existing job views/controls and the same native graph/attempt/provider liveness +relations as Node; use the existing Node read login's access, without new grants. +The whole metadata request is bounded at 750 ms; nginx waits up to 1 second. +No participation connection or lock is shared. + +The public response keeps `status`, `report_id`, `visualizations: []` and Node's +job fields/order. Native rows hide archived copies, current native liveness is +read separately after the result snapshot, and `job_id` filters the completed +metadata list. This does not invent a static visualization artifact contract. +The first result snapshot must fit a conservative single-page bound (512 KiB, +1,000 jobs); larger listings, unsupported legacy coercions and unavailable reads +hand back to Node, without a partial list, and so does a liveness sweep that +cannot finish within these bounds. `delphiVisualizationsServed` and +`delphiVisualizationsFallback` count outcomes. + +`queue-rs/polis-api/conformance/delphi-visualizations-pg-run.sh result.json` +replays the unchanged Postgres baseline and compares native jobs, filters and +terminal liveness. Set unique `COMPOSE_PROJECT_NAME`, `POLIS_RECOVERY_PG_PORT`, +and the local `DELPHI_VISUALIZATIONS_PG_NODE_IMAGE`, +`DELPHI_VISUALIZATIONS_PG_POSTGRES_IMAGE`, and +`DELPHI_VISUALIZATIONS_PG_API_IMAGE` (fixture-clock) images. The shared CLI +DynamoDB differential still proves existing-report handoffs; the dedicated +Postgres run provides serving proof. No Node handler, schema, writer or +production switch changes. ### Topic statistics validation diff --git a/queue-rs/polis-api/conformance/delphi-visualizations-pg-check.cjs b/queue-rs/polis-api/conformance/delphi-visualizations-pg-check.cjs new file mode 100644 index 000000000..8bc4ddd21 --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-visualizations-pg-check.cjs @@ -0,0 +1,108 @@ +"use strict"; +const fs = require("node:fs"); +const path = require("node:path"); +exports.start = async function({keys,jwks,publicKey,request,serialize,oidc,database}) { + const {createRequire}=require("node:module"); + const {Client}=createRequire(path.resolve(process.cwd(),"package.json"))("pg"); + const permissions=new Client({connectionString:database});await permissions.connect(); + await permissions.query("CREATE ROLE generated_logs_reader LOGIN; GRANT polis_queue_executor TO generated_logs_reader"); + await permissions.query("CREATE ROLE generated_viz_reader LOGIN; GRANT SELECT ON ALL TABLES IN SCHEMA public TO generated_viz_reader"); + await permissions.end(); + fs.mkdirSync(keys,{recursive:true}); + fs.writeFileSync(path.join(keys,"jwks.json"),JSON.stringify(jwks)); + fs.writeFileSync(path.join(keys,"participant.pem"),publicKey); + fs.writeFileSync(path.join(keys,"ready"),"ready\n"); + const port=Number(process.env.P2ZERO_RUST_PORT||5100); + let ready=false; + for(let i=0;i<120;i++) { + try { const r=await request("/health",null,port); if(r.status===200){ready=true;break;} } catch {} + await new Promise(resolve=>setTimeout(resolve,250)); + } + if(!ready) throw Error("Rust visualization readiness deadline"); + const captures=[]; + const handoffs=[]; + return { + matches(c) { return ["GET /api/v3/delphi/logs", "GET /api/v3/delphi/visualizations"].includes(c.route); }, + async compare(c,token,node) { + const r=await request(c.path,token,port); + const rust=serialize(c,r); + captures.push({case:c.id,node:JSON.parse(node),rust:JSON.parse(rust),equal:node===rust}); + }, + async finish() { + // Native rows and attempts use the release SQL, after the baseline reads. + // No worker or model runs, and no vote is inserted by this fixture. + const {createRequire}=require("node:module"); + const {Client}=createRequire(path.resolve(process.cwd(),"package.json"))("pg"); + const db=new Client({connectionString:database}); await db.connect(); + const owner=oidc("p2zero|owner","owner@example.invalid"); + const other=oidc("p2zero|other","other@example.invalid"); + async function check(id,query,token,status,verify) { + const c={id:`supplemental/${id}`,state:"supplemental",route:"GET "+query.split("?")[0],path:query,auth:token===owner?"owner":token===other?"other":token?"moderator":"none"}; + const n=await request(query,token);const r=await request(query,token,port); + const node=serialize(c,n),rust=serialize(c,r); + if(n.status!==status) throw Error(`${id}: fixture Node status ${n.status}, want ${status}`); + if(verify)verify(JSON.parse(n.body)); + captures.push({case:c.id,node:JSON.parse(node),rust:JSON.parse(rust),equal:node===rust}); + } + const job="00000000-0000-4000-8000-00000000f001"; + const run="00000000-0000-4000-8000-00000000f002"; + const attempt="00000000-0000-4000-8000-00000000f003"; + const worker="00000000-0000-4000-8000-00000000f004"; + const query=`/api/v3/delphi/logs?job_id=${job}`; + await db.query("SELECT pd_writer_admit('p2zero',105,'delphi','generated-logs','native-logs',repeat('a',64),$1,$2,'delphi_full_pipeline',NULL,'{}',repeat('b',40))",[job,run]); + await check("native-no-attempt",query,owner,200,b=>{if(b.length)throw Error("expected no attempt logs");}); + const q=(await db.query("SELECT priority,worker_class FROM polis_queue_jobs WHERE env='p2zero' AND job_id=$1",[job])).rows[0]; + const claim=(await db.query("SELECT pq_claim('p2zero',$1::smallint,$2::uuid,$3::uuid,900,$4::text) AS claim",[q.priority,worker,attempt,q.worker_class])).rows[0].claim; + if(claim.job_id!==job)throw Error("native claim was not the generated job"); + await db.query(`INSERT INTO polis_queue_logs(env,attempt_id,seq,ts,stream,line) VALUES + ('p2zero',$1,1,'2023-11-14T20:21:00.123456Z','stdout','generated stdout'), + ('p2zero',$1,2,'2023-11-14T20:21:01Z','manifest','{}'), + ('p2zero',$1,3,'2023-11-14T20:21:02.999999Z','stderr','generated stderr'), + ('p2zero',$1,4,'2023-11-14T20:21:03Z','truncated','generated truncation')`,[attempt]); + await check("native-streams",query,owner,200,b=>{if(b.length!==2||b[0].timestamp!==1699993260123||!b[1].message.includes("ERROR: generated stderr"))throw Error("native stream fixture");}); + await check("native-foreign-owner",query,other,403); + await check("native-no-token",query,null,401); + await check("missing-job-id","/api/v3/delphi/logs",owner,400); + // Limit is applied before stdout/stderr filtering, not after it. + await db.query("INSERT INTO polis_queue_logs(env,attempt_id,seq,ts,stream,line) SELECT 'p2zero',$1,i,'2023-11-14T20:21:04Z','manifest','{}' FROM generate_series(5,1000) i",[attempt]); + await db.query("INSERT INTO polis_queue_logs(env,attempt_id,seq,ts,stream,line) VALUES('p2zero',$1,1001,'2023-11-14T20:21:05Z','stdout','must not appear')",[attempt]); + await check("native-limit-before-filter",query,owner,200,b=>{if(b.length!==2)throw Error("first 1000 then filter");}); + await db.query("INSERT INTO oidc_user_mappings(oidc_sub,uid) VALUES('p2zero|admin',2)"); + await check("native-admin",query,oidc("p2zero|admin","admin@example.invalid"),200); + await db.query("INSERT INTO users(uid,hname,email,is_owner,site_id) VALUES(200,'Generated Site Moderator','sitemod@example.invalid',true,'p2zero-owner'); INSERT INTO oidc_user_mappings(oidc_sub,uid) VALUES('p2zero|sitemod',200)"); + await check("native-site-moderator",query,oidc("p2zero|sitemod","sitemod@example.invalid"),200); + const archived="00000068-0000-4000-8000-000000000001"; + await db.query("SELECT pd_writer_admit('p2zero',104,'delphi','generated-logs','archive-precedence',repeat('c',64),$1,gen_random_uuid(),'delphi_full_pipeline',NULL,'{}',repeat('b',40))",[archived]); + await check("active-row-hides-archive",`/api/v3/delphi/logs?job_id=${archived}`,owner,200,b=>{if(b.length)throw Error("active row did not hide historical logs");}); + const viz="/api/v3/delphi/visualizations?report_id=r2p2zero105"; + await check("visualizations-native-and-archive",viz,null,200,b=>{if(!b.jobs.some(j=>j.jobId===job&&j.workLive===true)||!b.jobs.some(j=>j.archived===true&&j.workLive===false))throw Error("mixed jobs fixture");}); + await check("visualizations-native-filter",`${viz}&job_id=${job}`,null,200,b=>{if(b.jobs.length!==1||b.jobs[0].jobId!==job)throw Error("job filter");}); + await check("visualizations-unknown-filter",`${viz}&job_id=generated-unknown-job`,null,200,b=>{if(b.jobs.length)throw Error("unknown job filter");}); + await check("visualizations-authorization-is-ignored",viz,other,200); + await db.query("SELECT pq_fail('p2zero',$1::uuid,$2::uuid,$3::uuid,$4::bigint,true,'stage_failed',true)",[job,worker,attempt,claim.lease_epoch]); + await check("visualizations-terminal-confirmed",`${viz}&job_id=${job}`,null,200,b=>{if(b.jobs.length!==1||b.jobs[0].workLive!==false||b.jobs[0].status!=="FAILED")throw Error("terminal job fixture");}); + await db.query("UPDATE polis_queue_logs SET line=repeat('x',600000) WHERE env='p2zero' AND attempt_id=$1 AND seq IN (1,3)",[attempt]); + const oversized=await request(query,owner,port); + const nodeOversized=await request(query,owner); + if(oversized.status!==502||nodeOversized.status!==200||nodeOversized.body.length<=1024*1024)throw Error("native input cap does not hand back complete logs"); + handoffs.push({case:"native-input-cap",rustStatus:oversized.status,nodeStatus:nodeOversized.status,nodeBytes:nodeOversized.body.length}); + // Only the later liveness statement needs this table. Force that + // statement to fail while the initial metadata snapshot still succeeds. + await db.query("REVOKE SELECT ON public.delphi_provider_requests FROM generated_viz_reader"); + const liveNode=await request(`${viz}&job_id=${job}`,null); + const liveRust=await request(`${viz}&job_id=${job}`,null,port); + const livenessFailure={case:"liveness-query-failure",nodeStatus:liveNode.status,rustStatus:liveRust.status,nodeBody:JSON.parse(liveNode.body),rustBody:liveRust.body}; + fs.writeFileSync(path.join(keys,"liveness-failure.json"),JSON.stringify(livenessFailure,null,2)+"\n"); + await db.query("GRANT SELECT ON public.delphi_provider_requests TO generated_viz_reader"); + if(liveNode.status!==200||livenessFailure.nodeBody.jobs[0].workLive!==false||liveRust.status!==502)throw Error(`liveness failure must hand back to Node: Node ${liveNode.status}, Rust ${liveRust.status}`); + handoffs.push(livenessFailure); + await db.end(); + const health=await request("/health",null,port); + const counters=JSON.parse(health.body); + const failures=captures.filter(c=>!c.equal); + fs.writeFileSync(path.join(keys,"results.json"),JSON.stringify({cases:captures.length,equal:captures.length-failures.length,failures:failures.length,counters,captures,handoffs},null,2)+"\n"); + console.log(`Rust logs and visualizations: ${captures.length} cases, ${failures.length} differences`); + if(failures.length) throw Error(`Rust visualization byte differences: ${failures.map(c=>c.case).join(", ")}`); + } + }; +}; diff --git a/queue-rs/polis-api/conformance/delphi-visualizations-pg-compose.yml b/queue-rs/polis-api/conformance/delphi-visualizations-pg-compose.yml new file mode 100644 index 000000000..519502f0a --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-visualizations-pg-compose.yml @@ -0,0 +1,69 @@ +services: + postgres: + image: ${DELPHI_VISUALIZATIONS_PG_POSTGRES_IMAGE:?set a fixture Postgres image} + environment: {POSTGRES_HOST_AUTH_METHOD: trust} + ports: ["127.0.0.1:${POLIS_RECOVERY_PG_PORT:?set a unique port}:5432"] + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 2s + timeout: 2s + retries: 30 + dynamodb: + image: amazon/dynamodb-local:3.3.1@sha256:ff89bd48ff32cd8d9be5fee8873b65b8854dc408f1afe881be6eb00247bc0dab + command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-inMemory"] + recorder: + image: ${DELPHI_VISUALIZATIONS_PG_NODE_IMAGE:?set a Node image} + working_dir: /app + entrypoint: [sh, -c] + command: ["cp -a /candidate/. /app/; exec node characterization/delphi/main.cjs replay"] + volumes: + - ${DELPHI_VISUALIZATIONS_PG_SOURCE}/server:/candidate:ro + - ${DELPHI_VISUALIZATIONS_PG_SOURCE}/delphi:/delphi + - ${DELPHI_VISUALIZATIONS_PG_SOURCE}/queue-rs:/queue-rs:ro + - ${DELPHI_VISUALIZATIONS_PG_SCRATCH}:/proof + environment: + P2ZERO_PG_ADMIN_URL: postgres://postgres@postgres:5432/postgres + DYNAMODB_ENDPOINT: http://dynamodb:8000 + DELPHI_RESULT_BACKEND: postgres + P2ZERO_RUST_KEYS: /proof + P2ZERO_RUST_CHECK: visualizations + TZ: UTC + depends_on: + postgres: {condition: service_healthy} + dynamodb: {condition: service_started} + polis-api: + image: ${DELPHI_VISUALIZATIONS_PG_API_IMAGE:?set a fixture-clock API image} + network_mode: service:recorder + entrypoint: [sh, -c] + command: ["while [ ! -f /proof/ready ]; do sleep 1; done; exec /usr/local/bin/polis-api"] + volumes: ["${DELPHI_VISUALIZATIONS_PG_SCRATCH}:/proof:ro"] + environment: + DATABASE_URL: postgres://postgres@postgres:5432/p2zero + DATABASE_SSL: 'false' + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + MATH_ENV: p2zero + DEV_MODE: 'true' + POLIS_API_DELPHI_LOGS_DATABASE_URL: postgres://generated_logs_reader@postgres:5432/p2zero + POLIS_API_DELPHI_LOGS_AUTH_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_LOGS_READS: '1' + POLIS_API_DELPHI_VISUALIZATIONS_READS: '1' + POLIS_API_DELPHI_VISUALIZATIONS_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_VISUALIZATIONS_RESULTS_DATABASE_URL: postgres://generated_viz_reader@postgres:5432/p2zero + DELPHI_RESULT_BACKEND: postgres + DELPHI_RESULT_ENV: p2zero + DELPHI_RESULT_SCOPE: delphi + POLIS_API_READ_JWKS_FILE: /proof/jwks.json + POLIS_API_PARTICIPANT_READS: '1' + POLIS_API_PARTICIPANT_PUBLIC_KEY_FILE: /proof/participant.pem + POLIS_API_FIXTURE_CLOCK: '1700000000000' + AUTH_ISSUER: https://oidc.p2zero.invalid/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ + POLIS_JWT_ISSUER: https://pol.is/ + POLIS_JWT_AUDIENCE: participants + ADMIN_UIDS: '[2]' + DOMAIN_OVERRIDE: localhost + SERVICE_URL: http://localhost + NODE_ENV: production + TZ: UTC diff --git a/queue-rs/polis-api/conformance/delphi-visualizations-pg-run.sh b/queue-rs/polis-api/conformance/delphi-visualizations-pg-run.sh new file mode 100755 index 000000000..e95f3a45b --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-visualizations-pg-run.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Postgres baseline and native visualization job metadata; all services are disposable fixtures. +# Requires three local images (Node, migration Postgres, fixture-clock polis-api). +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:?provide a results JSON path} +: "${COMPOSE_PROJECT_NAME:?set a unique project}" +: "${POLIS_RECOVERY_PG_PORT:?set a unique port}" +export RECOVERY_PG_PORT="$POLIS_RECOVERY_PG_PORT" +export DELPHI_VISUALIZATIONS_PG_SOURCE="$root" +export DELPHI_VISUALIZATIONS_PG_SCRATCH=${DELPHI_VISUALIZATIONS_PG_SCRATCH:-$(mktemp -d)} +mkdir -p "$DELPHI_VISUALIZATIONS_PG_SCRATCH" +[[ -z $(ls -A "$DELPHI_VISUALIZATIONS_PG_SCRATCH") ]] || { echo "scratch must be empty" >&2; exit 2; } +compose=(docker compose -f "$root/queue-rs/polis-api/conformance/delphi-visualizations-pg-compose.yml") +[[ -z $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]] || { echo "project already exists" >&2; exit 2; } +cleanup() { + "${compose[@]}" logs --no-color >"${out%.json}-services.log" 2>&1 || true + "${compose[@]}" down -v --remove-orphans >/dev/null 2>&1 || true +} +trap cleanup EXIT INT TERM +"${compose[@]}" up -d --pull never postgres dynamodb recorder polis-api +cid=$("${compose[@]}" ps -aq recorder) +result=$(docker wait "$cid") +"${compose[@]}" logs --no-color recorder +docker cp "$cid:/proof/results.json" "$out" +exit "$result" diff --git a/queue-rs/polis-api/conformance/nginx-routing.sh b/queue-rs/polis-api/conformance/nginx-routing.sh index 3a3ef9e78..fb0e61f16 100755 --- a/queue-rs/polis-api/conformance/nginx-routing.sh +++ b/queue-rs/polis-api/conformance/nginx-routing.sh @@ -1115,6 +1115,11 @@ docker rm -f "$p-rust" >/dev/null stub "$p-rust" polis-api 5100 502 "handoff" sleep 6 expect /api/v3/delphi/visualizations node "Delphi visualization validation handoff" +# Query filters and arbitrary Authorization stay intact on this public route. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start delphiVisualizations +expect_upstream polis-api GET '/api/v3/delphi/visualizations?report_id=r&job_id=generated-job' $'Authorization: Bearer generated\r\n' echo "ok 53 Delphi visualization validation off/on/deduplicated; method/body guards; 502 hands back to Node" docker rm -f "$p-rust" >/dev/null diff --git a/queue-rs/polis-api/src/delphi_visualizations.rs b/queue-rs/polis-api/src/delphi_visualizations.rs index f5ce2349d..f38967bdf 100644 --- a/queue-rs/polis-api/src/delphi_visualizations.rs +++ b/queue-rs/polis-api/src/delphi_visualizations.rs @@ -1,33 +1,46 @@ -//! Missing/unknown report validation only, on a separate bounded replica pool. +//! Legacy visualization validation and PostgreSQL job metadata. Dedicated +//! bounded pools; DynamoDB/S3 results and unsupported metadata stay with Node. use crate::{ http::{Outgoing, Request}, route::{self, App, Res}, }; -// Both workspaces compile the same shared contract module. +use anyhow::{Result, ensure}; +use postgres::{Client, IsolationLevel}; +use serde_json::Value; +use std::collections::{BTreeMap, BTreeSet}; #[path = "../../polis-contracts/src/delphi_visualizations.rs"] mod contract; pub use contract::PATH; -pub fn parse(app: &App, req: &Request) -> Option { +pub struct Parsed { + report_id: Option, + job_id: Option, +} +pub fn parse(app: &App, req: &Request) -> Option { if app.delphi_visualizations_db.is_none() || req.path() != PATH || !matches!(req.method.as_str(), "GET" | "HEAD") || !req.body.is_empty() || req.headers.get("transfer-encoding").is_some() || req.headers.get("content-length").is_some_and(|s| s != "0") - || req.headers.get("authorization").is_some() - || req.headers.get("cookie").is_some() { return None; } + // Node does not authenticate this public report route. Preserve the old + // validation-only admission when PostgreSQL result reads are not configured. + let pg = app.delphi_visualizations_result_db.is_some(); + if !pg && (req.headers.get("authorization").is_some() || req.headers.get("cookie").is_some()) { + return None; + } let raw = req.query().unwrap_or(""); if raw.len() > 1024 { return None; } let mut report_id = None; - let mut seen = false; + let mut job_id = None; + let mut seen = BTreeSet::new(); for (k, v) in url::form_urlencoded::parse(raw.as_bytes()) { - if k != "report_id" - || seen + if (k != "report_id" && (!pg || k != "job_id")) + || !seen.insert(k.clone()) || v.len() > 100 || !v .bytes() @@ -35,12 +48,15 @@ pub fn parse(app: &App, req: &Request) -> Option { { return None; } - seen = true; if !v.is_empty() { - report_id = Some(v.into_owned()); + if k == "report_id" { + report_id = Some(v.into_owned()); + } else { + job_id = Some(v.into_owned()); + } } } - Some(contract::Request { report_id }) + Some(Parsed { report_id, job_id }) } pub fn pool_limits() -> crate::db::Limits { crate::db::Limits { @@ -50,43 +66,261 @@ pub fn pool_limits() -> crate::db::Limits { max_lifetime: std::time::Duration::from_secs(300), } } +pub fn result_pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 2, + statement_timeout: std::time::Duration::from_millis(200), + ..pool_limits() + } +} pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { let Some(query) = parse(app, req) else { return route::bad_gateway(); }; - let status = if query.report_id.is_some() { 404 } else { 400 }; - let value = match query.report_id { - None => contract::Request::missing(), - Some(id) => { - let Some(pool) = &app.delphi_visualizations_db else { - return route::bad_gateway(); - }; - let report_id = id.clone(); - // The Node resolver is uncached. Only absence qualifies: every existing - // report (including unusual/null/zero identifiers) stays with Node. - let Ok(Ok(false)) = tokio::time::timeout( - std::time::Duration::from_millis(75), - pool.with(move |c| { - Ok(!c - .query( - "SELECT zid FROM reports WHERE report_id=$1 LIMIT 1", - &[&report_id], - )? - .is_empty()) - }), - ) - .await - else { - return route::bad_gateway(); - }; - contract::Request::unknown(id) - } - }; - let Ok(encoded) = serde_json::to_string(&value) else { + let Ok(Some((status, body))) = tokio::time::timeout( + std::time::Duration::from_millis(if app.delphi_visualizations_result_db.is_some() { + 750 + } else { + 75 + }), + answer(app, query), + ) + .await + else { return route::bad_gateway(); }; - let Ok(value) = crate::js::parse(&encoded) else { - return route::bad_gateway(); + route::json_text(req, res, status, body) +} +async fn answer(app: &App, query: Parsed) -> Option<(u16, String)> { + let Some(id) = query.report_id else { + return Some(( + 400, + crate::wire::to_json(&contract::Request::missing()).ok()?, + )); }; - route::json_status(req, res, status, &value) + let lookup = id.clone(); + let zid = app + .delphi_visualizations_db + .as_ref()? + .with(move |c| { + Ok(c.query_opt( + "SELECT zid FROM reports WHERE report_id=$1 LIMIT 1", + &[&lookup], + )? + .map(|r| r.try_get::<_, Option>(0)) + .transpose()?) + }) + .await + .ok()?; + if zid.is_some() && app.delphi_visualizations_result_db.is_none() { + return None; + } + let zid = zid.flatten(); + let Some(zid) = zid.filter(|z| *z != 0) else { + return Some(( + 404, + crate::wire::to_json(&contract::Request::unknown(id)).ok()?, + )); + }; + let pool = app.delphi_visualizations_result_db.as_ref()?; + let env = app.delphi_visualizations_env.clone(); + let scope = app.delphi_visualizations_scope.clone(); + let mut jobs = pool + .with(move |c| read(c, &env, scope.as_deref(), zid)) + .await + .ok()?; + if let Some(job) = query.job_id { + jobs.retain(|j| j.job_id == job); + } + let body = crate::wire::to_json(&contract::JobsResponse { + status: contract::Success::Success, + report_id: id, + visualizations: Vec::new(), + jobs, + }) + .ok()?; + if body.len() > 1024 * 1024 { + return None; + } + Some((200, body)) +} +#[derive(Clone)] +struct Item { + id: String, + created: Option, + job: contract::Job, +} +fn string_field(tag: &Value, name: &str) -> Result> { + match tag.get(name) { + None => Ok(None), + Some(v) if v.get("NULL") == Some(&Value::Bool(true)) => Ok(None), + Some(v) => Ok(Some( + v.get("S") + .and_then(Value::as_str) + .ok_or_else(|| anyhow::anyhow!("unsupported metadata scalar"))? + .to_owned(), + )), + } +} +fn nonempty(s: Option) -> Option { + s.filter(|s| !s.is_empty()) +} +fn safe_id(id: &str) -> bool { + !id.is_empty() + && id.len() <= 100 + && id + .bytes() + .all(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'-') + && !matches!(id, "__proto__" | "constructor" | "prototype") + && crate::js::array_index(id).is_none() +} +fn archived(tag: &Value) -> Result { + let id = string_field(tag, "job_id")?.ok_or_else(|| anyhow::anyhow!("missing job id"))?; + ensure!(safe_id(&id), "unsupported job id"); + let created = string_field(tag, "created_at")?; + ensure!( + created.as_ref().is_none_or(|s| s.is_ascii()), + "unsupported metadata ordering" + ); + let results = match string_field(tag, "job_results")? { + Some(s) if !s.is_empty() => { + ensure!( + !s.to_ascii_lowercase().contains("\\ud"), + "unsupported surrogate escape" + ); + match crate::js::parse(&s) { + Ok(v) => serde_json::from_str(&crate::js::stringify(&v))?, + Err(_) => crate::wire::Json::Null, + } + } + _ => crate::wire::Json::Null, + }; + Ok(Item { + id: id.clone(), + created: created.clone(), + job: contract::Job { + job_id: id, + status: nonempty(string_field(tag, "status")?).unwrap_or_else(|| "unknown".into()), + created_at: nonempty(created), + started_at: nonempty(string_field(tag, "started_at")?), + completed_at: nonempty(string_field(tag, "completed_at")?), + results, + archived: Some(true), + work_live: false, + }, + }) +} +fn native(row: &postgres::Row) -> Result { + let id: String = row.try_get("job_id")?; + ensure!(safe_id(&id), "unsupported job id"); + let created: Option = row.try_get("created_at")?; + Ok(Item { + id: id.clone(), + created: created.clone(), + job: contract::Job { + job_id: id, + status: row.try_get("status")?, + created_at: nonempty(created), + started_at: None, + completed_at: nonempty(row.try_get("completed_at")?), + results: crate::wire::Json::Null, + archived: None, + work_live: true, + }, + }) +} +fn read(c: &mut Client, env: &str, scope: Option<&str>, zid: i32) -> Result> { + // Conservative one-page bound: never collapse Node's multi-snapshot paging + // into one snapshot. Larger listings go to Node, without partial results. + ensure!( + (1..=999999999).contains(&zid), + "unsupported archive conversation range" + ); + let conversation = zid.to_string(); + let mut tx = c + .build_transaction() + .isolation_level(IsolationLevel::RepeatableRead) + .read_only(true) + .start()?; + let bytes:i64=tx.query_one("SELECT coalesce((SELECT sum(octet_length(codec_wire)) FROM public.delphi_result_legacy_controls WHERE env=$1 AND family='Delphi_JobQueue' AND zid=$3 AND ($2::text IS NULL OR scope_key=$2)),0)::bigint + coalesce((SELECT sum(octet_length(row_to_json(v)::text)) FROM public.delphi_result_jobs v WHERE env=$1 AND conversation_id=$4 AND ($2::text IS NULL OR scope_key=$2)),0)::bigint",&[&env,&scope,&zid,&conversation])?.try_get(0)?; + ensure!(bytes <= 512 * 1024, "single-page metadata bound"); + let rows=tx.query("SELECT job_id,conversation_id,report_id,status,job_type,job_config,created_at,completed_at,error,env,scope_key FROM public.delphi_result_jobs WHERE env=$1 AND conversation_id=$3 AND ($2::text IS NULL OR scope_key=$2)",&[&env,&scope,&conversation])?; + ensure!(rows.len() <= 1000, "job count bound"); + let active = rows + .iter() + .map(|r| r.try_get::<_, String>("job_id")) + .collect::, _>>()?; + let mut seen = BTreeMap::::new(); + let mut items = Vec::new(); + for row in tx.query("SELECT codec_wire FROM public.delphi_result_legacy_controls WHERE env=$1 AND family='Delphi_JobQueue' AND zid=$3 AND ($2::text IS NULL OR scope_key=$2) ORDER BY zid,scope_key",&[&env,&scope,&zid])?{ + let wire:String=row.try_get(0)?;let mut lines=wire.lines();let header:Value=serde_json::from_str(lines.next().unwrap_or(""))?; + ensure!(header["codec"]=="delphi-storage-codec/1"&&header["family"]=="Delphi_JobQueue","archive family"); + for line in lines{ + let tag:Value=serde_json::from_str(line)?;let id=tag["job_id"]["S"].as_str().ok_or_else(||anyhow::anyhow!("unsupported archive job id"))?; + if active.contains(id){continue;} + if let Some(old)=seen.insert(id.to_owned(),tag.clone()){ensure!(old==tag,"ambiguous archived job");continue;} + if tag["conversation_id"]["S"].as_str()!=Some(conversation.as_str()){continue;} + let item=archived(&tag)?;if item.created.is_some(){items.push(item);} + } + } + for row in &rows { + let item = native(row)?; + if item.created.is_some() { + items.push(item); + } + } + ensure!(items.len() <= 1000, "job count bound"); + items.sort_by(|a, b| a.created.cmp(&b.created).then_with(|| a.id.cmp(&b.id))); + tx.rollback()?; + // Node performs liveness after the result adapter's snapshot. Preserve + // that boundary. A sweep this bounded pool cannot finish is Node's to + // answer: Node's own sweep may succeed and report a job finished. + let rows = c.query( + include_str!("delphi_visualizations_liveness.sql"), + &[&env, &conversation, &scope], + )?; + ensure!(rows.len() <= 1000, "liveness job count bound"); + let mut live = BTreeMap::new(); + let mut fresh = Vec::new(); + for row in rows { + let item = native(&row)?; + live.insert(item.id.clone(), row.try_get::<_, bool>("work_live")?); + fresh.push(item); + } + let mut ids = BTreeSet::new(); + let mut jobs = Vec::new(); + for mut item in items { + if item.job.archived.is_none() { + item.job.work_live = live.get(&item.id).copied().unwrap_or(true); + } + ids.insert(item.id); + jobs.push(item.job); + } + for mut item in fresh { + if ids.insert(item.id.clone()) { + item.job.work_live = live.get(&item.id).copied().unwrap_or(true); + jobs.push(item.job); + } + } + Ok(jobs) +} +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn metadata_fields_and_result_property_order_match_node() { + let tag = serde_json::json!({"job_id":{"S":"job-a"},"created_at":{"S":""},"job_results":{"S":"{\"z\":1,\"a\":2}"},"status":{"S":""}}); + assert_eq!( + crate::wire::to_json(&archived(&tag).unwrap().job).unwrap(), + r#"{"jobId":"job-a","status":"unknown","createdAt":null,"startedAt":null,"completedAt":null,"results":{"z":1,"a":2},"archived":true,"workLive":false}"# + ); + } + #[test] + fn unsafe_identifiers_and_unmodelled_scalar_coercions_hand_back() { + for id in ["__proto__", "constructor", "0", "4294967294", ""] { + assert!(!safe_id(id)); + } + assert!(safe_id("batch_report_generated")); + assert!(archived(&serde_json::json!({"job_id":{"S":"job-a"},"status":{"N":"1"}})).is_err()); + } } diff --git a/queue-rs/polis-api/src/delphi_visualizations_liveness.sql b/queue-rs/polis-api/src/delphi_visualizations_liveness.sql new file mode 100644 index 000000000..ad96065cd --- /dev/null +++ b/queue-rs/polis-api/src/delphi_visualizations_liveness.sql @@ -0,0 +1,31 @@ +WITH RECURSIVE selected AS ( + SELECT j.*, n.graph_id FROM public.delphi_jobs j + LEFT JOIN public.delphi_graph_nodes n USING (env,job_id) + LEFT JOIN public.delphi_graphs g ON g.env=n.env AND g.graph_id=n.graph_id + WHERE j.env=$1 AND j.zid::text=$2 AND ($3::text IS NULL OR g.scope_key=$3) + ), related(root_id,job_id) AS ( + SELECT s.job_id,s.job_id FROM selected s + UNION + SELECT r.root_id,c.job_id FROM related r + JOIN public.delphi_jobs c ON c.env=$1 AND c.parent_job_id=r.job_id + ), work AS ( + SELECT root_id,job_id FROM related + UNION + SELECT s.job_id,n.job_id FROM selected s + JOIN public.delphi_graph_nodes n ON n.env=s.env AND n.graph_id=s.graph_id + ) + SELECT v.job_id,v.status,v.created_at,v.completed_at, EXISTS ( + SELECT 1 FROM work w + JOIN public.delphi_jobs j ON j.env=$1 AND j.job_id=w.job_id + LEFT JOIN public.polis_queue_jobs q ON q.env=j.env AND q.job_id=j.job_id + WHERE w.root_id=s.job_id AND ( + COALESCE(q.state,j.status) NOT IN ('succeeded','dead','cancelled') + OR EXISTS (SELECT 1 FROM public.polis_queue_attempts a + WHERE a.env=j.env AND a.job_id=j.job_id AND a.process_exit_confirmed_at IS NULL) + OR EXISTS (SELECT 1 FROM public.delphi_provider_requests p + WHERE p.env=j.env AND p.job_id=j.job_id + AND p.state IN ('intent','submission_unknown','submitted')) + ) + ) AS work_live + FROM selected s JOIN public.delphi_result_jobs v ON v.env=s.env AND v.job_id=s.job_id::text + ORDER BY v.job_id LIMIT 1001 diff --git a/queue-rs/polis-api/src/main.rs b/queue-rs/polis-api/src/main.rs index a13b80aa8..7df9b4c50 100644 --- a/queue-rs/polis-api/src/main.rs +++ b/queue-rs/polis-api/src/main.rs @@ -744,6 +744,21 @@ async fn main() -> Result<()> { config::connector_for_dsn(&dsn, "polis-api-delphi-visualizations/1")?, delphi_visualizations::pool_limits(), )); + if std::env::var("DELPHI_RESULT_BACKEND").ok().as_deref() == Some("postgres") { + state.delphi_visualizations_env = std::env::var("DELPHI_RESULT_ENV") + .ok() + .filter(|s| !s.is_empty()) + .context("DELPHI_RESULT_ENV is required for visualization jobs")?; + state.delphi_visualizations_scope = std::env::var("DELPHI_RESULT_SCOPE") + .ok() + .filter(|s| !s.is_empty()); + let results = std::env::var("POLIS_API_DELPHI_VISUALIZATIONS_RESULTS_DATABASE_URL") + .context("a primary result database is required for visualization jobs")?; + state.delphi_visualizations_result_db = Some(db::Pool::new( + config::connector_for_dsn(&results, "polis-api-delphi-visualizations-results/1")?, + delphi_visualizations::result_pool_limits(), + )); + } } if std::env::var("POLIS_API_TOPIC_STATS_READS").ok().as_deref() == Some("1") { let dsn = std::env::var("POLIS_API_TOPIC_STATS_DATABASE_URL").context( diff --git a/queue-rs/polis-api/src/next_comment.rs b/queue-rs/polis-api/src/next_comment.rs index 7989ff75c..37884833a 100644 --- a/queue-rs/polis-api/src/next_comment.rs +++ b/queue-rs/polis-api/src/next_comment.rs @@ -573,6 +573,14 @@ mod tests { Connector::Plain(Box::new(pg.clone())), crate::delphi_logs::auth_pool_limits(), )); + app.delphi_visualizations_db = Some(db::Pool::new( + Connector::Plain(Box::new(pg.clone())), + crate::delphi_visualizations::pool_limits(), + )); + app.delphi_visualizations_result_db = Some(db::Pool::new( + Connector::Plain(Box::new(pg.clone())), + crate::delphi_visualizations::result_pool_limits(), + )); let app = Arc::new(app); async fn park( pool: Arc, @@ -678,6 +686,7 @@ mod tests { app.comments_count_db.as_ref().unwrap(), app.delphi_result_db.as_ref().unwrap(), app.delphi_logs_db.as_ref().unwrap(), + app.delphi_visualizations_result_db.as_ref().unwrap(), ] { for _ in 0..2 { held.push(park(pool.clone()).await); @@ -688,6 +697,7 @@ mod tests { held.push(park(app.statement_importance_db.as_ref().unwrap().clone()).await); } held.push(park(app.delphi_logs_auth_db.as_ref().unwrap().clone()).await); + held.push(park(app.delphi_visualizations_db.as_ref().unwrap().clone()).await); let guarded = observe(app.clone()).await; eprintln!( "next statement isolation: deadline_ms={} control={control_sample:?} guarded={guarded:?} guarded/control={:.3}", diff --git a/queue-rs/polis-api/src/route.rs b/queue-rs/polis-api/src/route.rs index aad6c94f3..ca15fdc93 100644 --- a/queue-rs/polis-api/src/route.rs +++ b/queue-rs/polis-api/src/route.rs @@ -143,6 +143,9 @@ pub struct App { pub delphi_reports_db: Option>, pub delphi_reports_served: AtomicU64, pub delphi_reports_fallback: AtomicU64, + pub delphi_visualizations_result_db: Option>, + pub delphi_visualizations_env: String, + pub delphi_visualizations_scope: Option, pub delphi_visualizations_db: Option>, pub delphi_visualizations_served: AtomicU64, pub delphi_visualizations_fallback: AtomicU64, @@ -340,6 +343,9 @@ impl App { delphi_reports_db: None, delphi_reports_served: AtomicU64::new(0), delphi_reports_fallback: AtomicU64::new(0), + delphi_visualizations_result_db: None, + delphi_visualizations_env: String::new(), + delphi_visualizations_scope: None, delphi_visualizations_db: None, delphi_visualizations_served: AtomicU64::new(0), delphi_visualizations_fallback: AtomicU64::new(0), diff --git a/queue-rs/polis-contracts/src/delphi_visualizations.rs b/queue-rs/polis-contracts/src/delphi_visualizations.rs index be9646c75..70032560e 100644 --- a/queue-rs/polis-contracts/src/delphi_visualizations.rs +++ b/queue-rs/polis-contracts/src/delphi_visualizations.rs @@ -35,3 +35,32 @@ impl Request { } } } + +/// PostgreSQL mode has no static visualization artifacts. These are the +/// existing jobs-list fields, in the order Node writes them. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub struct Job { + pub job_id: String, + pub status: String, + pub created_at: Option, + pub started_at: Option, + pub completed_at: Option, + pub results: crate::wire::Json, + #[serde(skip_serializing_if = "Option::is_none")] + pub archived: Option, + pub work_live: bool, +} +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(deny_unknown_fields)] +pub struct JobsResponse { + pub status: Success, + pub report_id: String, + pub visualizations: Vec, + pub jobs: Vec, +} +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum Success { + Success, +} diff --git a/server/characterization/delphi/main.cjs b/server/characterization/delphi/main.cjs index 11e3c5935..2030f6604 100644 --- a/server/characterization/delphi/main.cjs +++ b/server/characterization/delphi/main.cjs @@ -438,7 +438,9 @@ async function main() { // Optional Rust conformance uses the unchanged fixture and recording oracle. const rust = process.env.P2ZERO_RUST_KEYS - ? await require("../../../queue-rs/polis-api/conformance/delphi-logs-check.cjs").start({ + ? await require(process.env.P2ZERO_RUST_CHECK === "visualizations" + ? "../../../queue-rs/polis-api/conformance/delphi-visualizations-pg-check.cjs" + : "../../../queue-rs/polis-api/conformance/delphi-logs-check.cjs").start({ keys: process.env.P2ZERO_RUST_KEYS, jwks: signer.jwks, publicKey: pair.publicKey, request, serialize, oidc, database: pgApp.toString(), @@ -463,7 +465,7 @@ async function main() { const r = await request(c.path, token); statusCounts[r.status] = (statusCounts[r.status] || 0) + 1; const text = serialize(c, r); - if (rust && c.route === "GET /api/v3/delphi/logs") await rust.compare(c, token, text); + if (rust && (rust.matches ? rust.matches(c) : c.route === "GET /api/v3/delphi/logs")) await rust.compare(c, token, text); const file = path.join(RECORDINGS, `${c.id}.json`); index.cases.push({ id: c.id, From 6c7f9b756b9c84575f1a74f91c0a08a220247968 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 14:29:37 -0700 Subject: [PATCH 03/30] polis-api: a typed read route for the Delphi topics list, behind its own switch (#3231) Rust read route only, off by default (its own switch plus a RUST_API_ROUTES arm); stacked on the visualizations route PR (merge order: logs, visualizations, topics; retargeted to edge as each merges). The public topics-by-layer read with moderation state, byte-faithful to Node against the Postgres-mode baseline; it passes stored topic names through unchanged. No write, schema or Node change. Reviewed independently: publish as-is after the rebase. Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- .../delphiRead.location.conf.template | 2 +- polis-cli/tests/differential/routes.json | 4 +- queue-rs/polis-api/README.md | 33 ++ .../conformance/delphi-topics-pg-check.cjs | 58 +++ .../conformance/delphi-topics-pg-compose.yml | 72 ++++ .../conformance/delphi-topics-pg-run.sh | 26 ++ .../polis-api/conformance/nginx-routing.sh | 1 + queue-rs/polis-api/src/delphi_logs.rs | 2 +- queue-rs/polis-api/src/delphi_read.rs | 82 +++-- queue-rs/polis-api/src/delphi_topics.rs | 348 ++++++++++++++++++ queue-rs/polis-api/src/main.rs | 18 + queue-rs/polis-api/src/next_comment.rs | 10 + queue-rs/polis-api/src/route.rs | 6 + queue-rs/polis-contracts/src/delphi_read.rs | 36 ++ server/characterization/delphi/main.cjs | 4 +- 15 files changed, 662 insertions(+), 40 deletions(-) create mode 100644 queue-rs/polis-api/conformance/delphi-topics-pg-check.cjs create mode 100644 queue-rs/polis-api/conformance/delphi-topics-pg-compose.yml create mode 100755 queue-rs/polis-api/conformance/delphi-topics-pg-run.sh create mode 100644 queue-rs/polis-api/src/delphi_topics.rs diff --git a/file-server/nginx/rust-api/delphiRead.location.conf.template b/file-server/nginx/rust-api/delphiRead.location.conf.template index d14f6ff8a..dc89f0db5 100644 --- a/file-server/nginx/rust-api/delphiRead.location.conf.template +++ b/file-server/nginx/rust-api/delphiRead.location.conf.template @@ -23,7 +23,7 @@ location = /api/v3/delphi { proxy_set_header Host $host; proxy_connect_timeout 100ms; proxy_send_timeout 100ms; - proxy_read_timeout 100ms; + proxy_read_timeout 1s; proxy_buffering off; proxy_request_buffering off; } diff --git a/polis-cli/tests/differential/routes.json b/polis-cli/tests/differential/routes.json index d5552739f..4d2022e5f 100644 --- a/polis-cli/tests/differential/routes.json +++ b/polis-cli/tests/differential/routes.json @@ -342,7 +342,7 @@ "delphi overview", "delphi show" ], - "scope": "Existing-report DynamoDB results remain Node; only missing/unknown report validation is staged. Raw replay provides positive serving proof." + "scope": "Shared DynamoDB fixture retains two Node handoffs. Dedicated PostgreSQL topics replay proves successful result serving and bounded handback; validation-only behavior remains in DynamoDB mode." }, "delphiReports": { "path": "/api/v3/delphi/reports", @@ -353,7 +353,7 @@ "delphi results", "delphi narrative view" ], - "scope": "Existing-report DynamoDB results remain Node; only missing/unknown report validation is staged. Raw replay provides positive serving proof." + "scope": "Shared DynamoDB fixture retains two Node handoffs. Dedicated PostgreSQL topics replay proves successful result serving and bounded handback; validation-only behavior remains in DynamoDB mode." }, "delphiVisualizations": { "path": "/api/v3/delphi/visualizations", diff --git a/queue-rs/polis-api/README.md b/queue-rs/polis-api/README.md index 7f3deabd9..d1b254436 100644 --- a/queue-rs/polis-api/README.md +++ b/queue-rs/polis-api/README.md @@ -1415,3 +1415,36 @@ then adds native attempts, moderator controls, archive precedence and the pre-filter entry limit. Its reader login has only the existing executor role. The shared CLI differential retains its DynamoDB fixture and therefore checks this route's disabled fallback; it does not claim Postgres log-serving coverage. + +### PostgreSQL legacy topics + +`POLIS_API_DELPHI_READS=1` and `RUST_API_ROUTES=delphiRead` remain off by default. +With `DELPHI_RESULT_BACKEND=postgres`, also set `POLIS_API_DELPHI_TOPICS_DATABASE_URL` +to a primary reader with EXECUTE on `pd_result_page` and SELECT on `reports` +(`report_id`, `zid`), `DELPHI_RESULT_ENV` +and optional `DELPHI_RESULT_SCOPE`. Both database URLs must point to the same primary database in PostgreSQL mode. +The report lookup retains its separate one-slot pool; the new result pool has two read-only slots, 15 ms acquisition and 200 ms statement +limits, and the whole request is bounded to 750 ms. It shares no participation pool. + +The legacy response groups by model/date, keeps last topic per layer/cluster, counts +all items, and takes its job UUID from the oldest narrative index row. Narrative and +topics are separate reads, as in Node; this is not an immutable run-result contract. +Numeric object keys preserve JavaScript order. Missing fields stay absent, stored nulls +stay null. Local-time ISO dates require `TZ=UTC`; unsupported date/coercion/prototype +shapes, ambiguous scopes, over 1,000 source rows or 512 KiB of tagged source, and all +query failures hand back to Node with 502. The SQL byte check runs before rows +are transferred to Rust. No partial result is returned. DynamoDB +mode retains validation-only serving. Public auth headers are ignored in PostgreSQL +mode as they are in Node. No handler, schema, writer or production setting changed. + +Conformance with locally built Node, migrated Postgres and fixture-clock API images: +```sh +COMPOSE_PROJECT_NAME=topics-proof POLIS_RECOVERY_PG_PORT=58241 \ +DELPHI_TOPICS_PG_NODE_IMAGE=topics-node:local \ +DELPHI_TOPICS_PG_POSTGRES_IMAGE=topics-postgres:local \ +DELPHI_TOPICS_PG_API_IMAGE=topics-api:local \ +queue-rs/polis-api/conformance/delphi-topics-pg-run.sh /tmp/topics-results.json +``` +The runner replays the unchanged Postgres baseline and checks Rust response bytes, +served/fallback counters, overwrites, ordering, nulls, publication replacement and +an explicit bounded fallback. Images use generated fixtures only. diff --git a/queue-rs/polis-api/conformance/delphi-topics-pg-check.cjs b/queue-rs/polis-api/conformance/delphi-topics-pg-check.cjs new file mode 100644 index 000000000..9b21ba288 --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-topics-pg-check.cjs @@ -0,0 +1,58 @@ +"use strict"; +const fs=require("node:fs"),path=require("node:path"); +exports.start=async function(context) { + const prior=await require("./delphi-visualizations-pg-check.cjs").start(context); + const {request,serialize,keys,database,oidc}=context; + const port=Number(process.env.P2ZERO_RUST_PORT||5100),captures=[],handoffs=[]; + async function compare(c,token,node) { + const rust=serialize(c,await request(c.path,token,port)); + captures.push({case:c.id,node:JSON.parse(node),rust:JSON.parse(rust),equal:node===rust}); + fs.writeFileSync(path.join(keys,"topics-captures.json"),JSON.stringify(captures,null,2)+"\n"); + } + return { + matches(c) {return prior.matches(c)||c.route==="GET /api/v3/delphi";}, + async compare(c,token,node) {if(c.route==="GET /api/v3/delphi")await compare(c,token,node);else await prior.compare(c,token,node);}, + async finish() { + await prior.finish(); + const priorResults=JSON.parse(fs.readFileSync(path.join(keys,"results.json"))); + const {createRequire}=require("node:module"); + const {Client}=createRequire(path.resolve(process.cwd(),"package.json"))("pg"); + const {publish}=require(path.resolve(process.cwd(),"__tests__/delphi-results-pg/support.ts")); + const db=new Client({connectionString:database});await db.connect(); + const query="/api/v3/delphi?report_id=r2p2zero105"; + async function check(id,url,token,verify) { + const c={id:`topics/${id}`,state:"supplemental",route:"GET /api/v3/delphi",path:url,auth:token?"other":"none"}; + const n=await request(url,token);if(n.status!==200)throw Error(`${id}: Node status ${n.status}`); + if(verify)verify(JSON.parse(n.body)); + await compare(c,token,serialize(c,n)); + } + await check("auth-is-ignored",query,oidc("p2zero|other","other@example.invalid")); + const topic=(key,layer,cluster,name,model,date)=>({conversation_id:{S:"105"},topic_key:{S:key},layer_id:{N:String(layer)},cluster_id:{N:String(cluster)},topic_name:{S:name},model_name:{S:model},created_at:{S:date}}); + const family="Delphi_CommentClustersLLMTopicNames"; + const rows=[topic("a",0,10,"overwritten","alpha","2023-11-14T19:20:01.000000"),topic("b",0,2,"second","alpha","2023-11-14T19:20:01.000000"),topic("c",0,10,"winner","alpha","2023-11-14T19:20:01.000000"),topic("d",1,-1,"new run","beta","2023-11-15T19:20:01.000000")]; + let previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,families:{[family]:rows}}); + await check("collisions-and-date-order",query,null,b=>{const k=Object.keys(b.runs);if(k.join()!=="beta_2023-11-15,alpha_2023-11-14"||b.runs[k[1]].item_count!==3||b.runs[k[1]].topics_by_layer[0][10].topic_name!=="winner")throw Error("collision fixture");}); + const missing={conversation_id:{S:"105"},topic_key:{S:"a"},topic_name:{NULL:true}}; + previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:[missing]}}); + await check("missing-and-null",query,null,b=>{if(b.runs.unknown_.topics_by_layer.undefined.undefined.topic_name!==null||"model_name" in b.runs.unknown_)throw Error("missing fields fixture");}); + previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:[]}}); + await check("empty-after-publication",query,null,b=>{if(Object.keys(b.runs).length)throw Error("empty publication");}); + // Large input stays on Node. No partial result is ever served by Rust. + const large=Array.from({length:1001},(_,i)=>topic(`topic-${String(i).padStart(4,"0")}`,0,i,"generated","bounded","2023-11-14T19:20:01.000000")); + await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:large}}); + const n=await request(query,null),r=await request(query,null,port); + if(n.status!==200||r.status!==502||JSON.parse(n.body).runs["bounded_2023-11-14"].item_count!==1001)throw Error("bounded handback"); + handoffs.push({case:"topics-row-bound",nodeStatus:n.status,rustStatus:r.status,nodeRows:1001}); + await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:[topic("large-item",0,0,"x".repeat(600000),"bounded","2023-11-14T19:20:01.000000")]}}); + const bigNode=await request(query,null),bigRust=await request(query,null,port); + if(bigNode.status!==200||bigRust.status!==502||bigNode.body.length<600000)throw Error("byte-bounded handback"); + handoffs.push({case:"topics-input-byte-bound",nodeStatus:bigNode.status,rustStatus:bigRust.status,nodeBytes:bigNode.body.length}); + await db.end(); + const counters=JSON.parse((await request("/health",null,port)).body); + const all=[...priorResults.captures,...captures],failures=all.filter(c=>!c.equal); + fs.writeFileSync(path.join(keys,"results.json"),JSON.stringify({cases:all.length,equal:all.length-failures.length,failures:failures.length,topics:captures.length,counters,captures:all,handoffs:[...priorResults.handoffs,...handoffs]},null,2)+"\n"); + console.log(`Rust Delphi topics: ${captures.length} cases; combined ${all.length} cases, ${failures.length} differences`); + if(failures.length)throw Error(`Rust topics byte differences: ${failures.map(c=>c.case).join(", ")}`); + } + }; +}; diff --git a/queue-rs/polis-api/conformance/delphi-topics-pg-compose.yml b/queue-rs/polis-api/conformance/delphi-topics-pg-compose.yml new file mode 100644 index 000000000..0b17695a4 --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-topics-pg-compose.yml @@ -0,0 +1,72 @@ +services: + postgres: + image: ${DELPHI_TOPICS_PG_POSTGRES_IMAGE:?set a fixture Postgres image} + environment: {POSTGRES_HOST_AUTH_METHOD: trust} + ports: ["127.0.0.1:${POLIS_RECOVERY_PG_PORT:?set a unique port}:5432"] + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 2s + timeout: 2s + retries: 30 + dynamodb: + image: amazon/dynamodb-local:3.3.1@sha256:ff89bd48ff32cd8d9be5fee8873b65b8854dc408f1afe881be6eb00247bc0dab + command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-inMemory"] + recorder: + image: ${DELPHI_TOPICS_PG_NODE_IMAGE:?set a Node image} + working_dir: /app + entrypoint: [sh, -c] + command: ["cp -a /candidate/. /app/; exec node characterization/delphi/main.cjs replay"] + volumes: + - ${DELPHI_TOPICS_PG_SOURCE}/server:/candidate:ro + - ${DELPHI_TOPICS_PG_SOURCE}/delphi:/delphi + - ${DELPHI_TOPICS_PG_SOURCE}/queue-rs:/queue-rs:ro + - ${DELPHI_TOPICS_PG_SCRATCH}:/proof + environment: + P2ZERO_PG_ADMIN_URL: postgres://postgres@postgres:5432/postgres + DYNAMODB_ENDPOINT: http://dynamodb:8000 + DELPHI_RESULT_BACKEND: postgres + P2ZERO_RUST_KEYS: /proof + P2ZERO_RUST_CHECK: topics + TZ: UTC + depends_on: + postgres: {condition: service_healthy} + dynamodb: {condition: service_started} + polis-api: + image: ${DELPHI_TOPICS_PG_API_IMAGE:?set a fixture-clock API image} + network_mode: service:recorder + entrypoint: [sh, -c] + command: ["while [ ! -f /proof/ready ]; do sleep 1; done; exec /usr/local/bin/polis-api"] + volumes: ["${DELPHI_TOPICS_PG_SCRATCH}:/proof:ro"] + environment: + DATABASE_URL: postgres://postgres@postgres:5432/p2zero + DATABASE_SSL: 'false' + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + MATH_ENV: p2zero + DEV_MODE: 'true' + POLIS_API_DELPHI_LOGS_DATABASE_URL: postgres://generated_logs_reader@postgres:5432/p2zero + POLIS_API_DELPHI_LOGS_AUTH_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_LOGS_READS: '1' + POLIS_API_DELPHI_READS: '1' + POLIS_API_DELPHI_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_TOPICS_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_VISUALIZATIONS_READS: '1' + POLIS_API_DELPHI_VISUALIZATIONS_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_VISUALIZATIONS_RESULTS_DATABASE_URL: postgres://generated_viz_reader@postgres:5432/p2zero + DELPHI_RESULT_BACKEND: postgres + DELPHI_RESULT_ENV: p2zero + DELPHI_RESULT_SCOPE: delphi + POLIS_API_READ_JWKS_FILE: /proof/jwks.json + POLIS_API_PARTICIPANT_READS: '1' + POLIS_API_PARTICIPANT_PUBLIC_KEY_FILE: /proof/participant.pem + POLIS_API_FIXTURE_CLOCK: '1700000000000' + AUTH_ISSUER: https://oidc.p2zero.invalid/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ + POLIS_JWT_ISSUER: https://pol.is/ + POLIS_JWT_AUDIENCE: participants + ADMIN_UIDS: '[2]' + DOMAIN_OVERRIDE: localhost + SERVICE_URL: http://localhost + NODE_ENV: production + TZ: UTC diff --git a/queue-rs/polis-api/conformance/delphi-topics-pg-run.sh b/queue-rs/polis-api/conformance/delphi-topics-pg-run.sh new file mode 100755 index 000000000..c2034829e --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-topics-pg-run.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Postgres baseline and native topic results; all services are disposable fixtures. +# Requires three local images (Node, migration Postgres, fixture-clock polis-api). +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:?provide a results JSON path} +: "${COMPOSE_PROJECT_NAME:?set a unique project}" +: "${POLIS_RECOVERY_PG_PORT:?set a unique port}" +export RECOVERY_PG_PORT="$POLIS_RECOVERY_PG_PORT" +export DELPHI_TOPICS_PG_SOURCE="$root" +export DELPHI_TOPICS_PG_SCRATCH=${DELPHI_TOPICS_PG_SCRATCH:-$(mktemp -d)} +mkdir -p "$DELPHI_TOPICS_PG_SCRATCH" +[[ -z $(ls -A "$DELPHI_TOPICS_PG_SCRATCH") ]] || { echo "scratch must be empty" >&2; exit 2; } +compose=(docker compose -f "$root/queue-rs/polis-api/conformance/delphi-topics-pg-compose.yml") +[[ -z $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]] || { echo "project already exists" >&2; exit 2; } +cleanup() { + "${compose[@]}" logs --no-color >"${out%.json}-services.log" 2>&1 || true + "${compose[@]}" down -v --remove-orphans >/dev/null 2>&1 || true +} +trap cleanup EXIT INT TERM +"${compose[@]}" up -d --pull never postgres dynamodb recorder polis-api +cid=$("${compose[@]}" ps -aq recorder) +result=$(docker wait "$cid") +"${compose[@]}" logs --no-color recorder +docker cp "$cid:/proof/results.json" "$out" +exit "$result" diff --git a/queue-rs/polis-api/conformance/nginx-routing.sh b/queue-rs/polis-api/conformance/nginx-routing.sh index fb0e61f16..8746113d2 100755 --- a/queue-rs/polis-api/conformance/nginx-routing.sh +++ b/queue-rs/polis-api/conformance/nginx-routing.sh @@ -1067,6 +1067,7 @@ expect /api/v3/comments node "Delphi report validation leaves comments alone" expect /api/v3/votes node "Delphi report validation leaves voting alone" [[ $(included | grep -c 'location = /api/v3/delphi') == 1 ]] || fail "Delphi report validation duplicated" expect_upstream polis-api GET /api/v3/delphi +expect_upstream polis-api GET "/api/v3/delphi?report_id=generated-report" $'Authorization: Bearer ignored\r\n' expect_upstream polis-api HEAD /api/v3/delphi expect_upstream server OPTIONS /api/v3/delphi expect_upstream server POST /api/v3/delphi $'Content-Length: 2\r\n' '{}' diff --git a/queue-rs/polis-api/src/delphi_logs.rs b/queue-rs/polis-api/src/delphi_logs.rs index 6006b7d8f..bad990847 100644 --- a/queue-rs/polis-api/src/delphi_logs.rs +++ b/queue-rs/polis-api/src/delphi_logs.rs @@ -274,7 +274,7 @@ fn log_events(raw: Js, job: &str) -> Option> { } /// ISO timestamps only. Date.parse's other grammars stay with Node. Legacy /// Python timestamps without a zone are admitted only under explicit UTC. -fn iso_millis(s: &str) -> Option { +pub(crate) fn iso_millis(s: &str) -> Option { let s = if let Some(s) = s.strip_suffix('Z') { s } else { diff --git a/queue-rs/polis-api/src/delphi_read.rs b/queue-rs/polis-api/src/delphi_read.rs index f0c3eade6..c14659aa0 100644 --- a/queue-rs/polis-api/src/delphi_read.rs +++ b/queue-rs/polis-api/src/delphi_read.rs @@ -5,7 +5,7 @@ use crate::{ }; // Both workspaces compile the same shared contract module. #[path = "../../polis-contracts/src/delphi_read.rs"] -mod contract; +pub(crate) mod contract; pub use contract::PATH; pub fn parse(app: &App, req: &Request) -> Option { if app.delphi_read_db.is_none() @@ -14,8 +14,8 @@ pub fn parse(app: &App, req: &Request) -> Option { || !req.body.is_empty() || req.headers.get("transfer-encoding").is_some() || req.headers.get("content-length").is_some_and(|s| s != "0") - || req.headers.get("authorization").is_some() - || req.headers.get("cookie").is_some() + || (app.delphi_topics_db.is_none() + && (req.headers.get("authorization").is_some() || req.headers.get("cookie").is_some())) { return None; } @@ -54,39 +54,51 @@ pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { let Some(query) = parse(app, req) else { return route::bad_gateway(); }; - let status = if query.report_id.is_some() { 404 } else { 400 }; - let value = match query.report_id { - None => contract::Request::missing(), - Some(id) => { - let Some(pool) = &app.delphi_read_db else { - return route::bad_gateway(); - }; - let report_id = id.clone(); - // The Node resolver is uncached. Only absence qualifies: every existing - // report (including unusual/null/zero identifiers) stays with Node. - let Ok(Ok(false)) = tokio::time::timeout( - std::time::Duration::from_millis(75), - pool.with(move |c| { - Ok(!c - .query( - "SELECT zid FROM reports WHERE report_id=$1 LIMIT 1", - &[&report_id], - )? - .is_empty()) - }), - ) - .await - else { - return route::bad_gateway(); - }; - contract::Request::unknown(id) - } - }; - let Ok(encoded) = serde_json::to_string(&value) else { + let Ok(Some((status, body))) = tokio::time::timeout( + std::time::Duration::from_millis(if app.delphi_topics_db.is_some() { + 750 + } else { + 75 + }), + answer(app, query), + ) + .await + else { return route::bad_gateway(); }; - let Ok(value) = crate::js::parse(&encoded) else { - return route::bad_gateway(); + route::json_text(req, res, status, body) +} +async fn answer(app: &App, query: contract::Request) -> Option<(u16, String)> { + let Some(id) = query.report_id else { + return Some(( + 400, + crate::wire::to_json(&contract::Request::missing()).ok()?, + )); + }; + let rid = id.clone(); + let zid = app + .delphi_read_db + .as_ref()? + .with(move |c| { + Ok(c.query_opt( + "SELECT zid FROM reports WHERE report_id=$1 LIMIT 1", + &[&rid], + )? + .map(|r| r.try_get::<_, Option>(0)) + .transpose()?) + }) + .await + .ok()?; + // Validation-only mode still hands every existing row to Node, including + // null and zero. PostgreSQL mode follows the handler's falsy-zid response. + if zid.is_some() && app.delphi_topics_db.is_none() { + return None; + } + let Some(zid) = zid.flatten().filter(|z| *z != 0) else { + return Some(( + 404, + crate::wire::to_json(&contract::Request::unknown(id)).ok()?, + )); }; - route::json_status(req, res, status, &value) + Some((200, crate::delphi_topics::answer(app, zid, id).await?)) } diff --git a/queue-rs/polis-api/src/delphi_topics.rs b/queue-rs/polis-api/src/delphi_topics.rs new file mode 100644 index 000000000..27e9fd27b --- /dev/null +++ b/queue-rs/polis-api/src/delphi_topics.rs @@ -0,0 +1,348 @@ +//! Bounded PostgreSQL topics, preserving the legacy route's two read boundaries. +use crate::{delphi_read::contract, wire::JsMap}; +use anyhow::{Result, ensure}; +use postgres::Client; +use serde_json::Value; +use std::collections::BTreeMap; +const TOPICS: &str = "Delphi_CommentClustersLLMTopicNames"; +const NARRATIVES: &str = "Delphi_NarrativeReports"; +const MAX_ROWS: usize = 1000; +const MAX_BYTES: usize = 512 * 1024; + +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 2, + statement_timeout: std::time::Duration::from_millis(200), + ..crate::delphi_read::pool_limits() + } +} + +/// Never merge Node's distinct narrative/topic snapshots. Bounded requests run +/// sequentially and release their own connection between the two reads. +pub async fn answer(app: &crate::route::App, zid: i32, report: String) -> Option { + if !(1..=999999999).contains(&zid) { + return None; + } + let pool = app.delphi_topics_db.as_ref()?; + let env = app.delphi_topics_env.clone(); + let scope = app.delphi_topics_scope.clone(); + let rid = report.clone(); + let job = pool + .with(move |c| narrative(c, &env, scope.as_deref(), &rid)) + .await + .ok()?; + let env = app.delphi_topics_env.clone(); + let scope = app.delphi_topics_scope.clone(); + let rows = pool + .with(move |c| family(c, &env, scope.as_deref(), TOPICS, Some(zid), None)) + .await + .ok()?; + let body = crate::wire::to_json(&response(rows, zid, report, job).ok()?).ok()?; + (body.len() <= 1024 * 1024).then_some(body) +} + +fn family( + c: &mut Client, + env: &str, + scope: Option<&str>, + name: &str, + zid: Option, + report: Option<&str>, +) -> Result> { + // The function walks exactly the served family. Its default key order is + // Node's pre-index ordering. Extra rows or more than a conservative single + // page go back to Node, without returning a partial snapshot. + let rows = c.query("WITH page AS MATERIALIZED (SELECT item_key::text AS item_key, item::text AS item, ordinality FROM public.pd_result_page($1, CASE WHEN $5::text IS NULL THEN ARRAY[$2]::integer[] ELSE ARRAY(SELECT zid FROM reports WHERE report_id=$5) END, $3, $4, NULL,NULL,NULL,NULL,false,1001) WITH ORDINALITY), bounded AS (SELECT *, sum(octet_length(item_key)+octet_length(item)) OVER () <= 524288 AS fits FROM page) SELECT CASE WHEN fits THEN item_key END, CASE WHEN fits THEN item END FROM bounded ORDER BY ordinality", &[&env,&zid,&scope,&name,&report])?; + ensure!(rows.len() <= MAX_ROWS, "result row bound"); + let mut bytes = 0; + let mut seen = BTreeMap::::new(); + let mut items = Vec::new(); + for row in rows { + let key: String = row.try_get(0)?; + let text: String = row.try_get(1)?; + bytes += text.len(); + ensure!(bytes <= MAX_BYTES, "single-page result bound"); + let item: Value = serde_json::from_str(&text)?; + if let Some(prior) = seen.insert(key, item.clone()) { + ensure!(prior == item, "ambiguous result scopes"); + continue; + } + validate_item(&item)?; + items.push(item); + } + Ok(items) +} + +// Node decodes every attribute, even fields the response does not use. Refuse +// unsupported representations rather than bypassing a decoder failure. +fn validate_item(item: &Value) -> Result<()> { + let fields = item + .as_object() + .ok_or_else(|| anyhow::anyhow!("invalid item"))?; + for v in fields.values() { + validate_attribute(v)?; + } + Ok(()) +} +fn validate_attribute(v: &Value) -> Result<()> { + let tag = v + .as_object() + .ok_or_else(|| anyhow::anyhow!("invalid attribute"))?; + ensure!(tag.len() == 1, "ambiguous attribute"); + if v.get("S").is_some_and(Value::is_string) + || v.get("BOOL").is_some_and(Value::is_boolean) + || v.get("NULL") == Some(&Value::Bool(true)) + { + return Ok(()); + } + if let Some(s) = v.get("N").and_then(Value::as_str) { + let n: f64 = s.parse()?; + ensure!( + n.is_finite() && (n.fract() != 0.0 || n.abs() <= 9_007_199_254_740_991.0), + "numeric reader precision" + ); + return Ok(()); + } + if let Some(list) = v.get("L").and_then(Value::as_array) { + for x in list { + validate_attribute(x)?; + } + return Ok(()); + } + if let Some(map) = v.get("M") { + return validate_item(map); + } + anyhow::bail!("unsupported attribute"); +} +fn text(item: &Value, key: &str) -> Result { + match item.get(key) { + None => Ok(None), + Some(v) if v.get("NULL") == Some(&Value::Bool(true)) => Ok(Some(None)), + Some(v) => Ok(Some(Some( + v.get("S") + .and_then(Value::as_str) + .ok_or_else(|| anyhow::anyhow!("unsupported string field"))? + .into(), + ))), + } +} +fn string(item: &Value, key: &str) -> Result> { + Ok(text(item, key)?.flatten()) +} +fn property(item: &Value, key: &str) -> Result { + let value = match item.get(key) { + None => "undefined".into(), + Some(v) if v.get("NULL") == Some(&Value::Bool(true)) => "null".into(), + Some(v) if v.get("S").is_some() => v["S"] + .as_str() + .ok_or_else(|| anyhow::anyhow!("invalid string"))? + .into(), + Some(v) => { + let n: f64 = v["N"] + .as_str() + .ok_or_else(|| anyhow::anyhow!("unsupported property"))? + .parse()?; + ensure!( + n.is_finite() && n.fract() == 0.0 && n.abs() <= 9_007_199_254_740_991.0, + "unsupported property number" + ); + crate::js::stringify(&crate::js::Js::Num(n)) + } + }; + ensure!( + !matches!( + value.as_str(), + "__proto__" + | "constructor" + | "prototype" + | "toString" + | "valueOf" + | "hasOwnProperty" + | "isPrototypeOf" + | "propertyIsEnumerable" + | "toLocaleString" + | "__defineGetter__" + | "__defineSetter__" + | "__lookupGetter__" + | "__lookupSetter__" + ), + "inherited object property" + ); + Ok(value) +} +fn narrative( + c: &mut Client, + env: &str, + scope: Option<&str>, + report: &str, +) -> Result> { + let mut rows = Vec::new(); + for item in family(c, env, scope, NARRATIVES, None, Some(report))? { + if string(&item, "report_id")?.as_deref() != Some(report) { + continue; + } + if let Some(ts) = string(&item, "timestamp")? { + let key = string(&item, "rid_section_model")? + .ok_or_else(|| anyhow::anyhow!("missing narrative key"))?; + ensure!( + ts.is_ascii() && key.is_ascii(), + "unsupported index ordering" + ); + rows.push((ts, key, item)); + } + } + // ReportIdTimestampIndex is ascending. Limit 1 is before reading section. + rows.sort_by(|a, b| a.0.cmp(&b.0).then_with(|| a.1.cmp(&b.1))); + let Some((_, _, first)) = rows.first() else { + return Ok(None); + }; + let Some(section) = string(first, "section")? else { + return Ok(None); + }; + if !section.contains('_') { + return Ok(None); + } + for w in section.as_bytes().windows(36) { + if w.iter().enumerate().all(|(i, b)| { + if [8, 13, 18, 23].contains(&i) { + *b == b'-' + } else { + b.is_ascii_digit() || (b'a'..=b'f').contains(b) + } + }) { + return Ok(Some(std::str::from_utf8(w)?.into())); + } + } + Ok(None) +} +fn response( + items: Vec, + zid: i32, + report: String, + job: Option, +) -> Result { + let mut groups: Vec<(String, Vec)> = Vec::new(); + for item in items { + ensure!( + string(&item, "conversation_id")?.as_deref() == Some(zid.to_string().as_str()), + "conversation key" + ); + let model = string(&item, "model_name")? + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| "unknown".into()); + let created = string(&item, "created_at")?.unwrap_or_default(); + ensure!(created.is_ascii(), "unsupported date prefix"); + let key = format!("{}_{}", model, &created[..created.len().min(10)]); + ensure!(key != "__proto__", "inherited run property"); + if let Some((_, rows)) = groups.iter_mut().find(|(k, _)| k == &key) { + rows.push(item); + } else { + groups.push((key, vec![item])); + } + } + let mut runs = Vec::new(); + for (key, rows) in groups { + let first = &rows[0]; + let created = string(first, "created_at")?.unwrap_or_default(); + let millis = if created.is_empty() { + 0 + } else { + crate::delphi_logs::iso_millis(&created) + .ok_or_else(|| anyhow::anyhow!("unsupported Date ordering"))? + }; + let mut layers: Vec<(String, Vec<(String, contract::Topic)>)> = Vec::new(); + for item in &rows { + let layer = property(item, "layer_id")?; + let cluster = property(item, "cluster_id")?; + let topic = contract::Topic { + topic_name: text(item, "topic_name")?, + model_name: text(item, "model_name")?, + created_at: text(item, "created_at")?, + topic_key: text(item, "topic_key")?, + }; + if !layers.iter().any(|(k, _)| k == &layer) { + layers.push((layer.clone(), Vec::new())); + } + let target = &mut layers + .iter_mut() + .find(|(k, _)| k == &layer) + .ok_or_else(|| anyhow::anyhow!("missing layer"))? + .1; + if let Some((_, old)) = target.iter_mut().find(|(k, _)| k == &cluster) { + *old = topic; + } else { + target.push((cluster, topic)); + } + } + let layers = JsMap::try_from_entries( + layers + .into_iter() + .map(|(k, v)| Ok((k, JsMap::try_from_entries(v)?))) + .collect::>>()?, + )?; + runs.push(( + key, + millis, + contract::Run { + model_name: text(first, "model_name")?, + created_date: text(first, "created_at")?, + topics_by_layer: layers, + item_count: rows.len(), + job_uuid: job.clone(), + }, + )); + } + runs.sort_by_key(|a| std::cmp::Reverse(a.1)); + let message = if runs.is_empty() { + "No LLM topics found for this conversation" + } else { + "LLM topics retrieved successfully" + }; + Ok(contract::TopicsResponse { + status: contract::Success::Success, + message, + report_id: report, + runs: JsMap::try_from_entries(runs.into_iter().map(|(k, _, r)| (k, r)))?, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + #[test] + fn duplicate_cluster_overwrites_without_reordering_and_counts_all_items() { + let row = |key: &str, cluster: &str, name: &str| json!({"conversation_id":{"S":"105"},"topic_key":{"S":key},"layer_id":{"N":"0"},"cluster_id":{"N":cluster},"model_name":{"S":"m"},"created_at":{"S":"2023-11-14T00:00:00Z"},"topic_name":{"S":name}}); + let result = response( + vec![ + row("a", "10", "old"), + row("b", "2", "second"), + row("c", "10", "new"), + ], + 105, + "generated-report".into(), + None, + ) + .unwrap(); + let encoded = crate::wire::to_json(&result).unwrap(); + assert!(encoded.find("\"2\":").unwrap() < encoded.find("\"10\":").unwrap()); + assert!(!encoded.contains("old")); + assert!(encoded.contains("new")); + assert!(encoded.contains("\"item_count\":3")); + } + #[test] + fn missing_and_null_properties_and_unsafe_keys_are_distinct() { + let mut row = + json!({"conversation_id":{"S":"105"},"topic_key":{"S":"a"},"topic_name":{"NULL":true}}); + let encoded = crate::wire::to_json( + &response(vec![row.clone()], 105, "generated-report".into(), None).unwrap(), + ) + .unwrap(); + assert!(encoded.contains("\"topic_name\":null")); + assert!(!encoded.contains("\"model_name\"")); + assert!(encoded.contains("\"undefined\":{\"undefined\":")); + row["layer_id"] = json!({"S":"__proto__"}); + assert!(response(vec![row], 105, "generated-report".into(), None).is_err()); + assert!(validate_attribute(&json!({"N":"9007199254740992"})).is_err()); + } +} diff --git a/queue-rs/polis-api/src/main.rs b/queue-rs/polis-api/src/main.rs index 7df9b4c50..a83c5d151 100644 --- a/queue-rs/polis-api/src/main.rs +++ b/queue-rs/polis-api/src/main.rs @@ -38,6 +38,7 @@ mod delphi_read; mod delphi_reports; mod delphi_result_read; mod delphi_run_read; +mod delphi_topics; mod delphi_visualizations; mod domain_whitelist; mod einvites_read; @@ -900,6 +901,23 @@ async fn main() -> Result<()> { config::connector_for_dsn(&dsn, "polis-api-delphi-read/1")?, delphi_read::pool_limits(), )); + if std::env::var("DELPHI_RESULT_BACKEND").ok().as_deref() == Some("postgres") { + let dsn = std::env::var("POLIS_API_DELPHI_TOPICS_DATABASE_URL") + .context("POLIS_API_DELPHI_TOPICS_DATABASE_URL required for PostgreSQL topics")?; + state.delphi_topics_env = std::env::var("DELPHI_RESULT_ENV") + .context("DELPHI_RESULT_ENV required for PostgreSQL topics")?; + anyhow::ensure!( + !state.delphi_topics_env.is_empty(), + "DELPHI_RESULT_ENV cannot be empty" + ); + state.delphi_topics_scope = std::env::var("DELPHI_RESULT_SCOPE") + .ok() + .filter(|s| !s.is_empty()); + state.delphi_topics_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-delphi-topics/1")?, + delphi_topics::pool_limits(), + )); + } } if std::env::var("POLIS_API_DATABASE_READS").ok().as_deref() == Some("1") { let dsn = std::env::var("POLIS_API_DATABASE_PROBE_URL") diff --git a/queue-rs/polis-api/src/next_comment.rs b/queue-rs/polis-api/src/next_comment.rs index 37884833a..58e60d5f3 100644 --- a/queue-rs/polis-api/src/next_comment.rs +++ b/queue-rs/polis-api/src/next_comment.rs @@ -581,6 +581,14 @@ mod tests { Connector::Plain(Box::new(pg.clone())), crate::delphi_visualizations::result_pool_limits(), )); + app.delphi_read_db = Some(db::Pool::new( + Connector::Plain(Box::new(pg.clone())), + crate::delphi_read::pool_limits(), + )); + app.delphi_topics_db = Some(db::Pool::new( + Connector::Plain(Box::new(pg.clone())), + crate::delphi_topics::pool_limits(), + )); let app = Arc::new(app); async fn park( pool: Arc, @@ -687,6 +695,7 @@ mod tests { app.delphi_result_db.as_ref().unwrap(), app.delphi_logs_db.as_ref().unwrap(), app.delphi_visualizations_result_db.as_ref().unwrap(), + app.delphi_topics_db.as_ref().unwrap(), ] { for _ in 0..2 { held.push(park(pool.clone()).await); @@ -698,6 +707,7 @@ mod tests { } held.push(park(app.delphi_logs_auth_db.as_ref().unwrap().clone()).await); held.push(park(app.delphi_visualizations_db.as_ref().unwrap().clone()).await); + held.push(park(app.delphi_read_db.as_ref().unwrap().clone()).await); let guarded = observe(app.clone()).await; eprintln!( "next statement isolation: deadline_ms={} control={control_sample:?} guarded={guarded:?} guarded/control={:.3}", diff --git a/queue-rs/polis-api/src/route.rs b/queue-rs/polis-api/src/route.rs index ca15fdc93..b6325f16c 100644 --- a/queue-rs/polis-api/src/route.rs +++ b/queue-rs/polis-api/src/route.rs @@ -171,6 +171,9 @@ pub struct App { pub collective_statement_db: Option>, pub collective_statement_served: AtomicU64, pub collective_statement_fallback: AtomicU64, + pub delphi_topics_db: Option>, + pub delphi_topics_env: String, + pub delphi_topics_scope: Option, pub delphi_read_db: Option>, pub delphi_read_served: AtomicU64, pub delphi_read_fallback: AtomicU64, @@ -371,6 +374,9 @@ impl App { collective_statement_db: None, collective_statement_served: AtomicU64::new(0), collective_statement_fallback: AtomicU64::new(0), + delphi_topics_db: None, + delphi_topics_env: String::new(), + delphi_topics_scope: None, delphi_read_db: None, delphi_read_served: AtomicU64::new(0), delphi_read_fallback: AtomicU64::new(0), diff --git a/queue-rs/polis-contracts/src/delphi_read.rs b/queue-rs/polis-contracts/src/delphi_read.rs index 77ae6c7fc..ec713e8c7 100644 --- a/queue-rs/polis-contracts/src/delphi_read.rs +++ b/queue-rs/polis-contracts/src/delphi_read.rs @@ -35,3 +35,39 @@ impl Request { } } } + +/// Missing properties remain omitted; a stored null remains JSON null. +pub type Text = Option>; +#[derive(Debug, Clone, Serialize)] +pub struct Topic { + #[serde(skip_serializing_if = "Option::is_none")] + pub topic_name: Text, + #[serde(skip_serializing_if = "Option::is_none")] + pub model_name: Text, + #[serde(skip_serializing_if = "Option::is_none")] + pub created_at: Text, + #[serde(skip_serializing_if = "Option::is_none")] + pub topic_key: Text, +} +#[derive(Debug, Clone, Serialize)] +pub struct Run { + #[serde(skip_serializing_if = "Option::is_none")] + pub model_name: Text, + #[serde(skip_serializing_if = "Option::is_none")] + pub created_date: Text, + pub topics_by_layer: crate::wire::JsMap>, + pub item_count: usize, + pub job_uuid: Option, +} +#[derive(Debug, Serialize)] +pub struct TopicsResponse { + pub status: Success, + pub message: &'static str, + pub report_id: String, + pub runs: crate::wire::JsMap, +} +#[derive(Debug, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum Success { + Success, +} diff --git a/server/characterization/delphi/main.cjs b/server/characterization/delphi/main.cjs index 2030f6604..aa8cc1337 100644 --- a/server/characterization/delphi/main.cjs +++ b/server/characterization/delphi/main.cjs @@ -438,7 +438,9 @@ async function main() { // Optional Rust conformance uses the unchanged fixture and recording oracle. const rust = process.env.P2ZERO_RUST_KEYS - ? await require(process.env.P2ZERO_RUST_CHECK === "visualizations" + ? await require(process.env.P2ZERO_RUST_CHECK === "topics" + ? "../../../queue-rs/polis-api/conformance/delphi-topics-pg-check.cjs" + : process.env.P2ZERO_RUST_CHECK === "visualizations" ? "../../../queue-rs/polis-api/conformance/delphi-visualizations-pg-check.cjs" : "../../../queue-rs/polis-api/conformance/delphi-logs-check.cjs").start({ keys: process.env.P2ZERO_RUST_KEYS, jwks: signer.jwks, From 422f50aa520307c449d691944fe4b06a0be2c459 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 15:47:39 -0700 Subject: [PATCH 04/30] polis-api: a typed read route for the Delphi narrative reports list, behind its own switch (#3232) Rust-only read of GET /api/v3/delphi/reports, off by default (its own switch plus a RUST_API_ROUTES arm); byte-faithful to Node against the Postgres-mode baseline (stored timestamps are copied strings on both sides); a query string the legacy parser would decode differently is handed to Node, and an unmatched section filter falls back to the section Node names; a 502 hands the request to Node. Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- .../delphiReports.location.conf.template | 2 +- queue-rs/polis-api/README.md | 30 +- .../conformance/delphi-reports-pg-check.cjs | 85 ++++ .../conformance/delphi-reports-pg-compose.yml | 75 +++ .../conformance/delphi-reports-pg-run.sh | 26 + .../polis-api/conformance/nginx-routing.sh | 1 + queue-rs/polis-api/src/delphi_narratives.rs | 463 ++++++++++++++++++ queue-rs/polis-api/src/delphi_reports.rs | 124 +++-- queue-rs/polis-api/src/main.rs | 19 + queue-rs/polis-api/src/next_comment.rs | 10 + queue-rs/polis-api/src/route.rs | 35 ++ .../polis-contracts/src/delphi_reports.rs | 54 ++ server/characterization/delphi/main.cjs | 4 +- 13 files changed, 875 insertions(+), 53 deletions(-) create mode 100644 queue-rs/polis-api/conformance/delphi-reports-pg-check.cjs create mode 100644 queue-rs/polis-api/conformance/delphi-reports-pg-compose.yml create mode 100755 queue-rs/polis-api/conformance/delphi-reports-pg-run.sh create mode 100644 queue-rs/polis-api/src/delphi_narratives.rs diff --git a/file-server/nginx/rust-api/delphiReports.location.conf.template b/file-server/nginx/rust-api/delphiReports.location.conf.template index 372bd5eef..d4d81c026 100644 --- a/file-server/nginx/rust-api/delphiReports.location.conf.template +++ b/file-server/nginx/rust-api/delphiReports.location.conf.template @@ -23,7 +23,7 @@ location = /api/v3/delphi/reports { proxy_set_header Host $host; proxy_connect_timeout 100ms; proxy_send_timeout 100ms; - proxy_read_timeout 100ms; + proxy_read_timeout 1s; proxy_buffering off; proxy_request_buffering off; } diff --git a/queue-rs/polis-api/README.md b/queue-rs/polis-api/README.md index d1b254436..2b9987331 100644 --- a/queue-rs/polis-api/README.md +++ b/queue-rs/polis-api/README.md @@ -1095,7 +1095,8 @@ serve topics or claim DynamoDB/provider parity. `GET`/`HEAD /api/v3/delphi/reports` is staged behind `POLIS_API_DELPHI_REPORTS_READS=1` and nginx `RUST_API_ROUTES=delphiReports`, both off by default. Set -`POLIS_API_DELPHI_REPORTS_DATABASE_URL` to Node's read replica. Only missing/empty +`POLIS_API_DELPHI_REPORTS_DATABASE_URL` to Node's read replica for validation-only +mode. Without `DELPHI_RESULT_BACKEND=postgres`, only missing/empty report IDs and absent reports (both HTTP 200, matching Node) are served, using the shared `polis-contracts::delphi_reports` request/response types. Existing reports and DynamoDB responses remain Node, as do identity, body, duplicate/structured @@ -1108,7 +1109,8 @@ contention hand back to Node; cancellation retains the slot until the query finishes. `delphiReportsServed` and `delphiReportsFallback` count the outcomes. Run `queue-rs/polis-api/conformance/delphi-reports-run.sh result.json` for raw Node/Rust byte replay on the generated fixture stack. This slice does not -serve narrative reports or claim DynamoDB/provider parity. +serve narrative reports or claim DynamoDB/provider parity. PostgreSQL mode +extends this route as described in “PostgreSQL narrative reports” below. ### Delphi visualization jobs @@ -1448,3 +1450,27 @@ queue-rs/polis-api/conformance/delphi-topics-pg-run.sh /tmp/topics-results.json The runner replays the unchanged Postgres baseline and checks Rust response bytes, served/fallback counters, overwrites, ordering, nulls, publication replacement and an explicit bounded fallback. Images use generated fixtures only. + +## PostgreSQL narrative reports + +With the existing `POLIS_API_DELPHI_REPORTS_READS=1` and +`RUST_API_ROUTES=delphiReports` switches, `DELPHI_RESULT_BACKEND=postgres` +enables bounded reads of `/api/v3/delphi/reports`. Both switches remain off by +default. The response preserves Node's public access, job selection, section +filters, property ordering and stored timestamp strings, including microseconds +and offset spelling. No timestamp is converted to a Date. The latest timestamp +within each run uses string comparison; run ordering uses Node's characterized +timestamp collation. Unsupported characters remain on Node. + +`POLIS_API_DELPHI_NARRATIVES_DATABASE_URL` selects an independent two-connection +result pool; `POLIS_API_DELPHI_REPORTS_DATABASE_URL` selects the separate +one-connection validation pool. Both URLs must use the same primary as Node. +The result login requires EXECUTE on `pd_result_page` and SELECT on `reports`; +sessions are read-only. No participation pool is used. Requests hand back to +Node on a pool/query failure, conflicting scopes, unsupported values, more than +1000 family rows, over 512 KiB of input, or over 1 MiB of output. The complete +request deadline is 750 ms, with a 200 ms result statement timeout. + +`conformance/delphi-reports-pg-run.sh` runs the unchanged Postgres baseline plus +native publication, timestamp, grouping, filter and bounded-handoff checks. +It requires unique compose/port settings and the three local fixture images. diff --git a/queue-rs/polis-api/conformance/delphi-reports-pg-check.cjs b/queue-rs/polis-api/conformance/delphi-reports-pg-check.cjs new file mode 100644 index 000000000..e8108098e --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-reports-pg-check.cjs @@ -0,0 +1,85 @@ +"use strict"; +const fs=require("node:fs"),path=require("node:path"); +exports.start=async function(context) { + const prior=await require("./delphi-topics-pg-check.cjs").start(context); + const {request,serialize,keys,database,oidc}=context; + const port=Number(process.env.P2ZERO_RUST_PORT||5100),captures=[],handoffs=[]; + async function compare(c,token,node) { + const rust=serialize(c,await request(c.path,token,port)); + captures.push({case:c.id,node:JSON.parse(node),rust:JSON.parse(rust),equal:node===rust}); + fs.writeFileSync(path.join(keys,"reports-captures.json"),JSON.stringify(captures,null,2)+"\n"); + } + return { + matches(c){return prior.matches(c)||c.route==="GET /api/v3/delphi/reports";}, + async compare(c,token,node){if(c.route==="GET /api/v3/delphi/reports")await compare(c,token,node);else await prior.compare(c,token,node);}, + async finish(){ + await prior.finish(); + const priorResults=JSON.parse(fs.readFileSync(path.join(keys,"results.json"))); + const {createRequire}=require("node:module"),{Client}=createRequire(path.resolve(process.cwd(),"package.json"))("pg"); + const {publish}=require(path.resolve(process.cwd(),"__tests__/delphi-results-pg/support.ts")); + const db=new Client({connectionString:database});await db.connect(); + const query="/api/v3/delphi/reports?report_id=r2p2zero105",family="Delphi_NarrativeReports"; + async function check(id,url,token,verify){ + const c={id:`reports/${id}`,state:"supplemental",route:"GET /api/v3/delphi/reports",path:url,auth:token?"other":"none"}; + const n=await request(url,token);if(n.status!==200)throw Error(`${id}: Node ${n.status}`); + if(verify)verify(JSON.parse(n.body));await compare(c,token,serialize(c,n)); + } + const narrative=(section,job,ts,model="m")=>({report_id:{S:"r2p2zero105"},rid_section_model:{S:`r2p2zero105#${section}#${model}`},job_id:{S:job},timestamp:{S:ts},model:{S:model},report_data:{S:"generated narrative"}}); + let rows=[narrative("global_old","old","2023-11-14T00:00:00Z"),narrative("10","new","2023-11-15T00:00:00Z"),narrative("2","new","2023-11-15T00:00:01Z"),narrative("10","new","2023-11-15T00:00:02Z","second")]; + rows[3].errors={NULL:true};rows[3].metadata={M:{nested:{L:[{BOOL:true},{N:"0.25"},{S:"generated"}]},"10":{S:"ten"},"2":{S:"two"}}}; + let previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,families:{[family]:rows}}); + await check("latest-collisions-order",query,null,b=>{if(b.current_job_id!=="new"||Object.keys(b.reports).join()!=="2,10"||b.reports[10].model!=="second"||b.available_runs[0].sectionCount!==3||b.reports[10].errors!==null)throw Error("group fixture");}); + await check("auth-ignored",query,oidc("p2zero|other","other@example.invalid")); + await check("old-job",query+"&job_id=old",null,b=>{if(b.current_job_id!=="old")throw Error("old job");}); + await check("missing-job",query+"&job_id=missing",null,b=>{if(Object.keys(b.reports).length||b.available_runs.some(r=>r.isCurrent))throw Error("missing job");}); + await check("section-substring",query+"&job_id=old§ion=global",null,b=>{if(!b.reports.global)throw Error("substring");}); + await check("section-missing",query+"§ion=absent",null,b=>{if(Object.keys(b.reports.absent).length)throw Error("section missing");}); + await check("topic-wrapper-data",query+"§ion=10&topic_key=metadata",null,b=>{if(b.data.nested[1]!==0.25)throw Error("topic wrapper");}); + await check("topic-missing",query+"§ion=10&topic_key=absent",null,b=>{if(b.message!=="Topic report not found")throw Error("missing topic");}); + rows=[narrative("undefined","current","2023-11-15T00:00:00Z")]; + previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:rows}}); + await check("unmatched-section-undefined",query+"§ion=zzz",null,b=>{if(b.reports.zzz.section!=="undefined"||b.reports.zzz.report_data!=="generated narrative")throw Error("undefined section fallback");}); + await check("unmatched-topic-no-undefined-fallback",query+"§ion=zzz&topic_key=report_data",null,b=>{if(b.message!=="Topic report not found")throw Error("topic direct lookup");}); + for(const value of ["%", "%FF", "a%zz%41", "%C3"]){ + const url=query+"§ion="+value,n=await request(url,null),r=await request(url,null,port); + if(n.status!==200||r.status!==502)throw Error(`query decoding handback ${value}: ${n.status}/${r.status}`); + const body=JSON.parse(n.body); + if(!Object.prototype.hasOwnProperty.call(body.reports,value))throw Error("Node raw query decoding"); + handoffs.push({case:`reports-query-decoding-${value}`,nodeStatus:n.status,rustStatus:r.status,nodeBytes:n.body.length}); + } + rows=[narrative("a","2","2023-11-15T00:00:00Z"),narrative("b","1","2023-11-15T00:00:00Z")];delete rows[0].job_id;rows[0].report_data={BOOL:false};rows[0].metadata={NULL:true}; + previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:rows}}); + await check("missing-job-and-falsy",query+"&job_id=unknown_job_2023-11-15",null,b=>{if(b.reports.a.report_data!==""||"job_id" in b.reports.a)throw Error("falsy");}); + // Narrative timestamps are strings throughout the adapter and handler. + // This catches Date conversion, millisecond truncation, offset rewriting, + // and accidentally using byte order for localeCompare's timezone signs. + const timestamps=["2023-11-14T19:51:01-01:00","2023-11-14T19:51:01+01:00","2023-11-14T19:51:01.000001+00:00","2023-11-14T19:51:01.000008+00:00","2023-11-14T19:51:01Z"]; + if([..."-:.+0123456789TZ"].sort((a,b)=>a.localeCompare(b)).join("")!=="-:.+0123456789TZ")throw Error("Node timestamp collation changed"); + rows=timestamps.map((ts,i)=>narrative(`s${i}`,`j${i}`,ts)); + previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:rows}}); + await check("timestamp-string-run-order",query,null,b=>{ + if(b.available_runs.map(r=>r.job_id).join()!=="j4,j1,j3,j2,j0")throw Error("timestamp collation order"); + for(const run of b.available_runs)if(run.latest_timestamp!==timestamps[Number(run.job_id.slice(1))])throw Error("timestamp spelling"); + }); + await check("timestamp-microseconds",query+"&job_id=j2",null,b=>{if(b.reports.s2.timestamp!==timestamps[2])throw Error("timestamp precision");}); + await check("timestamp-wrapper",query+"&job_id=j3§ion=s3&topic_key=timestamp",null,b=>{if(b.data!==timestamps[3])throw Error("timestamp wrapper spelling");}); + rows=[narrative("a","same",timestamps[0]),narrative("b","same",timestamps[1])]; + previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:rows}}); + await check("timestamp-within-run-maximum",query,null,b=>{if(b.available_runs[0].latest_timestamp!==timestamps[0])throw Error("timestamp byte maximum");}); + previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:[]}}); + await check("empty-publication",query,null,b=>{if("available_runs" in b)throw Error("empty shape");}); + rows=Array.from({length:1001},(_,i)=>narrative(`section_${String(i).padStart(4,"0")}`,"generated-bounded","2023-11-15T00:00:00Z")); + previous=await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:rows}}); + async function handoff(id){const n=await request(query,null),r=await request(query,null,port);if(n.status!==200||r.status!==502)throw Error(`${id}: bounded handback ${n.status}/${r.status}`);handoffs.push({case:id,nodeStatus:n.status,rustStatus:r.status,nodeBytes:n.body.length});} + await handoff("reports-row-bound"); + rows=[narrative("oversized","generated-bounded","2023-11-15T00:00:00Z")];rows[0].report_data={S:"x".repeat(600000)}; + await publish(db,{env:"p2zero",scope:"delphi",zid:105,previous,families:{[family]:rows}}); + await handoff("reports-input-byte-bound"); + await db.end(); + const counters=JSON.parse((await request("/health",null,port)).body),all=[...priorResults.captures,...captures],failures=all.filter(c=>!c.equal); + fs.writeFileSync(path.join(keys,"results.json"),JSON.stringify({cases:all.length,equal:all.length-failures.length,failures:failures.length,reports:captures.length,counters,captures:all,handoffs:[...priorResults.handoffs,...handoffs]},null,2)+"\n"); + console.log(`Rust Delphi reports: ${captures.length} cases; combined ${all.length} cases, ${failures.length} differences`); + if(failures.length)throw Error(`Rust reports byte differences: ${failures.map(c=>c.case).join(", ")}`); + } + }; +}; diff --git a/queue-rs/polis-api/conformance/delphi-reports-pg-compose.yml b/queue-rs/polis-api/conformance/delphi-reports-pg-compose.yml new file mode 100644 index 000000000..231db8eeb --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-reports-pg-compose.yml @@ -0,0 +1,75 @@ +services: + postgres: + image: ${DELPHI_REPORTS_PG_POSTGRES_IMAGE:?set a fixture Postgres image} + environment: {POSTGRES_HOST_AUTH_METHOD: trust} + ports: ["127.0.0.1:${POLIS_RECOVERY_PG_PORT:?set a unique port}:5432"] + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 2s + timeout: 2s + retries: 30 + dynamodb: + image: amazon/dynamodb-local:3.3.1@sha256:ff89bd48ff32cd8d9be5fee8873b65b8854dc408f1afe881be6eb00247bc0dab + command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-inMemory"] + recorder: + image: ${DELPHI_REPORTS_PG_NODE_IMAGE:?set a Node image} + working_dir: /app + entrypoint: [sh, -c] + command: ["cp -a /candidate/. /app/; exec node characterization/delphi/main.cjs replay"] + volumes: + - ${DELPHI_REPORTS_PG_SOURCE}/server:/candidate:ro + - ${DELPHI_REPORTS_PG_SOURCE}/delphi:/delphi + - ${DELPHI_REPORTS_PG_SOURCE}/queue-rs:/queue-rs:ro + - ${DELPHI_REPORTS_PG_SCRATCH}:/proof + environment: + P2ZERO_PG_ADMIN_URL: postgres://postgres@postgres:5432/postgres + DYNAMODB_ENDPOINT: http://dynamodb:8000 + DELPHI_RESULT_BACKEND: postgres + P2ZERO_RUST_KEYS: /proof + P2ZERO_RUST_CHECK: reports + TZ: UTC + depends_on: + postgres: {condition: service_healthy} + dynamodb: {condition: service_started} + polis-api: + image: ${DELPHI_REPORTS_PG_API_IMAGE:?set a fixture-clock API image} + network_mode: service:recorder + entrypoint: [sh, -c] + command: ["while [ ! -f /proof/ready ]; do sleep 1; done; exec /usr/local/bin/polis-api"] + volumes: ["${DELPHI_REPORTS_PG_SCRATCH}:/proof:ro"] + environment: + DATABASE_URL: postgres://postgres@postgres:5432/p2zero + DATABASE_SSL: 'false' + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + MATH_ENV: p2zero + DEV_MODE: 'true' + POLIS_API_DELPHI_LOGS_DATABASE_URL: postgres://generated_logs_reader@postgres:5432/p2zero + POLIS_API_DELPHI_LOGS_AUTH_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_LOGS_READS: '1' + POLIS_API_DELPHI_READS: '1' + POLIS_API_DELPHI_REPORTS_READS: '1' + POLIS_API_DELPHI_REPORTS_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_NARRATIVES_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_TOPICS_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_VISUALIZATIONS_READS: '1' + POLIS_API_DELPHI_VISUALIZATIONS_DATABASE_URL: postgres://postgres@postgres:5432/p2zero + POLIS_API_DELPHI_VISUALIZATIONS_RESULTS_DATABASE_URL: postgres://generated_viz_reader@postgres:5432/p2zero + DELPHI_RESULT_BACKEND: postgres + DELPHI_RESULT_ENV: p2zero + DELPHI_RESULT_SCOPE: delphi + POLIS_API_READ_JWKS_FILE: /proof/jwks.json + POLIS_API_PARTICIPANT_READS: '1' + POLIS_API_PARTICIPANT_PUBLIC_KEY_FILE: /proof/participant.pem + POLIS_API_FIXTURE_CLOCK: '1700000000000' + AUTH_ISSUER: https://oidc.p2zero.invalid/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ + POLIS_JWT_ISSUER: https://pol.is/ + POLIS_JWT_AUDIENCE: participants + ADMIN_UIDS: '[2]' + DOMAIN_OVERRIDE: localhost + SERVICE_URL: http://localhost + NODE_ENV: production + TZ: UTC diff --git a/queue-rs/polis-api/conformance/delphi-reports-pg-run.sh b/queue-rs/polis-api/conformance/delphi-reports-pg-run.sh new file mode 100755 index 000000000..203952517 --- /dev/null +++ b/queue-rs/polis-api/conformance/delphi-reports-pg-run.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Postgres baseline and native narrative results; all services are disposable fixtures. +# Requires three local images (Node, migration Postgres, fixture-clock polis-api). +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:?provide a results JSON path} +: "${COMPOSE_PROJECT_NAME:?set a unique project}" +: "${POLIS_RECOVERY_PG_PORT:?set a unique port}" +export RECOVERY_PG_PORT="$POLIS_RECOVERY_PG_PORT" +export DELPHI_REPORTS_PG_SOURCE="$root" +export DELPHI_REPORTS_PG_SCRATCH=${DELPHI_REPORTS_PG_SCRATCH:-$(mktemp -d)} +mkdir -p "$DELPHI_REPORTS_PG_SCRATCH" +[[ -z $(ls -A "$DELPHI_REPORTS_PG_SCRATCH") ]] || { echo "scratch must be empty" >&2; exit 2; } +compose=(docker compose -f "$root/queue-rs/polis-api/conformance/delphi-reports-pg-compose.yml") +[[ -z $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]] || { echo "project already exists" >&2; exit 2; } +cleanup() { + "${compose[@]}" logs --no-color >"${out%.json}-services.log" 2>&1 || true + "${compose[@]}" down -v --remove-orphans >/dev/null 2>&1 || true +} +trap cleanup EXIT INT TERM +"${compose[@]}" up -d --pull never postgres dynamodb recorder polis-api +cid=$("${compose[@]}" ps -aq recorder) +result=$(docker wait "$cid") +"${compose[@]}" logs --no-color recorder +docker cp "$cid:/proof/results.json" "$out" +exit "$result" diff --git a/queue-rs/polis-api/conformance/nginx-routing.sh b/queue-rs/polis-api/conformance/nginx-routing.sh index 8746113d2..392a09bf4 100755 --- a/queue-rs/polis-api/conformance/nginx-routing.sh +++ b/queue-rs/polis-api/conformance/nginx-routing.sh @@ -1088,6 +1088,7 @@ expect /api/v3/comments node "Delphi narrative report validation leaves comments expect /api/v3/votes node "Delphi narrative report validation leaves voting alone" [[ $(included | grep -c 'location = /api/v3/delphi/reports') == 1 ]] || fail "Delphi narrative report validation duplicated" expect_upstream polis-api GET /api/v3/delphi/reports +expect_upstream polis-api GET '/api/v3/delphi/reports?report_id=generated&job_id=old§ion=global&topic_key=report_data' $'Authorization: Bearer generated\r\n' expect_upstream polis-api HEAD /api/v3/delphi/reports expect_upstream server OPTIONS /api/v3/delphi/reports expect_upstream server POST /api/v3/delphi/reports $'Content-Length: 2\r\n' '{}' diff --git a/queue-rs/polis-api/src/delphi_narratives.rs b/queue-rs/polis-api/src/delphi_narratives.rs new file mode 100644 index 000000000..eea14d68d --- /dev/null +++ b/queue-rs/polis-api/src/delphi_narratives.rs @@ -0,0 +1,463 @@ +//! Bounded legacy narrative reads on a pool independent of participation. +use crate::{ + delphi_reports::contract, + wire::{JsMap, JsNumber, Json}, +}; +use anyhow::{Result, ensure}; +use serde_json::Value; +use std::collections::BTreeMap; + +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 2, + statement_timeout: std::time::Duration::from_millis(200), + ..crate::delphi_reports::pool_limits() + } +} + +pub async fn answer(app: &crate::route::App, query: contract::Request) -> Option { + let report = query.report_id.as_ref()?.clone(); + let rid = report.clone(); + let env = app.delphi_narratives_env.clone(); + let scope = app.delphi_narratives_scope.clone(); + let items=app.delphi_narratives_db.as_ref()?.with(move |c| { + // One complete, bounded family snapshot: an oversized family stays on + // Node, so its paginated reads are never replaced by a partial result. + let rows=c.query("WITH page AS MATERIALIZED (SELECT item_key::text AS item_key,item::text AS item,ordinality FROM public.pd_result_page($1,ARRAY(SELECT zid FROM reports WHERE report_id=$2),$3,'Delphi_NarrativeReports',NULL,NULL,NULL,NULL,false,1001) WITH ORDINALITY), bounded AS (SELECT *,sum(octet_length(item_key)+octet_length(item)) OVER () <= 524288 AS fits FROM page) SELECT CASE WHEN fits THEN item_key END,CASE WHEN fits THEN item END FROM bounded ORDER BY ordinality", &[&env,&rid,&scope])?; + ensure!(rows.len()<=1000,"result row bound"); + let mut seen=BTreeMap::::new(); + let mut items=Vec::new(); + for row in rows { + let key:String=row.try_get(0)?; + let text:String=row.try_get(1)?; + let item:Value=serde_json::from_str(&text)?; + if let Some(prior)=seen.insert(key,item.clone()) {ensure!(prior==item,"ambiguous result scopes");continue;} + // Decode every attribute, including fields not present in output. + let decoded=decode_object(&item)?; + let Some(Json::String(id))=decoded.get("report_id") else {continue}; + if id!=&rid {continue;} + let Some(ts)=string(&decoded,"timestamp")? else {continue}; + let key=string(&decoded,"rid_section_model")?.ok_or_else(||anyhow::anyhow!("missing key"))?; + ensure!(ts.is_ascii() && key.is_ascii(),"index ordering"); + items.push((ts,key,decoded)); + } + items.sort_by(|a,b| a.0.cmp(&b.0).then_with(||a.1.cmp(&b.1))); + Ok(items.into_iter().map(|(_,_,item)|item).collect::>()) + }).await.ok()?; + let body = response(items, &query).ok()?; + (body.len() <= 1024 * 1024).then_some(body) +} +fn decode_object(item: &Value) -> Result> { + let m = item + .as_object() + .ok_or_else(|| anyhow::anyhow!("invalid object"))?; + // JSONB emits keys by UTF-8 byte length, then byte value; the Node + // decoder retains that order before JavaScript integer-key enumeration. + let mut fields: Vec<_> = m.iter().collect(); + fields.sort_by(|(a, _), (b, _)| { + a.len() + .cmp(&b.len()) + .then_with(|| a.as_bytes().cmp(b.as_bytes())) + }); + JsMap::try_from_entries( + fields + .into_iter() + .map(|(k, v)| Ok((k.clone(), decode(v)?))) + .collect::>>()?, + ) + .map_err(Into::into) +} +fn decode(v: &Value) -> Result { + let m = v + .as_object() + .ok_or_else(|| anyhow::anyhow!("invalid attribute"))?; + ensure!(m.len() == 1, "ambiguous attribute"); + if let Some(s) = v.get("S").and_then(Value::as_str) { + return Ok(Json::String(s.into())); + } + if let Some(b) = v.get("BOOL").and_then(Value::as_bool) { + return Ok(Json::Bool(b)); + } + if v.get("NULL") == Some(&Value::Bool(true)) { + return Ok(Json::Null); + } + if let Some(s) = v.get("N").and_then(Value::as_str) { + let n: f64 = s.parse()?; + ensure!( + n.is_finite() && (n.fract() != 0.0 || n.abs() <= 9_007_199_254_740_991.0), + "numeric reader precision" + ); + return Ok(Json::Number(JsNumber::new(n)?)); + } + if let Some(l) = v.get("L").and_then(Value::as_array) { + return Ok(Json::Array(l.iter().map(decode).collect::>()?)); + } + if let Some(m) = v.get("M") { + return Ok(Json::Object(decode_object(m)?)); + } + anyhow::bail!("unsupported attribute") +} +fn string(row: &JsMap, key: &str) -> Result> { + match row.get(key) { + None | Some(Json::Null) => Ok(None), + Some(Json::String(s)) => Ok(Some(s.clone())), + _ => anyhow::bail!("unsupported string coercion"), + } +} +fn truthy(j: &Json) -> bool { + match j { + Json::Null => false, + Json::Bool(b) => *b, + Json::String(s) => !s.is_empty(), + Json::Number(n) => n.get() != 0.0, + _ => true, + } +} +fn or(row: &JsMap, key: &str, default: Json) -> Json { + row.get(key) + .filter(|v| truthy(v)) + .cloned() + .unwrap_or(default) +} +fn safe_key(k: &str) -> Result<()> { + ensure!( + !matches!( + k, + "__proto__" + | "constructor" + | "prototype" + | "toString" + | "valueOf" + | "hasOwnProperty" + | "isPrototypeOf" + | "propertyIsEnumerable" + | "toLocaleString" + | "__defineGetter__" + | "__defineSetter__" + | "__lookupGetter__" + | "__lookupSetter__" + ), + "inherited property" + ); + Ok(()) +} +fn ordered(v: Vec<(String, T)>) -> Result> { + Ok(JsMap::try_from_entries(v)?) +} +// Default Node/ICU collation for the bounded timestamp alphabet. Do not +// parse dates: doing so loses microseconds and changes the legacy ordering. +// Other alphabets stay on Node until their collation is characterized. +fn timestamp_key(value: &str) -> Option> { + if value.len() > 64 { + return None; + } + value + .bytes() + .map(|b| match b { + b'-' => Some(0), + b':' => Some(1), + b'.' => Some(2), + b'+' => Some(3), + b'0'..=b'9' => Some(4 + b - b'0'), + b'T' => Some(14), + b'Z' => Some(15), + _ => None, + }) + .collect() +} +fn response(items: Vec>, q: &contract::Request) -> Result { + let rid = q + .report_id + .as_ref() + .ok_or_else(|| anyhow::anyhow!("missing report"))? + .clone(); + if items.is_empty() { + return Ok(crate::wire::to_json(&contract::ReportsResponse { + status: contract::Status::Success, + message: "No reports found for the given report identifier.", + request_report_id: rid.clone(), + queried_gsi_report_id: rid, + reports: JsMap::new(), + current_job_id: None, + available_runs: None, + })?); + } + let mut groups: Vec<(String, Vec>)> = Vec::new(); + for item in items { + let ts = string(&item, "timestamp")?.unwrap_or_default(); + // These are stored strings, not JavaScript Dates. Preserve every + // fractional digit and the original offset in both response fields. + ensure!(timestamp_key(&ts).is_some(), "locale timestamp ordering"); + let job = string(&item, "job_id")? + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| { + format!( + "unknown_job_{}", + if ts.is_empty() { + "nodate" + } else { + &ts[..ts.len().min(10)] + } + ) + }); + safe_key(&job)?; + if let Some((_, g)) = groups.iter_mut().find(|(k, _)| k == &job) { + g.push(item); + } else { + groups.push((job, vec![item])); + } + } + // Object.keys enumerates integer job ids before sorting. Stable sorting + // keeps that order when the latest timestamps compare equal. + let ordered_groups = ordered(groups)?; + let mut groups: Vec<_> = ordered_groups + .iter() + .map(|(k, v)| (k.clone(), v.clone())) + .collect(); + let latest = |rows: &Vec>| { + rows.iter() + .filter_map(|r| match r.get("timestamp") { + Some(Json::String(s)) => Some(s.as_str()), + _ => None, + }) + .max() + .unwrap_or("") + .to_owned() + }; + // The latest item uses JavaScript > (ASCII here), whereas run ordering + // uses localeCompare. In particular '-' sorts before '+' only in the + // latter. The admitted alphabet has distinct primary collation weights. + groups.sort_by_cached_key(|(_, rows)| std::cmp::Reverse(timestamp_key(&latest(rows)))); + let current = q.job_id.clone().unwrap_or_else(|| groups[0].0.clone()); + safe_key(¤t)?; + let mut sections: Vec<(String, contract::Section)> = Vec::new(); + if let Some((_, rows)) = groups.iter().find(|(k, _)| k == ¤t) { + for row in rows { + let key = string(row, "rid_section_model")?.unwrap_or_default(); + let parts: Vec<_> = key.split('#').collect(); + if parts.len() < 2 { + continue; + } + let name = parts[1].to_string(); + safe_key(&name)?; + let section = contract::Section { + section: name.clone(), + model: parts.get(2).unwrap_or(&"unknown").to_string(), + timestamp: or(row, "timestamp", Json::String(String::new())), + report_data: or(row, "report_data", Json::String(String::new())), + errors: row.get("errors").cloned(), + job_id: row.get("job_id").cloned(), + metadata: or(row, "metadata", Json::Null), + }; + if let Some((_, old)) = sections.iter_mut().find(|(k, _)| k == &name) { + *old = section; + } else { + sections.push((name, section)); + } + } + } + let sections = ordered(sections)?; + if let Some(section) = &q.section { + safe_key(section)?; + } + if let (Some(section), Some(topic)) = (&q.section, &q.topic_key) { + safe_key(topic)?; + let data = if let Some(s) = sections.get(section) { + let encoded = crate::wire::to_json(s)?; + let Json::Object(o) = serde_json::from_str::(&encoded)? else { + unreachable!() + }; + o.get(topic).filter(|v| truthy(v)).cloned() + } else { + None + }; + return Ok(crate::wire::to_json(&contract::TopicResponse { + status: if data.is_some() { + contract::Status::Success + } else { + contract::Status::Error + }, + message: if data.is_some() { + "Topic report retrieved successfully" + } else { + "Topic report not found" + }, + request_report_id: rid.clone(), + queried_gsi_report_id: rid, + section: section.clone(), + topic_key: topic.clone(), + data, + })?); + } + let encode = |s: &contract::Section| -> Result { + Ok(serde_json::from_str(&crate::wire::to_json(s)?)?) + }; + let reports = if let Some(filter) = &q.section { + let selected = sections + .get(filter) + .or_else(|| { + sections + .iter() + .find(|(k, _)| k.contains(filter)) + .map(|(_, v)| v) + }) + .or_else(|| sections.get("undefined")); + ordered(vec![( + filter.clone(), + selected + .map(encode) + .transpose()? + .unwrap_or(Json::Object(JsMap::new())), + )])? + } else { + ordered( + sections + .iter() + .map(|(k, v)| Ok((k.clone(), encode(v)?))) + .collect::>>()?, + )? + }; + let available_runs = groups + .iter() + .map(|(job, rows)| contract::Run { + job_id: job.clone(), + latest_timestamp: latest(rows), + model: or(&rows[0], "model", Json::String("unknown".into())), + section_count: rows.len(), + is_current: job == ¤t, + }) + .collect(); + Ok(crate::wire::to_json(&contract::ReportsResponse { + status: contract::Status::Success, + message: "Reports retrieved successfully", + request_report_id: rid.clone(), + queried_gsi_report_id: rid, + reports, + current_job_id: Some(current), + available_runs: Some(available_runs), + })?) +} +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + fn row(job: &str, section: &str, ts: &str) -> JsMap { + decode_object(&json!({"job_id":{"S":job},"rid_section_model":{"S":format!("r#{section}#m")},"timestamp":{"S":ts},"report_data":{"S":"generated"}})).unwrap() + } + fn query() -> contract::Request { + contract::Request { + report_id: Some("r".into()), + ..Default::default() + } + } + #[test] + fn timestamp_strings_keep_microseconds_offsets_and_zero_padding() { + let older = "2023-11-14T19:51:01.000001+00:00"; + let newer = "2023-11-14T19:51:01.000008+00:00"; + let r = response( + vec![row("old", "a", older), row("new", "b", newer)], + &query(), + ) + .unwrap(); + let body: Value = serde_json::from_str(&r).unwrap(); + assert_eq!(body["reports"]["b"]["timestamp"], newer); + assert_eq!(body["available_runs"][0]["latest_timestamp"], newer); + assert_eq!(body["available_runs"][1]["latest_timestamp"], older); + let mut q = query(); + q.section = Some("b".into()); + q.topic_key = Some("timestamp".into()); + let r = response(vec![row("new", "b", newer)], &q).unwrap(); + assert_eq!(serde_json::from_str::(&r).unwrap()["data"], newer); + } + #[test] + fn run_order_uses_string_collation_not_instants_or_millisecond_dates() { + let timestamps = [ + "2023-11-14T19:51:01-01:00", + "2023-11-14T19:51:01+01:00", + "2023-11-14T19:51:01.000001+00:00", + "2023-11-14T19:51:01.000008+00:00", + "2023-11-14T19:51:01Z", + ]; + let items = timestamps + .iter() + .enumerate() + .map(|(i, t)| row(&format!("j{i}"), "s", t)) + .collect(); + let body: Value = serde_json::from_str(&response(items, &query()).unwrap()).unwrap(); + let jobs: Vec<_> = body["available_runs"] + .as_array() + .unwrap() + .iter() + .map(|r| r["job_id"].as_str().unwrap()) + .collect(); + assert_eq!(jobs, ["j4", "j1", "j3", "j2", "j0"]); + // Within a run the handler chooses the maximum with JavaScript >, + // which differs from localeCompare for the timezone sign. + let body: Value = serde_json::from_str( + &response( + vec![ + row("same", "a", timestamps[0]), + row("same", "b", timestamps[1]), + ], + &query(), + ) + .unwrap(), + ) + .unwrap(); + assert_eq!(body["available_runs"][0]["latest_timestamp"], timestamps[0]); + } + #[test] + fn latest_job_and_duplicate_sections_keep_legacy_order() { + let r = response( + vec![ + row("old", "s", "2023-11-14T00:00:00Z"), + row("new", "10", "2023-11-15T00:00:00Z"), + row("new", "2", "2023-11-15T00:00:01Z"), + row("new", "10", "2023-11-15T00:00:02Z"), + ], + &query(), + ) + .unwrap(); + assert!(r.contains("\"current_job_id\":\"new\"")); + assert!(r.find("\"2\":").unwrap() < r.find("\"10\":").unwrap()); + assert!(r.contains("\"sectionCount\":3")); + assert!(!r.contains("\"errors\"")); + assert!(r.contains("\"metadata\":null")); + } + #[test] + fn requested_missing_job_and_section_return_empty_object() { + let mut q = query(); + q.job_id = Some("absent".into()); + q.section = Some("missing".into()); + let r = response(vec![row("old", "s", "2023-11-14T00:00:00Z")], &q).unwrap(); + assert!(r.contains("\"reports\":{\"missing\":{}}")); + assert!(r.contains("\"isCurrent\":false")); + q.job_id = Some("__proto__".into()); + assert!(response(vec![row("old", "s", "2023-11-14T00:00:00Z")], &q).is_err()); + } + #[test] + fn reports_review_unmatched_section_uses_undefined_section() { + let mut q = query(); + q.section = Some("zzz".into()); + let rows = || vec![row("j", "undefined", "2023-11-14T00:00:00Z")]; + let body: Value = serde_json::from_str(&response(rows(), &q).unwrap()).unwrap(); + assert_eq!(body["reports"]["zzz"]["report_data"], "generated"); + assert_eq!(body["reports"]["zzz"]["section"], "undefined"); + // Topic lookup uses the section directly, without this fallback. + q.topic_key = Some("report_data".into()); + let body: Value = serde_json::from_str(&response(rows(), &q).unwrap()).unwrap(); + assert_eq!(body["message"], "Topic report not found"); + } + #[test] + fn topic_filter_reads_wrapper_property_and_preserves_null() { + let mut q = query(); + q.section = Some("s".into()); + q.topic_key = Some("report_data".into()); + let r = response(vec![row("j", "s", "2023-11-14T00:00:00Z")], &q).unwrap(); + assert!(r.contains("\"data\":\"generated\"")); + q.topic_key = Some("metadata".into()); + let r = response(vec![row("j", "s", "2023-11-14T00:00:00Z")], &q).unwrap(); + assert!(r.contains("Topic report not found")); + assert!(decode(&json!({"N":"9007199254740992"})).is_err()); + } +} diff --git a/queue-rs/polis-api/src/delphi_reports.rs b/queue-rs/polis-api/src/delphi_reports.rs index 7289f74d4..35b9dfaa2 100644 --- a/queue-rs/polis-api/src/delphi_reports.rs +++ b/queue-rs/polis-api/src/delphi_reports.rs @@ -1,11 +1,11 @@ -//! Missing/unknown report validation only, on a separate bounded replica pool. +//! Legacy report validation and bounded narrative reads on independent pools. use crate::{ http::{Outgoing, Request}, route::{self, App, Res}, }; // Both workspaces compile the same shared contract module. #[path = "../../polis-contracts/src/delphi_reports.rs"] -mod contract; +pub(crate) mod contract; pub use contract::PATH; pub fn parse(app: &App, req: &Request) -> Option { if app.delphi_reports_db.is_none() @@ -14,34 +14,55 @@ pub fn parse(app: &App, req: &Request) -> Option { || !req.body.is_empty() || req.headers.get("transfer-encoding").is_some() || req.headers.get("content-length").is_some_and(|s| s != "0") - || req.headers.get("authorization").is_some() - || req.headers.get("cookie").is_some() + || (app.delphi_narratives_db.is_none() + && (req.headers.get("authorization").is_some() || req.headers.get("cookie").is_some())) { return None; } let raw = req.query().unwrap_or(""); - if raw.len() > 1024 { + // Express 3 keeps a value verbatim when decodeURIComponent throws. + // Malformed escapes, invalid UTF-8 and raw non-ASCII stay on Node. + let b = raw.as_bytes(); + if raw.len() > 1024 + || !raw.is_ascii() + || (0..b.len()).any(|i| { + b[i] == b'%' + && !(i + 2 < b.len() + && b[i + 1].is_ascii_hexdigit() + && b[i + 2].is_ascii_hexdigit()) + }) + { return None; } - let mut report_id = None; - let mut seen = false; + let mut query = contract::Request::default(); + let mut seen = std::collections::HashSet::new(); for (k, v) in url::form_urlencoded::parse(raw.as_bytes()) { - if k != "report_id" - || seen - || v.len() > 100 - || !v - .bytes() - .all(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'-') - { + if !seen.insert(k.to_string()) || v.len() > 256 || v.contains(['\0', '\u{FFFD}']) { return None; } - seen = true; - if !v.is_empty() { - report_id = Some(v.into_owned()); + if k == "report_id" { + if v.len() > 100 + || !v + .bytes() + .all(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'-') + { + return None; + } + query.report_id = (!v.is_empty()).then(|| v.into_owned()); + } else { + app.delphi_narratives_db.as_ref()?; + let value = (!v.is_empty()).then(|| v.into_owned()); + match k.as_ref() { + "section" => query.section = value, + "topic_key" => query.topic_key = value, + "job_id" => query.job_id = value, + _ => return None, + } } } - Some(contract::Request { report_id }) + Some(query) } + pub fn pool_limits() -> crate::db::Limits { crate::db::Limits { size: 1, @@ -54,38 +75,43 @@ pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { let Some(query) = parse(app, req) else { return route::bad_gateway(); }; - let value = match query.report_id { - None => contract::Request::missing(), - Some(id) => { - let Some(pool) = &app.delphi_reports_db else { - return route::bad_gateway(); - }; - let report_id = id.clone(); - // The Node resolver is uncached. Only absence qualifies: every existing - // report (including unusual/null/zero identifiers) stays with Node. - let Ok(Ok(false)) = tokio::time::timeout( - std::time::Duration::from_millis(75), - pool.with(move |c| { - Ok(!c - .query( - "SELECT zid FROM reports WHERE report_id=$1 LIMIT 1", - &[&report_id], - )? - .is_empty()) - }), - ) - .await - else { - return route::bad_gateway(); - }; - contract::Request::unknown(id) - } - }; - let Ok(encoded) = serde_json::to_string(&value) else { + let Ok(Some(body)) = tokio::time::timeout( + std::time::Duration::from_millis(if app.delphi_narratives_db.is_some() { + 750 + } else { + 75 + }), + answer(app, query), + ) + .await + else { return route::bad_gateway(); }; - let Ok(value) = crate::js::parse(&encoded) else { - return route::bad_gateway(); + route::json_text(req, res, 200, body) +} +async fn answer(app: &App, query: contract::Request) -> Option { + let Some(id) = &query.report_id else { + return crate::wire::to_json(&contract::Request::missing()).ok(); }; - route::json(req, res, &value) + let rid = id.clone(); + let row = app + .delphi_reports_db + .as_ref()? + .with(move |c| { + Ok(c.query_opt( + "SELECT zid FROM reports WHERE report_id=$1 LIMIT 1", + &[&rid], + )? + .map(|r| r.try_get::<_, Option>(0)) + .transpose()?) + }) + .await + .ok()?; + if row.is_some() && app.delphi_narratives_db.is_none() { + return None; + } + if row.flatten().is_none() { + return crate::wire::to_json(&contract::Request::unknown(id.clone())).ok(); + } + crate::delphi_narratives::answer(app, query).await } diff --git a/queue-rs/polis-api/src/main.rs b/queue-rs/polis-api/src/main.rs index a83c5d151..7a6d274d7 100644 --- a/queue-rs/polis-api/src/main.rs +++ b/queue-rs/polis-api/src/main.rs @@ -34,6 +34,7 @@ mod delphi_job_result; #[path = "../../polis-contracts/src/delphi_run.rs"] mod delphi_run; mod delphi_logs; +mod delphi_narratives; mod delphi_read; mod delphi_reports; mod delphi_result_read; @@ -732,6 +733,24 @@ async fn main() -> Result<()> { config::connector_for_dsn(&dsn, "polis-api-delphi-reports/1")?, delphi_reports::pool_limits(), )); + if std::env::var("DELPHI_RESULT_BACKEND").ok().as_deref() == Some("postgres") { + let dsn = std::env::var("POLIS_API_DELPHI_NARRATIVES_DATABASE_URL").context( + "POLIS_API_DELPHI_NARRATIVES_DATABASE_URL required for PostgreSQL narrative reads", + )?; + state.delphi_narratives_env = + std::env::var("DELPHI_RESULT_ENV").context("DELPHI_RESULT_ENV required")?; + anyhow::ensure!( + !state.delphi_narratives_env.is_empty(), + "DELPHI_RESULT_ENV cannot be empty" + ); + state.delphi_narratives_scope = std::env::var("DELPHI_RESULT_SCOPE") + .ok() + .filter(|s| !s.is_empty()); + state.delphi_narratives_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-delphi-narratives/1")?, + delphi_narratives::pool_limits(), + )); + } } if std::env::var("POLIS_API_DELPHI_VISUALIZATIONS_READS") .ok() diff --git a/queue-rs/polis-api/src/next_comment.rs b/queue-rs/polis-api/src/next_comment.rs index 58e60d5f3..942bc755b 100644 --- a/queue-rs/polis-api/src/next_comment.rs +++ b/queue-rs/polis-api/src/next_comment.rs @@ -589,6 +589,14 @@ mod tests { Connector::Plain(Box::new(pg.clone())), crate::delphi_topics::pool_limits(), )); + app.delphi_narratives_db = Some(db::Pool::new( + Connector::Plain(Box::new(pg.clone())), + crate::delphi_narratives::pool_limits(), + )); + app.delphi_reports_db = Some(db::Pool::new( + Connector::Plain(Box::new(pg.clone())), + crate::delphi_reports::pool_limits(), + )); let app = Arc::new(app); async fn park( pool: Arc, @@ -696,6 +704,7 @@ mod tests { app.delphi_logs_db.as_ref().unwrap(), app.delphi_visualizations_result_db.as_ref().unwrap(), app.delphi_topics_db.as_ref().unwrap(), + app.delphi_narratives_db.as_ref().unwrap(), ] { for _ in 0..2 { held.push(park(pool.clone()).await); @@ -708,6 +717,7 @@ mod tests { held.push(park(app.delphi_logs_auth_db.as_ref().unwrap().clone()).await); held.push(park(app.delphi_visualizations_db.as_ref().unwrap().clone()).await); held.push(park(app.delphi_read_db.as_ref().unwrap().clone()).await); + held.push(park(app.delphi_reports_db.as_ref().unwrap().clone()).await); let guarded = observe(app.clone()).await; eprintln!( "next statement isolation: deadline_ms={} control={control_sample:?} guarded={guarded:?} guarded/control={:.3}", diff --git a/queue-rs/polis-api/src/route.rs b/queue-rs/polis-api/src/route.rs index b6325f16c..b1d3b0bc1 100644 --- a/queue-rs/polis-api/src/route.rs +++ b/queue-rs/polis-api/src/route.rs @@ -140,6 +140,9 @@ pub struct App { pub read_oidc: Option>, pub contexts_served: AtomicU64, pub contexts_fallback: AtomicU64, + pub delphi_narratives_db: Option>, + pub delphi_narratives_env: String, + pub delphi_narratives_scope: Option, pub delphi_reports_db: Option>, pub delphi_reports_served: AtomicU64, pub delphi_reports_fallback: AtomicU64, @@ -343,6 +346,9 @@ impl App { read_oidc: None, contexts_served: AtomicU64::new(0), contexts_fallback: AtomicU64::new(0), + delphi_narratives_db: None, + delphi_narratives_env: String::new(), + delphi_narratives_scope: None, delphi_reports_db: None, delphi_reports_served: AtomicU64::new(0), delphi_reports_fallback: AtomicU64::new(0), @@ -5298,6 +5304,35 @@ mod tests { assert_eq!(state.delphi_reports_served.load(Ordering::Relaxed), 4); assert_eq!(state.delphi_reports_fallback.load(Ordering::Relaxed), 14); } + #[tokio::test] + async fn reports_review_query_decoding_hands_back_express_incompatible_values() { + let mut state = app(true); + let pool = state.db.clone(); + let inner = Arc::get_mut(&mut state).unwrap(); + inner.delphi_reports_db = Some(pool.clone()); + inner.delphi_narratives_db = Some(pool); + for field in ["section", "topic_key", "job_id"] { + for value in ["%", "%FF", "a%zz%41", "%C3", "%4", "a+%zz%41", "café"] { + let mut req = request("GET", &[("host", "localhost")]); + req.target = format!("/api/v3/delphi/reports?report_id=r&{field}={value}"); + assert!( + crate::delphi_reports::parse(&state, &req).is_none(), + "{field}={value}" + ); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + } + for value in ["a%20b", "a+b", "%25", "%E9%9B%AA", "%C3%A9"] { + let mut req = request("GET", &[("host", "localhost")]); + req.target = format!("/api/v3/delphi/reports?report_id=r§ion={value}"); + assert!( + crate::delphi_reports::parse(&state, &req).is_some(), + "{value}" + ); + } + assert_eq!(state.delphi_reports_fallback.load(Ordering::Relaxed), 21); + assert_eq!(state.delphi_reports_served.load(Ordering::Relaxed), 0); + } #[cfg(feature = "db-tests")] #[tokio::test] async fn delphi_reports_unknown_reports_use_independent_bounded_read_only_pool() { diff --git a/queue-rs/polis-contracts/src/delphi_reports.rs b/queue-rs/polis-contracts/src/delphi_reports.rs index 207d81d59..a39d95eac 100644 --- a/queue-rs/polis-contracts/src/delphi_reports.rs +++ b/queue-rs/polis-contracts/src/delphi_reports.rs @@ -5,11 +5,18 @@ pub const PATH: &str = "/api/v3/delphi/reports"; #[serde(deny_unknown_fields)] pub struct Request { pub report_id: Option, + #[serde(default)] + pub section: Option, + #[serde(default)] + pub topic_key: Option, + #[serde(default)] + pub job_id: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "lowercase")] pub enum Status { Error, + Success, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] @@ -36,3 +43,50 @@ impl Request { } } } + +use crate::wire::{JsMap, Json}; +#[derive(Debug, Clone, Serialize)] +pub struct Section { + pub section: String, + pub model: String, + pub timestamp: Json, + pub report_data: Json, + #[serde(skip_serializing_if = "Option::is_none")] + pub errors: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub job_id: Option, + pub metadata: Json, +} +#[derive(Debug, Clone, Serialize)] +pub struct Run { + pub job_id: String, + pub latest_timestamp: String, + pub model: Json, + #[serde(rename = "sectionCount")] + pub section_count: usize, + #[serde(rename = "isCurrent")] + pub is_current: bool, +} +#[derive(Debug, Clone, Serialize)] +pub struct ReportsResponse { + pub status: Status, + pub message: &'static str, + pub request_report_id: String, + pub queried_gsi_report_id: String, + pub reports: JsMap, + #[serde(skip_serializing_if = "Option::is_none")] + pub current_job_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub available_runs: Option>, +} +#[derive(Debug, Clone, Serialize)] +pub struct TopicResponse { + pub status: Status, + pub message: &'static str, + pub request_report_id: String, + pub queried_gsi_report_id: String, + pub section: String, + pub topic_key: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub data: Option, +} diff --git a/server/characterization/delphi/main.cjs b/server/characterization/delphi/main.cjs index aa8cc1337..75e27d855 100644 --- a/server/characterization/delphi/main.cjs +++ b/server/characterization/delphi/main.cjs @@ -438,7 +438,9 @@ async function main() { // Optional Rust conformance uses the unchanged fixture and recording oracle. const rust = process.env.P2ZERO_RUST_KEYS - ? await require(process.env.P2ZERO_RUST_CHECK === "topics" + ? await require(process.env.P2ZERO_RUST_CHECK === "reports" + ? "../../../queue-rs/polis-api/conformance/delphi-reports-pg-check.cjs" + : process.env.P2ZERO_RUST_CHECK === "topics" ? "../../../queue-rs/polis-api/conformance/delphi-topics-pg-check.cjs" : process.env.P2ZERO_RUST_CHECK === "visualizations" ? "../../../queue-rs/polis-api/conformance/delphi-visualizations-pg-check.cjs" From c7b2b8e2fc837680c18e10bd08a56c511f5953fd Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 17:00:50 -0700 Subject: [PATCH 05/30] cli: a participant's submission is a comment; a statement is a collective statement (#3233) CLI only (34 files); no server change. The participant command family is renamed: statement list, view and next become comment list, view and next; report statements list becomes report comments list; polis comment (submitting) and the collective statements commands are unchanged. Help text, README, tests and the differential census follow, including every user-visible error and help string that still said statement for a participant's comment. Reviewed independently: publish with edits (applied). Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- polis-cli/README.md | 92 ++++++++-------- polis-cli/admin-operations.json | 28 ++--- polis-cli/crates/polis/src/admin.rs | 4 +- polis-cli/crates/polis/src/commands.rs | 102 +++++++++--------- polis-cli/crates/polis/src/commenting.rs | 4 +- polis-cli/crates/polis/src/importance.rs | 8 +- polis-cli/crates/polis/src/main.rs | 14 +-- polis-cli/crates/polis/src/pass6.rs | 12 +-- polis-cli/crates/polis/src/pass7.rs | 15 ++- polis-cli/crates/polis/src/prioritize.rs | 4 +- polis-cli/crates/polis/src/reads.rs | 2 +- polis-cli/crates/polis/src/seeds.rs | 18 ++-- polis-cli/crates/polis/src/voting.rs | 4 +- polis-cli/crates/polis/tests/cli.rs | 2 +- .../crates/polis/tests/comment_naming.rs | 52 +++++++++ polis-cli/crates/polis/tests/commenting.rs | 2 +- polis-cli/crates/polis/tests/importance.rs | 18 ++-- polis-cli/crates/polis/tests/pass6.rs | 23 ++-- polis-cli/crates/polis/tests/pass7.rs | 33 +++--- polis-cli/crates/polis/tests/voting.rs | 2 +- polis-cli/docs/admin-operations.md | 32 +++--- polis-cli/docs/json-output.md | 26 ++--- polis-cli/docs/tutorial.txt | 22 ++-- polis-cli/tests/comment_live.py | 2 +- polis-cli/tests/differential/admin-verify.cjs | 4 +- polis-cli/tests/differential/admin_cases.py | 10 +- polis-cli/tests/differential/cases.py | 10 +- polis-cli/tests/differential/harness.py | 4 +- polis-cli/tests/differential/routes.json | 4 +- polis-cli/tests/differential/test_contract.py | 4 +- .../tests/differential/verify-participant.cjs | 2 +- polis-cli/tests/fuzz/generator.py | 10 +- polis-cli/tests/fuzz/known-differences.json | 2 +- polis-cli/tests/fuzz/test_generator.py | 4 +- polis-cli/tests/vote_live.py | 2 +- queue-rs/polis-contracts/src/upstream.rs | 6 +- 36 files changed, 318 insertions(+), 265 deletions(-) create mode 100644 polis-cli/crates/polis/tests/comment_naming.rs diff --git a/polis-cli/README.md b/polis-cli/README.md index 5d70868b4..f870ffb66 100644 --- a/polis-cli/README.md +++ b/polis-cli/README.md @@ -151,18 +151,18 @@ are preserved in canonical spelling; other IDs become deterministic UUIDv5 value from the normalized origin, conversation ID and exact external ID. Text is unchanged. `data.id_mapping` retains external and submitted IDs alongside `data.receipt`. The database UUID contract is unchanged; stable mapping is not a server idempotency -or automatic-retry guarantee. Statement text must be nonblank, contain +or automatic-retry guarantee. Comment text must be nonblank, contain no NUL, and fit 997 UTF-16 units. Duplicate text/IDs, blank records, malformed quoting, and unknown columns are rejected before HTTP. Text, whitespace, and embedded line breaks are preserved. No normalization or silent row dropping occurs. ```csv comment_text,original_id -A generated example statement,00000000-0000-4000-8000-000000000001 +A generated example comment,00000000-0000-4000-8000-000000000001 ``` Both `seed add` and `seed import` use `POST /api/v3/comments-bulk` with `is_seed=true`. -This endpoint enforces moderator permission; the ordinary statement endpoint's +This endpoint enforces moderator permission; the ordinary comment endpoint's seed-flag permission gap is deliberately not used. `seed add` generates a UUID. Imports are neither atomic nor assumed idempotent. `data.receipt` preserves the @@ -355,7 +355,7 @@ moderator-authorized XID mapping as CSV or JSON; this is not a full roster. `seed import seeds.csv --conversation --votes votes.csv --source-agree=+1` adds optional votes through the server's sign-aware importer. Declare the actual source -sign (+1 or -1); no default or CLI sign conversion. Statement and vote operations +sign (+1 or -1); no default or CLI sign conversion. Comment and vote operations are separate: keep their receipts, and treat `processing` as queued, not complete. The importer requires a target with no votes and a configured import worker. @@ -396,19 +396,19 @@ reads moderator event statistics, bounded to 8 MiB, without a report-ID fallback created report's ID as `report_id`, taken from the server's reply; a server that replies `{}` leaves it `null`. The accepted receipt and a readback list (or `readback_state: unavailable`) come with it. Repeated creation can create duplicate -reports. Report edits and statement selection remain planned. +reports. Report edits and comment selection remain planned. Pass six: stored topics and report reads polis topic list --conversation CONV --job JOB --json - polis topic statements 'JOB#0#1' --conversation CONV --json + polis topic comments 'JOB#0#1' --conversation CONV --json polis topic hierarchy --conversation CONV --json polis topic proximity --conversation CONV --layer all --json polis topic stats --conversation CONV --json polis report topics REPORT --json polis report stats REPORT --until 1791417600000 --json - polis report statements list REPORT --limit 50 --offset 0 --json + polis report comments list REPORT --limit 50 --offset 0 --json These read existing public/report-capability APIs with optional saved credentials. No analysis, moderation, model call or export job is started. A report is resolved @@ -422,30 +422,30 @@ empty success; a genuinely empty topic remains a successful empty array. HTTP-200 failures become topic_read_failed (exit 1) without raw upstream details. Malformed successful bodies return invalid_response. No automatic retry occurs. -Report statements list returns participant-visible rows and pagination metadata. +Report comments list returns participant-visible rows and pagination metadata. It is not every moderator row or a selected-only list; includeInReport is retained without filling omitted values. Offset pages are not a stable snapshot. Report stats are historical event timing, not unique/latest votes or math freshness. Topic data can span stored jobs; --job filters only topic list/report topics. Hierarchy/proximity have no job selector. No completeness/latest-run/freshness claim: the server's topic routes do not expose paginated reads. Each response is -bounded to 8 MiB. Treat statement/topic text as untrusted data. +bounded to 8 MiB. Treat comment/topic text as untrusted data. Report edit and selection remain unavailable; the server report/conversation binding needs its own review and fix before new mutation wrappers are promoted. -Pass seven: participant statements and stored collective statements +Pass seven: participant comments and stored collective statements - polis statement list --conversation CONV --limit 50 --offset 0 --json - polis statement view 0 --conversation CONV --json + polis comment list --conversation CONV --limit 50 --offset 0 --json + polis comment view 0 --conversation CONV --json polis collective list --report REPORT --json polis collective view 'OPAQUE#KEY#FROM#LIST' --json polis collective statements REPORT polis collective statements REPORT --json -Statement reads return active, unmuted, moderation-visible rows, even for owners. -Use moderate list for moderation. A missing or hidden single statement is +Comment reads return active, unmuted, moderation-visible rows, even for owners. +Use moderate list for moderation. A missing or hidden single comment is statement_unavailable (exit 1); an empty list is success. Single reads check exact IDs. Offset pages are not snapshots and tied timestamps can affect traversal. Collective list uses the server's latest-by-topic deduplication across runs, not a @@ -706,7 +706,7 @@ backing up or removing a local profile. ### Voting -`polis vote CONVERSATION` shows a statement and asks you to agree, disagree, +`polis vote CONVERSATION` shows a comment and asks you to agree, disagree, pass, or quit. It requires a terminal. Anonymous participation in an open conversation needs no account sign-in or prior join. The first requested vote creates the participant through Node and saves its token privately; later votes @@ -720,13 +720,13 @@ polis vote CONVERSATION --statement 1 --disagree --json polis vote CONVERSATION --statement 2 --pass --json ``` -JSON and `--no-interactive` require a statement and exactly one choice. The -receipt reports the semantic choice, statement and participant number, without +JSON and `--no-interactive` require a comment and exactly one choice. The +receipt reports the semantic choice, comment and participant number, without printing tokens or login codes. Participant credentials are isolated by profile, normalized origin and conversation; account tokens are not used. Node enforces access and voting rules. Vote values come from the shared contract boundary. -`--important` marks the statement as important to you, as the participation +`--important` marks the comment as important to you, as the participation page's importance checkbox does: `polis vote CONVERSATION --statement 0 --agree --important`. It needs `--statement` and one choice, and it changes neither the choice nor the @@ -738,14 +738,14 @@ No request is automatically retried. A lost or incompatible response, or a credential-save failure after a response, exits 7: check participation before resubmitting. Node may create membership before rejecting a vote; an error does not guarantee that membership is unchanged. Interactive quit sends no vote. -Statement text is untrusted content and terminal control characters are removed. +Comment text is untrusted content and terminal control characters are removed. `polis vote list` continues to provide the existing separate read command. -### Submit a participant statement +### Submit a participant comment ```sh -polis comment CONVERSATION "A statement to discuss" -polis comment CONVERSATION "A statement to discuss" --json +polis comment CONVERSATION "A comment to discuss" +polis comment CONVERSATION "A comment to discuss" --json ``` An open conversation needs no separate join or account sign-in: the first @@ -777,11 +777,11 @@ polis topic prioritize CONVERSATION --clear ``` Keys are checked before any credential is read. Saving then reads the run's -stored topics, the stored topic coordinates and the statement text, keeps each -topic's three statements nearest the mean of its coordinates, sends one POST +stored topics, the stored topic coordinates and the comment text, keeps each +topic's three comments nearest the mean of its coordinates, sends one POST and reads the choice back. The request is the page's own: each topic's layer, -cluster, key and those statements with their coordinates and distances. A -topic that is not stored for its run, or that has no statements in the stored +cluster, key and those comments with their coordinates and distances. A +topic that is not stored for its run, or that has no comments in the stored coordinates, is refused (exit 5) with nothing sent. A save replaces your whole previous choice; it never appends. @@ -800,7 +800,7 @@ and `readback` for writes), with issued tokens removed. No request is automatically retried. Once the POST or DELETE is sent, a lost or incompatible response, a failed read-back, or a credential-save failure -exits 7: run `--show` before saving again. Statement and topic text is +exits 7: run `--show` before saving again. Comment and topic text is untrusted content; the terminal receipt prints topic keys with control characters removed. @@ -813,13 +813,13 @@ polis conversation new --from setup.json --json ``` The interactive wizard asks about participation, overlapping invitation and -external-ID policies, moderation, visibility, and initial statements, then +external-ID policies, moderation, visibility, and initial comments, then shows a summary before asking to apply. Agents use the same typed JSON file. Dry runs make no HTTP requests. Saved files are private and never overwrite an existing file. Setup creates a staged conversation, confirms each settings/wave/allowlist/ -statement step, and applies final participation settings last. On partial +comment step, and applies final participation settings last. On partial failure it exits 7 with the known conversation ID and completed steps, without retrying. The error says that the conversation exists, closed and invite-only, and `data.finish` lists the commands that finish it with the requested @@ -828,7 +828,7 @@ settings, for example `polis conversation edit ID --invite-only false receipt before trying again: another `new` invocation creates another conversation. If the site refuses the first create request, nothing was created and the command exits with that refusal's own code (for example 4, forbidden). -Initial statements use moderator authority, with +Initial comments use moderator authority, with no seed bypass flag or automatic vote. No invitation code is printed. [The complete setting inventory and admission model](../docs/conversation-setup.md) @@ -883,26 +883,34 @@ and other server failures retain their existing errors. A gateway outage returning 502 also means the feature is currently unavailable; this does not prove it is permanently absent. No unfiltered-list fallback occurs. -### Statement importance +### Comment importance -`polis statement list --conversation CONVERSATION --sort importance ---min-important 3` reads the complete participant-visible statement count snapshot, filters -it, orders by important count descending (ties by statement ID), and then applies -`--offset` and `--limit`. With only `--min-important`, order is statement ID. -Plain `statement list` and `statement view` retain their existing behavior. +`polis comment list --conversation CONVERSATION --sort importance +--min-important 3` reads the complete participant-visible comment count snapshot, filters +it, orders by important count descending (ties by comment ID), and then applies +`--offset` and `--limit`. With only `--min-important`, order is comment ID. +Plain `comment list` and `comment view` retain their existing behavior. The new read must be enabled by the site operator. A 404 returns exit 8; -other read failures retain their error codes. No failure invents zero counts. The snapshot is bounded to 10,000 participant-visible statements. +other read failures retain their error codes. No failure invents zero counts. The snapshot is bounded to 10,000 participant-visible comments. Counts use each participant's latest vote, not every stored vote change. The CLI reads text only for the selected IDs and checks the exact returned set before printing anything. -A statement that disappears or becomes hidden between reads fails the request; +A comment that disappears or becomes hidden between reads fails the request; there is no automatic retry or partial ranking. Repeated offset pages do not share a snapshot. Each request retains the existing timeout and 8 MiB bound. -`polis report statements list REPORT` adds `important`, `voters`, and the -importance read timestamp. An unavailable read or a statement absent from the +`polis report comments list REPORT` adds `important`, `voters`, and the +importance read timestamp. An unavailable read or a comment absent from the participant-visible snapshot has null counts, never invented zero. A warning and `importance.state=unavailable` identify failed count reads while preserving the -original statement text and report-selection metadata. +original comment text and report-selection metadata. Counts are current reads, not historical analysis inputs. No command starts -analysis, changes statements, casts a vote, or calls a model. +analysis, changes comments, casts a vote, or calls a model. + +Participant submissions are **comments**; **statements** are collective statements. +Use `comment list`, `comment view`, `comment next`, and `report comments list`. +`polis comment CONVERSATION TEXT` still submits a comment. The other participant +comment operations share that command group. `collective statements` and +`delphi statement export/import` retain their collective meaning. Existing +`--statement` selectors and JSON/API field names retain their wire compatibility; +they select a comment where the command concerns participation. diff --git a/polis-cli/admin-operations.json b/polis-cli/admin-operations.json index 7d6500685..0772a223c 100644 --- a/polis-cli/admin-operations.json +++ b/polis-cli/admin-operations.json @@ -555,7 +555,7 @@ "auth": "public", "effect": false, "response": "json", - "about": "Read report topic statement counts" + "about": "Read report topic comment counts" }, { "command": "report feed list", @@ -812,7 +812,7 @@ "about": "Set this account’s conversation notification preference" }, { - "command": "statement translations", + "command": "comment translations", "method": "GET", "path": "/api/v3/comments/translations", "parameters": [ @@ -839,10 +839,10 @@ "auth": "account", "effect": true, "response": "json", - "about": "Read or request stored statement translations" + "about": "Read or request stored comment translations" }, { - "command": "statement next", + "command": "comment next", "method": "GET", "path": "/api/v3/nextComment", "parameters": [ @@ -856,7 +856,7 @@ "auth": "participant", "effect": false, "response": "json", - "about": "Read the next participant-scoped statement without casting a vote" + "about": "Read the next participant-scoped comment without casting a vote" }, { "command": "delphi narrative run", @@ -1046,7 +1046,7 @@ "auth": "account", "effect": true, "response": "json", - "about": "Moderate explicit statement IDs and/or a stored topic; inspect partial outcomes" + "about": "Moderate explicit comment IDs and/or a stored topic; inspect partial outcomes" }, { "command": "collective generate", @@ -1155,7 +1155,7 @@ "about": "Delete all of this participant’s selections" }, { - "command": "statement flag", + "command": "comment flag", "method": "POST", "path": "/api/v3/ptptCommentMod", "parameters": [ @@ -1252,10 +1252,10 @@ "auth": "account", "effect": true, "response": "json", - "about": "Upvote the conversation once; this is not a statement vote" + "about": "Upvote the conversation once; this is not a comment vote" }, { - "command": "statement star", + "command": "comment star", "method": "POST", "path": "/api/v3/stars", "parameters": [ @@ -1285,10 +1285,10 @@ "auth": "participant", "effect": true, "response": "json", - "about": "Set this participant’s statement star flag" + "about": "Set this participant’s comment star flag" }, { - "command": "statement trash", + "command": "comment trash", "method": "POST", "path": "/api/v3/trashes", "parameters": [ @@ -1318,10 +1318,10 @@ "auth": "participant", "effect": true, "response": "json", - "about": "Set this participant’s statement trash flag" + "about": "Set this participant’s comment trash flag" }, { - "command": "report statements select", + "command": "report comments select", "method": "POST", "path": "/api/v3/reportCommentSelections", "parameters": [ @@ -1348,7 +1348,7 @@ "effect": true, "response": "json", "resolve_report": true, - "about": "Set statement inclusion using the report’s own conversation" + "about": "Set comment inclusion using the report’s own conversation" }, { "command": "account edit", diff --git a/polis-cli/crates/polis/src/admin.rs b/polis-cli/crates/polis/src/admin.rs index c6e03a23a..144956e4e 100644 --- a/polis-cli/crates/polis/src/admin.rs +++ b/polis-cli/crates/polis/src/admin.rs @@ -312,7 +312,7 @@ pub fn execute( || (path == "topic moderate" && !fields.contains_key("topic_key") && !fields.contains_key("comment_ids")) - || (path == "statement flag" && fields.len() == 2) + || (path == "comment flag" && fields.len() == 2) { return Err(Error::input( "Choose at least one setting or target. No request was sent.", @@ -499,7 +499,7 @@ mod tests { fn typed_values_do_not_echo_bad_input() { let o = operations() .iter() - .find(|o| o.command == "statement star") + .find(|o| o.command == "comment star") .unwrap(); let p = o.parameters.iter().find(|p| p.name == "state").unwrap(); let e = convert(p, "private-invalid-value").unwrap_err(); diff --git a/polis-cli/crates/polis/src/commands.rs b/polis-cli/crates/polis/src/commands.rs index 5537767cb..2047a0a42 100644 --- a/polis-cli/crates/polis/src/commands.rs +++ b/polis-cli/crates/polis/src/commands.rs @@ -6,18 +6,18 @@ const GROUPS: &[(&str, &str, &str)] = &[ ("auth", "Sign in and inspect your session", "login status logout token refresh"), ("account", "Your identity and organization", "view edit invite verify"), ("conversation", "Create and explore conversations", "new create reserve list view edit close reopen stats activity snapshot uuid email-link share"), - ("seed", "Prepare and import seed statements", "add import csv/validate csv/preview csv/normalize"), - ("statement", "Read and contribute participant statements", "list view add next translations flag upvote star trash"), + ("seed", "Prepare and import seed comments", "add import csv/validate csv/preview csv/normalize"), + ("comment", "Read and contribute participant comments", "list view add next translations flag upvote star trash"), ("vote", "Participate with agree, disagree, or pass", "cast list import csv/validate csv/convert"), - ("moderate", "Review statements as a moderator", "list accept reject set"), + ("moderate", "Review comments as a moderator", "list accept reject set"), ("participant", "Participation, groups, and access lists", "login status list export activity preferences group group-members query locations highlight/list highlight/set xid/list xid/export allowlist/view allowlist/import allowlist/export"), ("invite", "Invite people and manage invitation waves", "code/list code/create wave/list wave/create list export status revoke"), ("metadata", "Conversation questions and choices", "view choices question/list question/add question/delete answer/list answer/add answer/delete"), ("context", "Browse and create conversation contexts", "list create"), ("notification", "Manage conversation subscriptions", "subscribe unsubscribe set"), - ("report", "Publish and explore reports", "list create view edit statements/list statements/select stats topics visualization export feed/list feed/consensus feed/topics"), + ("report", "Publish and explore reports", "list create view edit comments/list comments/select stats topics visualization export feed/list feed/consensus feed/topics"), ("math", "Inspect the conversation's mathematical summary", "view correlation refresh"), - ("topic", "Explore topic structure and statements", "list statements hierarchy proximity stats prioritize moderate"), + ("topic", "Explore topic structure and comments", "list comments hierarchy proximity stats prioritize moderate"), ("agenda", "Choose and manage topic priorities", "priorities list add replace remove"), ("delphi", "Run analysis and read stored results", "run status results logs wait show narrative/run narrative/view narrative/export narrative/import statement/export statement/import visualization/view"), ("collective", "Generate and read collective statements", "generate list view statements export import"), @@ -72,20 +72,20 @@ pub fn available(path: &str) -> bool { | "metadata question list" | "metadata answer list" | "context list" - | "statement list" - | "statement view" + | "comment list" + | "comment view" | "collective list" | "collective view" | "collective statements" | "topic list" - | "topic statements" + | "topic comments" | "topic hierarchy" | "topic proximity" | "topic stats" | "topic prioritize" | "report topics" | "report stats" - | "report statements list" + | "report comments list" | "account view" | "conversation edit" | "conversation share" @@ -171,10 +171,8 @@ fn leaf(path: &str) -> Command { "metadata question list" => "Read active conversation metadata questions", "metadata answer list" => "Read active metadata answer options, not participant responses", "context list" => "List public conversation contexts from the selected site", - "statement list" => "Page through participant-visible statements in a conversation", - "statement view" => { - "Read one participant-visible statement by its conversation-local number" - } + "comment list" => "Page through participant-visible comments in a conversation", + "comment view" => "Read one participant-visible comment by its conversation-local number", "collective list" => { "Read stored collective statements, deduplicated by the server by topic" } @@ -183,13 +181,13 @@ fn leaf(path: &str) -> Command { "topic list" | "report topics" => { "Read stored topics, retaining unavailable moderation markers" } - "topic statements" => "Read statements by exact topic key; missing stores are errors", + "topic comments" => "Read comments by exact topic key; missing stores are errors", "topic hierarchy" => "Read the stored topic hierarchy; no analysis starts", "topic proximity" => "Read stored topic coordinates for a layer or all layers", "topic stats" => "Read topic moderation counts and their availability", "topic prioritize" => "Choose the topics that matter most to you, as a participant", "report stats" => "Read participation timing through a matching report capability", - "report statements list" => "Page through visible statements with report-selection fields", + "report comments list" => "Page through visible comments with report-selection fields", "account view" => "Read the signed-in account from this site's users API", "conversation edit" => { "Edit moderator settings, preserve legacy defaults, then verify them" @@ -217,13 +215,13 @@ fn leaf(path: &str) -> Command { } "completion" => "Generate shell completions from the command tree without accessing a site", "tutorial" => "Read the terminal getting-started manual", - "seed add" => "Add one seed statement through the moderator-enforced bulk API", - "seed import" => "Validate a CSV, then import its seed statements as moderator", + "seed add" => "Add one seed comment through the moderator-enforced bulk API", + "seed import" => "Validate a CSV, then import its seed comments as moderator", "seed csv validate" => "Validate UTF-8 CSV headers, lengths, duplicates, and row counts", - "seed csv preview" => "Show the exact validated statements without submitting them", + "seed csv preview" => "Show the exact validated comments without submitting them", "moderate list" => "Read the moderation queue with limit and offset", - "moderate accept" => "Accept one statement, preserving its current metadata", - "moderate reject" => "Reject one statement, preserving its current metadata", + "moderate accept" => "Accept one comment, preserving its current metadata", + "moderate reject" => "Reject one comment, preserving its current metadata", "participant list" => { "Read this account's participation record as a scoped list (not a roster)" } @@ -280,7 +278,7 @@ fn leaf(path: &str) -> Command { "conversation reserve" => c.after_help("EXAMPLE\n polis conversation reserve --json\n\nOne authenticated POST requests a new ID. Legacy compatibility requires a conversation row at zid=0; a fresh database lacks it and returns a server failure. The CLI does not create that row. The legacy server registers it with zid=0: no conversation is created and no owner is bound. The ID is not proof of ownership or exclusive access. Preserve the receipt for a later explicit API creation request; conversation create does not yet accept a reserved ID. No lookup, release, expiry or idempotency contract is exposed. Every invocation can allocate another ID; no automatic retry or readback. If the response is lost, ask the site operator to inspect reservations before retrying. Responses are bounded to 8 MiB and --timeout."), "participant preferences" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("translations","Store translation display preference for the signed-in account").required(true).value_parser(["true","false"])).after_help("EXAMPLES\n polis participant preferences --conversation CONV --translations true --json\n polis participant preferences --conversation CONV --translations false --json\n\nSets show_translation_activated for the signed-in account in this conversation. Requires an explicit true or false; no participant ID, XID or another-account target is accepted. This changes a stored display preference only; no translation, model call or vote is requested. Sends one PUT, with no automatic retry. The legacy API returns an empty array even when no participant preference row exists. Success therefore reports state=acknowledged, affected_rows=null and persistence=unverified; it does not prove the value changed or create/join a participant. There is no preference readback endpoint. Ask the site operator to inspect this account's stored preference before retrying an uncertain write. Existing participant status does not read this preference. Requires site sign-in; 8 MiB response bound and --timeout apply."), "participant locations" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("group","Opinion-group array index, not its stored id or a base-cluster index").required(true).value_parser(clap::value_parser!(u32).range(0..=2147483647))).after_help("EXAMPLE\n polis participant locations --conversation CONV --group 0 --json\n\nPublic read of stored participant coordinates for one opinion-group ARRAY INDEX in the site math, not its stored id or a base-cluster index. Rows contain lat, lng and n=1; duplicates and server order are preserved, with no identities added. Empty can mean no matching locations, absent math, a refused math bundle or an absent group: it does not prove no participants. The server may cache math and reads locations separately; no generation, freshness, full-population or cross-read coherence is promised. Optional saved credentials apply. Coordinates are untrusted stored data; no geocoding, map lookup, aggregation, writes, computation or retry. One bounded request, 8 MiB and --timeout. Non-finite or out-of-range coordinates are refused as invalid_response, never clipped or dropped."), - "participant highlight list" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("mod","Exact stored participant moderation integer; omit for all values").allow_hyphen_values(true).value_parser(clap::value_parser!(i32))).after_help("EXAMPLES\n polis participant highlight list --conversation CONV --json\n polis participant highlight list --conversation CONV --mod 1 --json\n\nReads the existing participant-profile route. Only participants with an owner-associated XID and non-null profile image are returned. Without --mod all stored moderation values are eligible; --mod filters the exact signed integer, not statement moderation or an opinion-group ID. Empty can mean no matching profiles OR withheld access: the server exposes rows only to the exact owner, a Polis developer, or anyone when conversation data is open. A same-site moderator is not necessarily the owner. No roster completeness, stable order or pagination claim: the server caps candidates at 99999 before profile filtering. Profile text and URLs are untrusted data; URLs are never fetched. Optional saved credentials apply. One bounded read, 8 MiB and --timeout; no writes, retries or computation. Use participant highlight set for an explicitly confirmed write."), + "participant highlight list" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("mod","Exact stored participant moderation integer; omit for all values").allow_hyphen_values(true).value_parser(clap::value_parser!(i32))).after_help("EXAMPLES\n polis participant highlight list --conversation CONV --json\n polis participant highlight list --conversation CONV --mod 1 --json\n\nReads the existing participant-profile route. Only participants with an owner-associated XID and non-null profile image are returned. Without --mod all stored moderation values are eligible; --mod filters the exact signed integer, not comment moderation or an opinion-group ID. Empty can mean no matching profiles OR withheld access: the server exposes rows only to the exact owner, a Polis developer, or anyone when conversation data is open. A same-site moderator is not necessarily the owner. No roster completeness, stable order or pagination claim: the server caps candidates at 99999 before profile filtering. Profile text and URLs are untrusted data; URLs are never fetched. Optional saved credentials apply. One bounded read, 8 MiB and --timeout; no writes, retries or computation. Use participant highlight set for an explicitly confirmed write."), "participant group-members" => c.arg(arg("conversation","Public conversation ID").required(true)).after_help("EXAMPLE\n polis participant group-members --conversation CONV --json\n\nPublic read of the base-cluster index to participant-ID map (bidToPid). Array positions are base-cluster indices, not opinion-group IDs. This is not a complete participant roster. No sign-in required; configured credentials still apply. No computation, refresh, conditional request, cache or automatic retry. Missing math returns membership_unavailable, not an empty list; the legacy API also masks storage errors as 304. An empty stored map is a valid result. No generation is returned, so do not join this result to a separate math read or claim freshness/coherence. Member order and empty clusters are preserved. Responses are bounded to 8 MiB and --timeout."), "math view" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("key","Exact top-level field; repeat to select multiple fields").action(ArgAction::Append)).after_help("EXAMPLES\n polis math view --conversation CONV --json\n polis math view --conversation CONV --key math_tick --key pca --json\n\nPublic read; no sign-in required. Returns the served presentation as data, not a raw engine checkpoint. No refresh, job or worker task is submitted. The server may synthesize defaults when no math row exists; math_tick 0 does not prove computation or freshness. No conditional request or cache is used. A 304 is unavailable, not an empty success. Missing requested keys are omitted by the server; an empty object is valid for a field selection. Unknown fields are preserved. Maximum 32 unique keys, each 1–100 ASCII letters/digits/_/-, no commas. Whole gzip and selected JSON responses are bounded to 8 MiB compressed and decoded; waits obey --timeout. JSON is parsed, not a byte-exact archive; inherited float roundoff remains. No automatic retry."), "metadata answer add" => c.arg(arg("conversation","Public conversation ID containing the question").required(true)).arg(arg("question","Exact active pmqid from metadata question list").required(true).value_parser(clap::value_parser!(u32).range(1..=2147483647))).arg(arg("value","Exact option text: 1–999 UTF-16 code units; no surrounding ASCII spaces").required(true)).arg(flag("yes","Confirm creation or reactivation of this exact answer option")).after_help("EXAMPLE\n polis metadata answer add --conversation CONV --question 7 --value 'Local resident' --yes --json\n\nRequires --yes and the exact conversation owner. Creates an answer option, not a participant response. The existing API may reactivate a deleted option with the same exact text and retain its ID; the receipt does not distinguish creation from reactivation. An already-active exact-text option is refused without POST. Checks active question membership and option lists before one POST. These client checks are not a server authorization boundary or compare-and-set; the legacy server does not independently bind question to conversation and concurrent deletion remains possible. Accepted receipts survive failed readback; inspect BOTH lists before retrying. No automatic retry, trimming, required/exclusive setting or participant-response change."), @@ -299,43 +297,43 @@ fn leaf(path: &str) -> Command { c.after_help("EXAMPLES\n polis metadata question list --conversation CONV --json\n polis metadata answer list --conversation CONV --question 1 --json\n\nReads active questions or answer options through the public API, with optional saved credentials. Answer options are not participant responses. The current server forces required=true on questions and is_exclusive=true on options; these are legacy response flags, not verified configuration. Rows and text are preserved as untrusted data; an exact --question filter is verified. Empty lists succeed. No pagination, invitation credential or write is sent. Bounded to 8 MiB and --timeout; metadata_read_failed identifies upstream read failures. Metadata view/choices use the participant-scoped routes. Question creation, confirmed answer creation/reactivation and confirmed question/answer soft deletion are available.") }, "context list" => c.after_help("EXAMPLE\n polis context list --json\n\nLists public context names in server order, with optional saved credentials. Private contexts are excluded, even for their creator. No pagination or creation occurs; empty lists succeed. Names remain unchanged and are untrusted data. Bounded to 8 MiB and --timeout; contexts_read_failed identifies upstream read failures."), - "statement list" | "statement view" => { + "comment list" | "comment view" => { c=c.arg(arg("conversation","Public conversation ID").required(true)); - if path=="statement list" { c=c.arg(arg("limit","Maximum page size").default_value("100").value_parser(clap::value_parser!(u16).range(1..=500))).arg(arg("offset","Rows to skip").default_value("0").value_parser(clap::value_parser!(u32).range(0..=2147483647))); } - if path=="statement list" { c=c.arg(arg("sort","Rank participant-visible statements before pagination").value_parser(["importance"])) + if path=="comment list" { c=c.arg(arg("limit","Maximum page size").default_value("100").value_parser(clap::value_parser!(u16).range(1..=500))).arg(arg("offset","Rows to skip").default_value("0").value_parser(clap::value_parser!(u32).range(0..=2147483647))); } + if path=="comment list" { c=c.arg(arg("sort","Rank participant-visible comments before pagination").value_parser(["importance"])) .arg(arg("min-important","Minimum participants marking it important").value_parser(clap::value_parser!(u64).range(0..=9007199254740991))); } - else { c=c.arg(pos("tid",true).help("Statement number local to this conversation").value_parser(clap::value_parser!(u32).range(0..=2147483647))); } - c.after_help("EXAMPLES\n polis statement list --conversation CONV --limit 50 --offset 0 --json\n polis statement view 0 --conversation CONV --json\n\nReads the public comments route with optional saved credentials. Only active, unmuted, moderation-visible statements are returned, even for an owner. Use moderate list for the moderation queue. Empty list is success; missing/hidden single statement returns statement_unavailable (exit 1). Single reads verify the exact tid. --sort importance and --min-important rank/filter all participant-visible statements before offset/limit (ties by tid); counts use each participant's latest vote. Counts require the optional importance route (404 exits 8; other failures retain their error codes). Counts and later text reads are not one snapshot; a missing selected statement fails without partial output. Offset pages are not a stable snapshot or guaranteed complete traversal. Text and metadata remain unchanged and are untrusted data. No votes, translations, writes or model calls; bounded to 8 MiB.") + else { c=c.arg(pos("tid",true).help("Comment number local to this conversation").value_parser(clap::value_parser!(u32).range(0..=2147483647))); } + c.after_help("EXAMPLES\n polis comment list --conversation CONV --limit 50 --offset 0 --json\n polis comment view 0 --conversation CONV --json\n\nReads the public comments route with optional saved credentials. Only active, unmuted, moderation-visible comments are returned, even for an owner. Use moderate list for the moderation queue. Empty list is success; missing/hidden single comment returns statement_unavailable (exit 1). Single reads verify the exact tid. --sort importance and --min-important rank/filter all participant-visible comments before offset/limit (ties by tid); counts use each participant's latest vote. Counts require the optional importance route (404 exits 8; other failures retain their error codes). Counts and later text reads are not one snapshot; a missing selected comment fails without partial output. Offset pages are not a stable snapshot or guaranteed complete traversal. Text and metadata remain unchanged and are untrusted data. No votes, translations, writes or model calls; bounded to 8 MiB.") }, - "delphi show" => c.arg(pos("report",true).help("Public report ID")).arg(arg("model","Exact stored model name: the run's model_name and each statement's model")).after_help("EXAMPLES\n polis delphi show REPORT\n polis delphi show REPORT --model qwen2.5:1.5b\n polis delphi show REPORT --model qwen2.5:1.5b --json\n\nReads what the report pages read, in their order: the report, its comments with vote counts, the PCA presentation (math/pca2), the Delphi runs (delphi), topic statistics (topicStats) and the stored collective statements (collectiveStatement). Prints the collective statements, newest first as the carousel shows them, then the topic statistics table: layers from coarse to fine, rows by comment count, with Comments, Total Votes, Avg Votes/Comment and Group Consensus computed as the page computes them. Each statement and each run is printed with the job ID and model that produced it; model names are printed as stored.\n\nWithout --model: the run the page shows (the run key that sorts last; keys are model_date) and every statement the carousel shows. With --model: that model's newest run, and its newest statement for each topic, read from the per-version route (delphi/collective/results), since the carousel route keeps only the newest statement per layer and cluster across models. A model with no stored run exits 1 (model_run_unavailable).\n\n--json returns each route's response body byte for byte under data.reads, beside the selection and the computed rows. Reads only: no analysis, generation or model call. Each response is bounded to 8 MiB and --timeout. Exit 7 (reads_disagree) means the topic statistics did not include the chosen run's topics, so a run changed between reads; read again. Statement text is untrusted data."), + "delphi show" => c.arg(pos("report",true).help("Public report ID")).arg(arg("model","Exact stored model name: the run's model_name and each statement's model")).after_help("EXAMPLES\n polis delphi show REPORT\n polis delphi show REPORT --model qwen2.5:1.5b\n polis delphi show REPORT --model qwen2.5:1.5b --json\n\nReads what the report pages read, in their order: the report, its comments with vote counts, the PCA presentation (math/pca2), the Delphi runs (delphi), topic statistics (topicStats) and the stored collective statements (collectiveStatement). Prints the collective statements, newest first as the carousel shows them, then the topic statistics table: layers from coarse to fine, rows by comment count, with Comments, Total Votes, Avg Votes/Comment and Group Consensus computed as the page computes them. Each statement and each run is printed with the job ID and model that produced it; model names are printed as stored.\n\nWithout --model: the run the page shows (the run key that sorts last; keys are model_date) and every statement the carousel shows. With --model: that model's newest run, and its newest statement for each topic, read from the per-version route (delphi/collective/results), since the carousel route keeps only the newest statement per layer and cluster across models. A model with no stored run exits 1 (model_run_unavailable).\n\n--json returns each route's response body byte for byte under data.reads, beside the selection and the computed rows. Reads only: no analysis, generation or model call. Each response is bounded to 8 MiB and --timeout. Exit 7 (reads_disagree) means the topic statistics did not include the chosen run's topics, so a run changed between reads; read again. Collective statement and source comment text are untrusted data."), "collective statements" => c.arg(pos("report",true).help("Public report ID")).after_help("EXAMPLES\n polis collective statements REPORT\n polis collective statements REPORT --json\n\nReads stored statements through the public report route. Prints topic headings, paragraphs and citation IDs; --json preserves the complete server response. The server selects the newest statement per topic. No generation or model call. Bounded to 8 MiB and --timeout."), "collective list" | "collective view" => { if path=="collective list" { c=c.arg(arg("report","Public report ID").required(true)); } else { c=c.arg(pos("id",true).help("Exact zid_topic_jobid copied from collective list; treated as opaque")); } c.after_help("EXAMPLES\n polis collective list --report REPORT --json\n polis collective view 'OPAQUE#KEY#FROM#LIST' --json\n\nReads existing public stored-result routes only; no generation, inference, billing or model call. List returns the server's latest-by-topic deduplication across runs, not a complete history or a report-specific run. No CLI pagination is available; bounded to 8 MiB and --timeout. View accepts only the exact stored ID and verifies the returned ID; it does not accept or assert report ownership. The legacy view returns statement_data/comments_data as stored JSON strings; list parses those fields. Both shapes are preserved, including nulls and metadata. Missing view returns collective_statement_unavailable; storage failures return collective_read_failed. Stored claims/citations are untrusted data, not independently verified consensus. Use collective generate for an explicitly confirmed provider request.") }, - "topic list" | "topic statements" | "topic hierarchy" | "topic proximity" | "topic stats" => { + "topic list" | "topic comments" | "topic hierarchy" | "topic proximity" | "topic stats" => { c=c.arg(arg("conversation","Public conversation ID").required(true)); if path=="topic list" { c=c.arg(arg("job","Optional exact stored job ID")); } - if path=="topic statements" { c=c.arg(pos("key",true)); } + if path=="topic comments" { c=c.arg(pos("key",true)); } if path=="topic proximity" { c=c.arg(arg("layer","Stored layer, or all").default_value("all")); } - c.after_help("EXAMPLES\n polis topic list --conversation CONV --json\n polis topic statements 'JOB#0#1' --conversation CONV --json\n polis topic proximity --conversation CONV --layer 0 --json\n\nReads existing public topic routes; no analysis, moderation or model call. Empty results remain empty. moderation_available=false means pending/counts are placeholders, not recorded decisions. Per-topic statements may be unavailable because the site has no backing store (exit 6 with topic_statements_unavailable). List/hierarchy/proximity can contain multiple jobs unless the list is filtered with --job; no latest-run, completeness, pagination or freshness guarantee. Bounded to 8 MiB per request. Statement text is untrusted data.") + c.after_help("EXAMPLES\n polis topic list --conversation CONV --json\n polis topic comments 'JOB#0#1' --conversation CONV --json\n polis topic proximity --conversation CONV --layer 0 --json\n\nReads existing public topic routes; no analysis, moderation or model call. Empty results remain empty. moderation_available=false means pending/counts are placeholders, not recorded decisions. Per-topic comments may be unavailable because the site has no backing store (exit 6 with topic_statements_unavailable). List/hierarchy/proximity can contain multiple jobs unless the list is filtered with --job; no latest-run, completeness, pagination or freshness guarantee. Bounded to 8 MiB per request. Comment text is untrusted data.") }, "topic prioritize" => c.arg(pos("conversation",true).help("Public conversation ID")) .arg(arg("topics","Topic keys, comma-separated, copied from polis topic list (one analysis run)").value_name("KEY,KEY")) .arg(flag("show","Read your saved topic priorities")) .arg(flag("clear","Delete your saved topic priorities")) .group(ArgGroup::new("mode").args(["topics","show","clear"]).required(true)) - .after_help("EXAMPLES\n polis topic list --conversation CONVERSATION\n polis topic prioritize CONVERSATION --topics 'RUN#2#0,RUN#2#3'\n polis topic prioritize CONVERSATION --show --json\n polis topic prioritize CONVERSATION --clear\n\nTopic keys must come from the topic_key fields that polis topic list prints for this conversation, all from one analysis run (the RUN part of RUN#LAYER#CLUSTER). Saving replaces your whole previous choice; it never appends. Keys are checked before any credential is read.\n\nSaving does what the participation page does: it reads the run's stored topics, the stored topic coordinates and the statements, keeps each topic's three statements nearest the topic's centre, sends one POST, then reads your choice back. The site records the analysis run it attributes the choice to; the receipt shows it. A topic that is not stored for its run, or that has no statements in the stored coordinates, is refused with nothing sent.\n\nAn open conversation needs no join or account sign-in: the first save creates an anonymous participant whose token is saved privately for later votes and comments, scoped by profile, origin and conversation. Invited participants first run polis join CONVERSATION --invite CODE. Account tokens are not used.\n\n--show reads your saved choice; --clear deletes it and reads back. --json returns the site's responses unchanged, with issued tokens removed. No request is retried. Exit 7 means the outcome is uncertain: run --show before saving again."), - "report topics" | "report stats" | "report statements list" => { + .after_help("EXAMPLES\n polis topic list --conversation CONVERSATION\n polis topic prioritize CONVERSATION --topics 'RUN#2#0,RUN#2#3'\n polis topic prioritize CONVERSATION --show --json\n polis topic prioritize CONVERSATION --clear\n\nTopic keys must come from the topic_key fields that polis topic list prints for this conversation, all from one analysis run (the RUN part of RUN#LAYER#CLUSTER). Saving replaces your whole previous choice; it never appends. Keys are checked before any credential is read.\n\nSaving does what the participation page does: it reads the run's stored topics, the stored topic coordinates and the comments, keeps each topic's three comments nearest the topic's centre, sends one POST, then reads your choice back. The site records the analysis run it attributes the choice to; the receipt shows it. A topic that is not stored for its run, or that has no comments in the stored coordinates, is refused with nothing sent.\n\nAn open conversation needs no join or account sign-in: the first save creates an anonymous participant whose token is saved privately for later votes and comments, scoped by profile, origin and conversation. Invited participants first run polis join CONVERSATION --invite CODE. Account tokens are not used.\n\n--show reads your saved choice; --clear deletes it and reads back. --json returns the site's responses unchanged, with issued tokens removed. No request is retried. Exit 7 means the outcome is uncertain: run --show before saving again."), + "report topics" | "report stats" | "report comments list" => { if path=="report topics" { c=c.arg(pos("id",false).help("Public report ID (or use --report)").required_unless_present("report").conflicts_with("report")) .arg(arg("report","Public report ID (alternative to positional ID)").required_unless_present("id")) .arg(arg("job","Optional exact stored job ID")); } else { c=c.arg(pos("id",true)); } if path=="report stats" { c=c.arg(arg("until","Exclusive positive UTC epoch-millisecond cutoff").value_parser(clap::value_parser!(u64).range(1..=9007199254740991))); } - if path=="report statements list" { c=c.arg(arg("limit","Maximum page size").default_value("100").value_parser(clap::value_parser!(u16).range(1..=500))).arg(arg("offset","Rows to skip").default_value("0").value_parser(clap::value_parser!(u32).range(0..=2147483647))); } - c.after_help("EXAMPLES\n polis report topics REPORT --json\n polis report topics --report REPORT --job JOB --json\n polis report stats REPORT --until 1791417600000 --json\n polis report statements list REPORT --limit 50 --offset 0 --json\n\nResolves exactly one matching report to its conversation before reading; no separately supplied conversation can be paired with it. Uses existing public/report-capability access; saved optional credentials still apply. Statements are participant-visible rows, not every moderator row or a selected-only list; important/voters are current participant-visible statement counts using each participant's latest vote, with read_at_ms. Null means unavailable or not visible at that read, never zero. Counts are not historical report inputs; includeInReport is retained exactly and omitted values are not inferred. Pagination is offset-based, not a stable snapshot. Stats are historical event timing, not latest votes or math freshness. Topics are conversation-wide stored data, not a report-specific run unless --job is supplied. No write or analysis starts; each request is bounded to 8 MiB.") + if path=="report comments list" { c=c.arg(arg("limit","Maximum page size").default_value("100").value_parser(clap::value_parser!(u16).range(1..=500))).arg(arg("offset","Rows to skip").default_value("0").value_parser(clap::value_parser!(u32).range(0..=2147483647))); } + c.after_help("EXAMPLES\n polis report topics REPORT --json\n polis report topics --report REPORT --job JOB --json\n polis report stats REPORT --until 1791417600000 --json\n polis report comments list REPORT --limit 50 --offset 0 --json\n\nResolves exactly one matching report to its conversation before reading; no separately supplied conversation can be paired with it. Uses existing public/report-capability access; saved optional credentials still apply. Comments are participant-visible rows, not every moderator row or a selected-only list; important/voters are current participant-visible comment counts using each participant's latest vote, with read_at_ms. Null means unavailable or not visible at that read, never zero. Counts are not historical report inputs; includeInReport is retained exactly and omitted values are not inferred. Pagination is offset-based, not a stable snapshot. Stats are historical event timing, not latest votes or math freshness. Topics are conversation-wide stored data, not a report-specific run unless --job is supplied. No write or analysis starts; each request is bounded to 8 MiB.") }, "auth login" => c.arg(flag("device","Sign in on another device with a browser").conflicts_with_all(["browser","no-browser","with-token","token-stdin","no-store"])) .arg(flag("with-token","Read a bearer token from stdin and save to a 0600 file").conflicts_with_all(["token-stdin","browser","no-browser"])) @@ -349,18 +347,18 @@ fn leaf(path: &str) -> Command { "conversation stats" => c.arg(pos("id",true)).arg(arg("until","Exclusive UTC epoch-millisecond cutoff, positive safe integer").value_parser(clap::value_parser!(u64).range(1..=9007199254740991))).after_help("EXAMPLES\n polis conversation stats CONV --json\n polis conversation stats CONV --until 1791417600000 --json\n\nRequires this site's moderator permission. Returns the existing vote/comment timing and histogram fields unchanged; these are historical event statistics, not unique latest votes or math freshness. No pagination; bounded to 8 MiB and the request timeout. No report-ID permission fallback."), "report create" => c.arg(arg("conversation","Public conversation ID").required(true)).after_help("EXAMPLE\n polis report create --conversation CONV --json\n polis report list --conversation CONV --json\n\nRequires moderator access. Creates report configuration with the existing default mod_level=-2; starts no math, export or Delphi generation. data.report_id is the created report's ID when the server returns it; servers that reply {} leave it null, and data.reports is then an uncorrelated readback list, never proof of which report was created. There is no idempotency key. A failed readback preserves the accepted receipt. Never repeat creation to recover a lost ID; list first. An uncertain write exits 7."), "account view" => c.after_help("EXAMPLE\n polis account view --json\n\nRequires authentication. Returns this account's server profile, which may include personal data. It is not a plan, credit balance, or proof of permission for another resource."), - "conversation new" => c.arg(arg("from","Read a typed setup JSON file instead of asking questions")).arg(arg("save","Write the typed setup to a new private file")).arg(flag("dry-run","Describe setup without any HTTP requests")).after_help("EXAMPLES\n polis conversation new\n polis conversation new --from setup.json --dry-run --json\n polis conversation new --from setup.json --json\n\nUses the same typed model for people and agents. Invalid settings fail before writes. The interactive wizard shows a summary and asks before applying. Creates a staged closed conversation, applies settings, invitation waves, external-ID allowlist and initial statements, reads back each step, then applies the final participation settings. Partial failure exits 7 with completed steps and, in data.finish, the commands that finish the staged closed, invite-only conversation; never blindly rerun new, which creates another conversation. A refused first create made nothing and exits with its own code. Initial statements use the moderator bulk endpoint with no seed flag or automatic vote. No server permissions are changed. See docs/conversation-setup.md for current behavior and proposed improvements."), + "conversation new" => c.arg(arg("from","Read a typed setup JSON file instead of asking questions")).arg(arg("save","Write the typed setup to a new private file")).arg(flag("dry-run","Describe setup without any HTTP requests")).after_help("EXAMPLES\n polis conversation new\n polis conversation new --from setup.json --dry-run --json\n polis conversation new --from setup.json --json\n\nUses the same typed model for people and agents. Invalid settings fail before writes. The interactive wizard shows a summary and asks before applying. Creates a staged closed conversation, applies settings, invitation waves, external-ID allowlist and initial comments, reads back each step, then applies the final participation settings. Partial failure exits 7 with completed steps and, in data.finish, the commands that finish the staged closed, invite-only conversation; never blindly rerun new, which creates another conversation. A refused first create made nothing and exits with its own code. Initial comments use the moderator bulk endpoint with no seed flag or automatic vote. No server permissions are changed. See docs/conversation-setup.md for current behavior and proposed improvements."), "conversation create" => c.arg(arg("topic","Conversation topic (1–1000 UTF-16 units)").required(true)).arg(arg("description","Optional description (up to 50000 UTF-16 units)")).arg(flag("draft","Create a draft")), "conversation list" => c.arg(flag("mine","Owned conversations only (the default)")).arg(flag("recent","Newest created first (the default)")).arg(arg("limit","Rows read from the site before the owner filter (1–9999)").default_value("100").value_parser(clap::value_parser!(u16).range(1..=9999))).arg(arg("active","Filter active or closed").value_parser(["true","false"])).arg(arg("draft","Filter draft or published").value_parser(["true","false"])).arg(arg("search","Case-insensitive topic substring (literal), applied to the rows read")).arg(arg("sort","Creation date (newest/oldest) or size (participants/statements/votes, largest first)").value_parser(["newest","oldest","participants","statements","votes"])).arg(flag("sizes","Read per-conversation statistics and show size columns")).arg(arg("min-participants","Minimum stored participant count; uses the Rust owner list").value_parser(clap::value_parser!(u32).range(0..=2147483647))).arg(arg("cursor","Opaque next_cursor from the same owner and filters; uses the Rust owner list")).after_help("EXAMPLES\n polis conversation list --json\n polis conversation list --limit 500 --active true --json\n polis conversation list --search 'budget' --json\n\nReads GET /api/v3/conversations. The current API returns an array of the conversations this account owns or shares a site with, newest created first, at most --limit rows; it has no offset, cursor, owner filter or search parameter. Rows whose server-set is_owner is false are dropped here, so pagination.returned can be below pagination.server_rows. pagination.truncated is true when the site returned --limit rows: raise --limit to read more. --active and --draft are applied by the site; --search is a literal, case-insensitive topic match applied to the rows read. Requires sign-in. Bounded reads, 8 MiB and --timeout; no automatic retry.\n\nWithout --json the result is a table: topic and description (cleaned and cut to fit the terminal), the conversation URL and the newest report URL, with +N when the conversation has N more reports. The report column comes from a second, best-effort GET /api/v3/reports: if that read fails, the table still prints with an empty column and one warning on stderr. --json reads only the conversations route and returns the data envelope unchanged.\n\nSupplying --sort newest/oldest, --min-participants or --cursor selects the separately enabled Rust owner-list endpoint and requires an OIDC access token. That mode supports server-side search, a limit of at most 500, and opaque cursor pagination. Repeat filters on each page. It never falls back to an unfiltered list. Stored participant counts and pagination are not a frozen snapshot.\n\n--sizes or --sort participants|statements|votes uses the existing list plus one sequential conversationStats read per returned owned row (maximum --limit 500). Size sorting is descending within those returned rows, NOT a global ranking; ties keep site order. Participants counts distinct voters (including author votes), statements counts all stored comments including moderated/seeds, votes counts vote records including revotes. These differ from the stored participant_count, which is preserved in JSON. --sizes preserves site order. Each read retains the 8 MiB and --timeout bounds; a failed or invalid stats read fails the command, with no partial ranking. Counts are separate reads, not a snapshot. Size options cannot be combined with cursor/min-participants or --recent. No size reads occur unless requested."), "conversation view" | "conversation close" | "conversation reopen" => c.arg(pos("id",true)), "participant export"|"participant xid export" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("output","New output file; never overwrite").required(true)).arg(arg("format","CSV preserves bytes; JSON retains every CSV cell as a string").value_parser(["csv","json"]).default_value("csv")).after_help("Uses the moderator-enforced XID export. Only participants with XIDs are included, not every participant. Server caps this endpoint at 1,000,000 rows; CLI bounds bytes at 8 MiB. Downloaded cells are untrusted text."), "plan view" => c.arg(flag("web","Open this site account page; no checkout or plan change")).arg(flag("no-browser","Return the account URL without opening it").requires("web")), "plan upgrade"|"plan manage" => c.arg(flag("no-browser","Return the account URL without opening it")).after_help("Billing is unavailable. Opens only /account on the configured site; no Stripe URL is invented and no subscription, payment or paid work is created. --no-interactive also suppresses the browser."), - "seed add" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("text","Exact statement text (up to 997 UTF-16 units)").required(true)), - "seed import" => c.arg(pos("csv",true)).arg(arg("votes","Optional BYOD vote CSV; all files validated before any write").requires("source-agree")).arg(arg("source-agree","Required source vote sign; forwarded unchanged to the sign-aware importer").value_parser(["+1","-1"]).allow_hyphen_values(true).requires("votes")).arg(arg("conversation","Public conversation ID").required(true)).after_help("CSV requires comment_text,original_id headers (external original_id is mapped deterministically to a site/conversation-bound UUID; UUIDs are preserved); UTF-8 with optional BOM. All rows validated first. Optional --votes requires --source-agree=+1|-1 and the server's sign-aware vote importer. Vote columns: vote_id,user_id,vote_value,timestamp,comment_id; comment_id refers to original_id in this seed file. Vote values are never converted by the CLI. Statements are imported first; votes are only queued after complete statement receipts. This is NOT atomic across statements/votes; a processing receipt is NOT import completion. No trimming, silent drops, retries, or atomicity claim. JSON data.receipt is the per-row receipt; save it and read back before any retry."), + "seed add" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("text","Exact comment text (up to 997 UTF-16 units)").required(true)), + "seed import" => c.arg(pos("csv",true)).arg(arg("votes","Optional BYOD vote CSV; all files validated before any write").requires("source-agree")).arg(arg("source-agree","Required source vote sign; forwarded unchanged to the sign-aware importer").value_parser(["+1","-1"]).allow_hyphen_values(true).requires("votes")).arg(arg("conversation","Public conversation ID").required(true)).after_help("CSV requires comment_text,original_id headers (external original_id is mapped deterministically to a site/conversation-bound UUID; UUIDs are preserved); UTF-8 with optional BOM. All rows validated first. Optional --votes requires --source-agree=+1|-1 and the server's sign-aware vote importer. Vote columns: vote_id,user_id,vote_value,timestamp,comment_id; comment_id refers to original_id in this seed file. Vote values are never converted by the CLI. Comments are imported first; votes are only queued after complete comment receipts. This is NOT atomic across comments/votes; a processing receipt is NOT import completion. No trimming, silent drops, retries, or atomicity claim. JSON data.receipt is the per-row receipt; save it and read back before any retry."), "seed csv validate"|"seed csv preview" => c.arg(pos("csv",true)), "moderate list" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("status","Moderation state").value_parser(["all","pending","accepted","rejected"]).default_value("pending")).arg(arg("limit","Maximum rows returned").default_value("100").value_parser(clap::value_parser!(u16).range(1..=500))).arg(arg("offset","Rows to skip").default_value("0").value_parser(clap::value_parser!(u32).range(0..=2147483647))), - "moderate accept"|"moderate reject" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("tid","Statement number in the conversation").required(true).value_parser(clap::value_parser!(u32).range(0..=2147483647))).after_help("Reads the current row before PUT; preserves is_meta, velocity and (for rejection) active. The legacy API has no compare-and-set: avoid concurrent edits of the same statement. No automatic retry."), + "moderate accept"|"moderate reject" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("tid","Comment number in the conversation").required(true).value_parser(clap::value_parser!(u32).range(0..=2147483647))).after_help("Reads the current row before PUT; preserves is_meta, velocity and (for rejection) active. The legacy API has no compare-and-set: avoid concurrent edits of the same comment. No automatic retry."), "participant list"|"participant status"|"participant xid list"|"report list" => c.arg(arg("conversation","Public conversation ID").required(true)), "vote list" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("pid","Participant number; omit to resolve your account's record").value_parser(clap::value_parser!(u32).range(0..=2147483647))), "report view" => c.arg(pos("id",true)), @@ -393,7 +391,7 @@ fn purpose(path: &str) -> String { pub fn command() -> Command { let mut root=Command::new("polis").version(concat!(env!("CARGO_PKG_VERSION"), " (commit ", env!("POLIS_BUILD_COMMIT"), "; ", env!("POLIS_BUILD_SOURCE"), ")")) .about("Listen at scale. Bring Polis to your terminal.") - .long_about("Listen at scale. Bring Polis to your terminal.\n\nConversations, statements, and shared understanding — for people and agents.\nWorking now: auth, conversations, seeds, moderation, participant/vote reads, + .long_about("Listen at scale. Bring Polis to your terminal.\n\nConversations, comments, and shared understanding — for people and agents.\nWorking now: auth, conversations, seeds, moderation, participant/vote reads, report exports, stored Delphi results, and raw API.\nThe full product surface is discoverable below; planned commands return exit 8.") .arg(flag("json","Emit the versioned polis-cli/1 JSON envelope (including errors and help)").global(true)) .arg(flag("no-interactive","Never prompt; saved file sign-ins, explicitly opted-in Keychain and environment tokens still work").global(true)) @@ -405,26 +403,30 @@ report exports, stored Delphi results, and raw API.\nThe full product surface is .arg(arg("invite", "Accept a one-time invite; save its login code privately").conflicts_with("login-code")) .arg(arg("login-code", "Sign in as a returning Treevite participant")) .after_help("Without a code, prepares participation without enrolling a fresh visitor. The first requested vote or comment enrolls them. Repeated joins reuse only this profile, origin and conversation's participant credentials. Invite and login codes are distinct; no automatic retry or fallback. Tokens and login codes are saved in the owner-only credentials store and never printed. Codes passed as arguments may be visible in local shell history and process listings.")); - root = root.subcommand(Command::new("comment") - .about("Submit a participant statement to a conversation") - .arg(pos("conversation", true)) - .arg(pos("text", true)) - .after_help("EXAMPLES\n polis comment CONVERSATION \"A statement to discuss\"\n polis comment CONVERSATION \"A statement to discuss\" --json\n\nUses this profile, origin and conversation's participant credentials. In an open conversation the first requested comment enrolls an anonymous participant; no prior join or account sign-in is needed. For invitations, first use polis join CONVERSATION --invite CODE. Sends only conversation_id and txt, with no seed flag or author vote. Node enforces participation and moderation; a submission receipt does not imply approval or visibility. Text is never echoed in errors. Arguments can remain in shell history and process listings. No automatic retries; an uncertain write or credential-save failure exits 7. Inspect the conversation before submitting again.")); for &(group, about, leaves) in GROUPS { let mut cmd = Command::new(group) .about(about) .subcommand_required(true) .arg_required_else_help(true); + if group == "comment" { + cmd = Command::new("comment") + .about("Submit a participant comment, or read comments and their statistics") + .subcommand_negates_reqs(true) + .args_conflicts_with_subcommands(true) + .arg(pos("conversation", true)) + .arg(pos("text", true)) + .after_help("EXAMPLES\n polis comment CONVERSATION \"A comment to discuss\"\n polis comment CONVERSATION \"A comment to discuss\" --json\n\nUses this profile, origin and conversation's participant credentials. In an open conversation the first requested comment enrolls an anonymous participant; no prior join or account sign-in is needed. For invitations, first use polis join CONVERSATION --invite CODE. Sends only conversation_id and txt, with no seed flag or author vote. Node enforces participation and moderation; a submission receipt does not imply approval or visibility. Text is never echoed in errors. Arguments can remain in shell history and process listings. No automatic retries; an uncertain write or credential-save failure exits 7. Inspect the conversation before submitting again."); + } if group == "vote" { cmd = cmd.subcommand_required(false).arg_required_else_help(false) .args_conflicts_with_subcommands(true) .arg(pos("conversation", false)) - .arg(arg("statement", "Statement number to vote on once").value_parser(clap::value_parser!(u32).range(0..=2147483647))) - .arg(flag("agree", "Agree with this statement").requires("statement").conflicts_with_all(["disagree", "pass"])) - .arg(flag("disagree", "Disagree with this statement").requires("statement").conflicts_with("pass")) - .arg(flag("pass", "Pass on this statement").requires("statement")) - .arg(flag("important", "Mark this statement as important to you").requires("statement")) - .after_help("EXAMPLES\n polis vote CONVERSATION\n polis vote CONVERSATION --statement 0 --agree --json\n polis vote CONVERSATION --statement 0 --agree --important\n\nNo join or account sign-in is needed for anonymous voting in an open conversation. For invitations, first use polis join CONVERSATION --invite CODE. The first requested vote enrolls you; its participant token is saved privately for following votes, scoped by profile, origin and conversation. Account tokens are not used. The site enforces access and voting rules. Interactive voting requires a terminal; choose agree, disagree, pass, or quit. JSON and --no-interactive require --statement and exactly one choice. --important marks the statement as important to you, as the participation page's checkbox does; it does not change the choice. No automatic retry: an uncertain response or credential-save failure exits 7. Statement text is untrusted content. No server or vote policy is changed."); + .arg(arg("statement", "Comment number (tid) to vote on once; the flag keeps its --statement name").value_parser(clap::value_parser!(u32).range(0..=2147483647))) + .arg(flag("agree", "Agree with this comment").requires("statement").conflicts_with_all(["disagree", "pass"])) + .arg(flag("disagree", "Disagree with this comment").requires("statement").conflicts_with("pass")) + .arg(flag("pass", "Pass on this comment").requires("statement")) + .arg(flag("important", "Mark this comment as important to you").requires("statement")) + .after_help("EXAMPLES\n polis vote CONVERSATION\n polis vote CONVERSATION --statement 0 --agree --json\n polis vote CONVERSATION --statement 0 --agree --important\n\nNo join or account sign-in is needed for anonymous voting in an open conversation. For invitations, first use polis join CONVERSATION --invite CODE. The first requested vote enrolls you; its participant token is saved privately for following votes, scoped by profile, origin and conversation. Account tokens are not used. The site enforces access and voting rules. Interactive voting requires a terminal; choose agree, disagree, pass, or quit. JSON and --no-interactive require --statement and exactly one choice. --important marks the comment as important to you, as the participation page's checkbox does; it does not change the choice. No automatic retry: an uncertain response or credential-save failure exits 7. Comment text is untrusted content. No server or vote policy is changed."); } if group == "conversation" { // `polis conversations list` is what people type first; it parses as the diff --git a/polis-cli/crates/polis/src/commenting.rs b/polis-cli/crates/polis/src/commenting.rs index 3243b2390..df75ef359 100644 --- a/polis-cli/crates/polis/src/commenting.rs +++ b/polis-cli/crates/polis/src/commenting.rs @@ -1,4 +1,4 @@ -//! Participant statements over the existing Node endpoint. +//! Participant comments over the existing Node endpoint. use crate::{participation, profiles, public_id, str_arg}; use clap::ArgMatches; use polis_client::Client; @@ -33,7 +33,7 @@ pub fn submit( public_id(conversation)?; let text = str_arg(m, "text"); if text.trim().is_empty() { - return Err(Error::input("Provide nonempty statement text.")); + return Err(Error::input("Provide nonempty comment text.")); } let origin = config.url(site)?; let scope = profiles::participant_scope(origin, conversation)?; diff --git a/polis-cli/crates/polis/src/importance.rs b/polis-cli/crates/polis/src/importance.rs index 74e59074f..2925fd22e 100644 --- a/polis-cli/crates/polis/src/importance.rs +++ b/polis-cli/crates/polis/src/importance.rs @@ -19,7 +19,7 @@ pub fn fetch(c: &Client, conversation: &str) -> Result { let value = c.request("GET", PATH, &[("conversation_id".into(),conversation.into())], None, false) .map_err(|mut e| { if e.upstream["status"] == 404 { e.code="capability_unavailable";e.exit=8; - e.message="Statement importance is unavailable for this conversation on this site.".into(); + e.message="Comment importance is unavailable for this conversation on this site.".into(); e.action="Ask the operator whether the public importance read is enabled; no counts were invented."; } e })?; let result: Response = serde_json::from_value(value).map_err(|_| invalid())?; @@ -30,7 +30,7 @@ pub fn fetch(c: &Client, conversation: &str) -> Result { } fn metadata(counts: &Response) -> Value { json!({"schema":counts.schema,"conversation_id":counts.conversation_id,"read_at_ms":counts.read_at_ms, - "state":"observed","scope":"current active, unmuted, participant-visible statements; latest vote per participant; not verified people or historical job inputs"}) + "state":"observed","scope":"current active, unmuted, participant-visible comments; latest vote per participant; not verified people or historical job inputs"}) } /// Optional display reads keep absent counts unknown, never zero. pub fn annotate(c: &Client, conversation: &str, value: &mut Value) -> Result<()> { @@ -133,13 +133,13 @@ pub fn list( Ok( json!({"comments":rows,"pagination":{"total":total,"limit":limit,"offset":offset,"has_more":offset.saturating_add(limit) Error { Error::new( "importance_changed", - "The selected statements changed or the text response did not match the importance read.", + "The selected comments changed or the text response did not match the importance read.", "Read again to get a fresh count snapshot. No partial ranking was printed.", 1, ) diff --git a/polis-cli/crates/polis/src/main.rs b/polis-cli/crates/polis/src/main.rs index defeb654a..e9872a851 100644 --- a/polis-cli/crates/polis/src/main.rs +++ b/polis-cli/crates/polis/src/main.rs @@ -221,20 +221,20 @@ fn execute(root: &ArgMatches, config: &mut profiles::Config, site: &str) -> Resu "metadata question add" | "context create" => { pass9::execute(&path, m, config, site, timeout) } - "statement list" - | "statement view" + "comment list" + | "comment view" | "collective list" | "collective view" | "collective statements" => pass7::execute(&path, m, config, site, timeout), "delphi show" => delphi_show::execute(m, config, site, timeout), "topic list" - | "topic statements" + | "topic comments" | "topic hierarchy" | "topic proximity" | "topic stats" | "report topics" | "report stats" - | "report statements list" => pass6::execute(&path, m, config, site, timeout), + | "report comments list" => pass6::execute(&path, m, config, site, timeout), "account view" | "conversation edit" | "conversation share" | "conversation stats" | "report create" => pass5::execute(&path, m, config, site, timeout), "conversation close" @@ -525,7 +525,7 @@ fn execute(root: &ArgMatches, config: &mut profiles::Config, site: &str) -> Resu true, ) { Ok(receipt) if receipt["status"] == "processing" => Ok( - json!({"state":"processing","seeds":seeds,"votes":{"state":"processing","submitted":count,"source_agree":str_arg(m,"source-agree"),"receipt":receipt},"note":"Statement import is complete; votes are queued, not completed. Check the site import notification and read back before retrying."}), + json!({"state":"processing","seeds":seeds,"votes":{"state":"processing","submitted":count,"source_agree":str_arg(m,"source-agree"),"receipt":receipt},"note":"Comment import is complete; votes are queued, not completed. Check the site import notification and read back before retrying."}), ), Ok(receipt) => Ok( json!({"state":"partial_or_unknown","seeds":seeds,"votes":{"state":"unknown","receipt":receipt},"receipt":data}), @@ -796,7 +796,7 @@ fn main() -> ExitCode { { if let Ok(value) = &result { if let Some(choice) = value["choice"].as_str() { - println!("Recorded {choice} for statement {}.", value["statement"]); + println!("Recorded {choice} for comment {}.", value["statement"]); } else { println!("Voting finished. {} vote(s) recorded.", value["recorded"]); } @@ -816,7 +816,7 @@ fn main() -> ExitCode { if !json_mode && root.subcommand_name() == Some("comment") { if let Ok(value) = &result { println!( - "Submitted statement {}. The site determines moderation and visibility.", + "Submitted comment {}. The site determines moderation and visibility.", value["statement"] ); return ExitCode::SUCCESS; diff --git a/polis-cli/crates/polis/src/pass6.rs b/polis-cli/crates/polis/src/pass6.rs index 47af79773..f236a7016 100644 --- a/polis-cli/crates/polis/src/pass6.rs +++ b/polis-cli/crates/polis/src/pass6.rs @@ -52,7 +52,7 @@ pub fn execute( str_arg(m, if is_report { "id" } else { "conversation" }) }; public_id(id)?; - let topic = if path == "topic statements" { + let topic = if path == "topic comments" { Some(topic_path(str_arg(m, "key"))?) } else { None @@ -117,7 +117,7 @@ pub fn execute( } "/api/v3/conversationStats" } - "report statements list" => { + "report comments list" => { query.extend([ ("report_id".into(), id.into()), ( @@ -137,7 +137,7 @@ pub fn execute( } "/api/v3/topicMod/topics" } - "topic statements" => topic.as_deref().unwrap(), + "topic comments" => topic.as_deref().unwrap(), "topic hierarchy" => "/api/v3/topicMod/hierarchy", "topic proximity" => { query.push(("layer_id".into(), str_arg(m, "layer").into())); @@ -156,12 +156,12 @@ pub fn execute( // moderation_available=false and null/empty results. Do not invent freshness. let valid = match path { "report stats" => v["voteTimes"].is_array() && v["commentTimes"].is_array(), - "report statements list" => v["comments"].is_array() && v["pagination"].is_object(), + "report comments list" => v["comments"].is_array() && v["pagination"].is_object(), _ if v["status"] != "success" => false, "topic list" | "report topics" => { v["topics"].is_array() || v["topics_by_layer"].is_object() } - "topic statements" => v["comments"].is_array(), + "topic comments" => v["comments"].is_array(), "topic hierarchy" => v .get("hierarchy") .is_some_and(|h| h.is_null() || h.is_object()), @@ -172,7 +172,7 @@ pub fn execute( if !valid { return Err(response_error()); } - if path == "report statements list" { + if path == "report comments list" { crate::importance::annotate(&c, &conversation, &mut v)?; } Ok(v) diff --git a/polis-cli/crates/polis/src/pass7.rs b/polis-cli/crates/polis/src/pass7.rs index dad02a492..90d45302b 100644 --- a/polis-cli/crates/polis/src/pass7.rs +++ b/polis-cli/crates/polis/src/pass7.rs @@ -10,7 +10,7 @@ fn unavailable(collective: bool) -> Error { if collective { Error::new("collective_statement_unavailable", "The stored collective statement was not found.", "Run polis collective list --report and copy an exact zid_topic_jobid; this read will not generate a replacement.", 1) } else { - Error::new("statement_unavailable", "This statement is absent or not participant-visible.", "Check the conversation and statement number. Authorized moderators can inspect hidden statements with polis moderate list.", 1) + Error::new("statement_unavailable", "This comment is absent or not participant-visible.", "Check the conversation and comment number. Authorized moderators can inspect hidden comments with polis moderate list.", 1) } } fn read_error(mut e: Error, collective: bool, single: bool) -> Error { @@ -28,11 +28,16 @@ fn read_error(mut e: Error, collective: bool, single: bool) -> Error { } else { "statements_read_failed" }; - e.message = "The site could not read the requested stored statements.".into(); + e.message = if collective { + "The site could not read the requested stored collective statements." + } else { + "The site could not read the requested comments." + } + .into(); e.action = if collective { - "Check the report or stored statement ID and site. Ask the operator to inspect collective-statement storage; retrying this read does not generate content." + "Check the report or stored collective statement ID and site. Ask the operator to inspect collective-statement storage; retrying this read does not generate content." } else { - "Check the conversation, statement number and pagination. Ask the operator to inspect statement reads; use moderate list for hidden statements if authorized." + "Check the conversation, comment number and pagination. Ask the operator to inspect comment reads; use moderate list for hidden comments if authorized." }; } e @@ -89,7 +94,7 @@ pub fn execute( } } let c = public_client(config, site, timeout)?; - if path == "statement list" + if path == "comment list" && (m.get_one::("sort").is_some() || m.get_one::("min-important").is_some()) { return crate::importance::list( diff --git a/polis-cli/crates/polis/src/prioritize.rs b/polis-cli/crates/polis/src/prioritize.rs index 53b293cf0..268169c65 100644 --- a/polis-cli/crates/polis/src/prioritize.rs +++ b/polis-cli/crates/polis/src/prioritize.rs @@ -373,9 +373,9 @@ pub fn execute( &topics, )?; if let Some(i) = groups.iter().position(Vec::is_empty) { - return Err(unavailable(i + 1, "has no statements in the conversation's stored topic coordinates, so its representative statements cannot be chosen")); + return Err(unavailable(i + 1, "has no comments in the conversation's stored topic coordinates, so its representative comments cannot be chosen")); } - // The page reads statement text from the moderation listing; its vote + // The page reads comment text from the moderation listing; its vote // counts are not needed for the text, so they are not requested. let texts = texts( &c.request( diff --git a/polis-cli/crates/polis/src/reads.rs b/polis-cli/crates/polis/src/reads.rs index 7b6b19acc..3ab743365 100644 --- a/polis-cli/crates/polis/src/reads.rs +++ b/polis-cli/crates/polis/src/reads.rs @@ -161,7 +161,7 @@ pub fn execute( .ok_or_else(|| { Error::new( "not_found", - "Statement not found in this moderation view.", + "Comment not found in this moderation view.", "Read the moderation list and check permissions.", 1, ) diff --git a/polis-cli/crates/polis/src/seeds.rs b/polis-cli/crates/polis/src/seeds.rs index b80830b5b..04b1e2f8e 100644 --- a/polis-cli/crates/polis/src/seeds.rs +++ b/polis-cli/crates/polis/src/seeds.rs @@ -4,7 +4,7 @@ use std::collections::HashSet; pub fn text(value: &str) -> Result<()> { if value.trim().is_empty() || value.encode_utf16().count() > 997 || value.contains('\0') { return Err(Error::input( - "Statement must contain text, no NUL, and at most 997 UTF-16 units.", + "Comment must contain text, no NUL, and at most 997 UTF-16 units.", )); } Ok(()) @@ -41,7 +41,7 @@ pub fn validate(raw: &str) -> Result> { })?; let t = &row[ti]; let id = &row[oi]; - text(t).map_err(|_| Error::input(format!("Invalid statement in CSV record {}.", i + 2)))?; + text(t).map_err(|_| Error::input(format!("Invalid comment in CSV record {}.", i + 2)))?; let canonical = uuid::Uuid::parse_str(id) .map(|u| u.to_string()) .unwrap_or_else(|_| id.to_owned()); @@ -58,11 +58,11 @@ pub fn validate(raw: &str) -> Result> { } rows.push(json!({"record":i+2,"comment_text":t,"original_id":id})); if rows.len() > 1000 { - return Err(Error::input("Import at most 1000 statements per file.")); + return Err(Error::input("Import at most 1000 comments per file.")); } } if rows.is_empty() { - return Err(Error::input("CSV contains no statements.")); + return Err(Error::input("CSV contains no comments.")); } Ok(rows) } @@ -71,7 +71,7 @@ pub fn validate(raw: &str) -> Result> { // receive the same input; no receipt field is removed from the comparison. #[cfg(feature = "fixture-ids")] fn fixture_id(value: &str) -> Result { - uuid::Uuid::parse_str(value).map_err(|_| Error::input("Invalid fixture statement UUID.")) + uuid::Uuid::parse_str(value).map_err(|_| Error::input("Invalid fixture comment UUID.")) } fn statement_id() -> Result { #[cfg(feature = "fixture-ids")] @@ -79,7 +79,7 @@ fn statement_id() -> Result { return fixture_id( value .to_str() - .ok_or_else(|| Error::input("Invalid fixture statement UUID."))?, + .ok_or_else(|| Error::input("Invalid fixture comment UUID."))?, ); } Ok(uuid::Uuid::new_v4()) @@ -89,10 +89,10 @@ pub fn single(value: &str) -> Result { let mut writer = csv::Writer::from_writer(Vec::new()); writer .write_record(["comment_text", "original_id"]) - .map_err(|_| Error::input("Cannot encode statement."))?; + .map_err(|_| Error::input("Cannot encode comment."))?; writer .write_record([value, &statement_id()?.to_string()]) - .map_err(|_| Error::input("Cannot encode statement."))?; + .map_err(|_| Error::input("Cannot encode comment."))?; Ok(String::from_utf8(writer.into_inner().unwrap()).unwrap()) } @@ -140,7 +140,7 @@ pub(crate) fn strict_csv(raw: &str) -> Result<()> { } // Keep external identifiers in the receipt; PostgreSQL receives a stable UUID. -// Domain separation binds mappings to a site AND conversation, never statement text. +// Domain separation binds mappings to a site AND conversation, never comment text. pub fn submission(raw: &str, origin: &str, conversation: &str) -> Result<(String, Vec)> { let rows = validate(raw)?; let origin = polis_client::base_url(origin)?.to_string(); diff --git a/polis-cli/crates/polis/src/voting.rs b/polis-cli/crates/polis/src/voting.rs index 8e743ab21..6f29f5c02 100644 --- a/polis-cli/crates/polis/src/voting.rs +++ b/polis-cli/crates/polis/src/voting.rs @@ -173,7 +173,7 @@ pub fn execute( let mut recorded = 0u64; loop { let Some(stmt) = next(config, site, timeout, conversation)? else { - writeln!(output, "No more statements available.").map_err(io_error)?; + writeln!(output, "No more comments available.").map_err(io_error)?; break; }; let Some(choice) = prompt(&mut input, &mut output, &stmt)? else { @@ -199,7 +199,7 @@ fn prompt( .chars() .filter(|&c| !c.is_control() && !crate::listing::invisible(c)) .collect(); - writeln!(output, "\nStatement {}: {text}", stmt.tid).map_err(io_error)?; + writeln!(output, "\nComment {}: {text}", stmt.tid).map_err(io_error)?; loop { write!(output, "[a]gree / [d]isagree / [p]ass / [q]uit: ").map_err(io_error)?; output.flush().map_err(io_error)?; diff --git a/polis-cli/crates/polis/tests/cli.rs b/polis-cli/crates/polis/tests/cli.rs index 06732c666..ab2dc155b 100644 --- a/polis-cli/crates/polis/tests/cli.rs +++ b/polis-cli/crates/polis/tests/cli.rs @@ -1134,7 +1134,7 @@ fn admin_report_write_resolves_its_conversation_before_mutation() { #[test] fn participant_admin_defaults_to_scoped_identity_and_account_is_explicit() { let args = [ - "statement", + "comment", "star", "--conversation", "abc", diff --git a/polis-cli/crates/polis/tests/comment_naming.rs b/polis-cli/crates/polis/tests/comment_naming.rs new file mode 100644 index 000000000..6a43c99fc --- /dev/null +++ b/polis-cli/crates/polis/tests/comment_naming.rs @@ -0,0 +1,52 @@ +use serde_json::Value; +use std::process::Command; +fn run(args: &[&str]) -> (i32, Value) { + let dir = tempfile::tempdir().unwrap(); + std::fs::write( + dir.path().join("profiles.json"), + r#"{"default":"local","sites":{"local":"http://127.0.0.1:9"}}"#, + ) + .unwrap(); + let o = Command::new(env!("CARGO_BIN_EXE_polis")) + .env("POLIS_CONFIG_DIR", dir.path()) + .args(args) + .arg("--json") + .output() + .unwrap(); + ( + o.status.code().unwrap(), + serde_json::from_slice(&o.stdout).unwrap(), + ) +} +#[test] +fn participant_reads_are_comment_commands_and_collective_statements_remain() { + for args in [ + vec!["help", "comment", "list"], + vec!["help", "comment", "view"], + vec!["help", "report", "comments", "list"], + vec!["help", "collective", "statements"], + ] { + let (exit, v) = run(&args); + assert_eq!(exit, 0, "{args:?} {v}"); + } +} +#[test] +fn next_is_discoverable_with_its_existing_participant_read_contract() { + let (exit, v) = run(&["schema", "comment", "next"]); + assert_eq!(exit, 0, "{v}"); + assert_eq!(v["data"]["implemented"], true); + assert!(v["data"]["description"] + .as_str() + .unwrap() + .contains("without casting a vote")); + assert_eq!(run(&["comment", "next", "--conversation", "bad/id"]).0, 2); +} +#[test] +fn old_participant_read_names_no_longer_parse() { + for args in [ + vec!["help", "statement", "list"], + vec!["help", "report", "statements", "list"], + ] { + assert_eq!(run(&args).0, 2, "{args:?}"); + } +} diff --git a/polis-cli/crates/polis/tests/commenting.rs b/polis-cli/crates/polis/tests/commenting.rs index fce7c421b..a854dbed1 100644 --- a/polis-cli/crates/polis/tests/commenting.rs +++ b/polis-cli/crates/polis/tests/commenting.rs @@ -303,7 +303,7 @@ fn comment_discovery_and_human_receipt_omit_text() { .unwrap(); assert!(out.status.success()); let text = String::from_utf8(out.stdout).unwrap(); - assert!(text.contains("Submitted statement 0")); + assert!(text.contains("Submitted comment 0")); assert!(!text.contains(TEXT)); assert!(!text.contains(TOKEN)); t.join().unwrap(); diff --git a/polis-cli/crates/polis/tests/importance.rs b/polis-cli/crates/polis/tests/importance.rs index 5ae7bbda4..31a5e6820 100644 --- a/polis-cli/crates/polis/tests/importance.rs +++ b/polis-cli/crates/polis/tests/importance.rs @@ -105,7 +105,7 @@ fn importance_sort_ranks_before_pagination_and_joins_exact_tids() { let (exit, v) = call( t.path(), &[ - "statement", + "comment", "list", "--conversation", "convA", @@ -144,7 +144,7 @@ fn importance_filter_only_uses_tid_order_and_empty_rank_needs_no_text_read() { let (exit, v) = call( t.path(), &[ - "statement", + "comment", "list", "--conversation", "convA", @@ -179,7 +179,7 @@ fn importance_ties_reorder_text_exactly_and_preserve_metadata() { let (exit, v) = call( t.path(), &[ - "statement", + "comment", "list", "--conversation", "convA", @@ -231,7 +231,7 @@ fn importance_invalid_contracts_never_print_partial_rank() { let (exit, v) = call( t.path(), &[ - "statement", + "comment", "list", "--conversation", "convA", @@ -258,7 +258,7 @@ fn importance_missing_duplicate_or_unrequested_text_fails_closed() { let (exit, v) = call( t.path(), &[ - "statement", + "comment", "list", "--conversation", "convA", @@ -289,7 +289,7 @@ fn importance_disabled_is_capability_unavailable_without_text_read() { let (exit, v) = call( t.path(), &[ - "statement", + "comment", "list", "--conversation", "convA", @@ -320,7 +320,7 @@ fn report_statement_counts_include_zero_and_keep_unobserved_unknown() { ); let (exit, v) = call( t.path(), - &["report", "statements", "list", "repA"], + &["report", "comments", "list", "repA"], None, false, ); @@ -346,7 +346,7 @@ fn report_statement_counts_unavailable_remain_unknown_without_hiding_rows() { ); let (exit, v) = call( t.path(), - &["report", "statements", "list", "repA"], + &["report", "comments", "list", "repA"], None, false, ); @@ -358,7 +358,7 @@ fn report_statement_counts_unavailable_remain_unknown_without_hiding_rows() { } fn assert_statement_list_rejects(args: &[&str]) { let t = tempfile::tempdir().unwrap(); - let mut full = vec!["statement", "list", "--conversation", "convA"]; + let mut full = vec!["comment", "list", "--conversation", "convA"]; full.extend(args); let (exit, _) = call(t.path(), &full, None, false); assert_eq!(exit, 2, "{args:?}"); diff --git a/polis-cli/crates/polis/tests/pass6.rs b/polis-cli/crates/polis/tests/pass6.rs index c74c941b8..52f12102e 100644 --- a/polis-cli/crates/polis/tests/pass6.rs +++ b/polis-cli/crates/polis/tests/pass6.rs @@ -121,7 +121,7 @@ fn topic_key_is_one_encoded_segment_and_round_trips_special_characters() { t.path(), &[ "topic", - "statements", + "comments", "job#0#1?%&猫", "--conversation", "convA" @@ -154,7 +154,7 @@ fn unsafe_topic_inputs_refuse_before_network() { assert_eq!( parsed_call( t.path(), - &["topic", "statements", key, "--conversation", "convA"] + &["topic", "comments", key, "--conversation", "convA"] ) .0, 2 @@ -247,14 +247,14 @@ fn missing_store_is_not_empty_success_and_diagnostics_are_not_reflected() { let s=server(t.path(),vec![(503,"application/json",json!({"error":"polis_err_topicMod_comments_store_missing","details":"private-upstream-detail"}).to_string())]); let (exit, v) = parsed_call( t.path(), - &["topic", "statements", "job#0#1", "--conversation", "convA"], + &["topic", "comments", "job#0#1", "--conversation", "convA"], ); assert_eq!(exit, 6); assert_eq!(v["error"]["code"], "topic_statements_unavailable"); assert!(v["error"]["action"] .as_str() .unwrap() - .contains("report statements list")); + .contains("report comments list")); assert!(!v.to_string().contains("private-upstream-detail")); assert_eq!(s.join().unwrap().len(), 1); } @@ -316,14 +316,7 @@ fn report_reads_resolve_the_matching_conversation_and_preserve_fields() { ), ( vec![ - "report", - "statements", - "list", - "rA", - "--limit", - "2", - "--offset", - "4", + "report", "comments", "list", "rA", "--limit", "2", "--offset", "4", ], json!({"comments":[{"tid":4,"includeInReport":false}],"pagination":{"total":5}}), "/api/v3/comments?conversation_id=convA&report_id=rA&limit=2&offset=4", @@ -332,7 +325,7 @@ fn report_reads_resolve_the_matching_conversation_and_preserve_fields() { let t = tempfile::tempdir().unwrap(); let mut responses = vec![json_res(report()), json_res(body.clone())]; let mut expected = body.clone(); - if args[1] == "statements" { + if args[1] == "comments" { responses.push((404, "text/html", "Cannot GET importance".into())); expected["comments"][0]["important"] = Value::Null; expected["comments"][0]["voters"] = Value::Null; @@ -390,9 +383,9 @@ fn help_describes_read_semantics_and_schema_lists_arguments() { let t = tempfile::tempdir().unwrap(); for (args, expected) in [ (vec!["help", "topic", "list"], "moderation_available=false"), - (vec!["help", "topic", "statements"], "missing"), + (vec!["help", "topic", "comments"], "missing"), ( - vec!["help", "report", "statements", "list"], + vec!["help", "report", "comments", "list"], "participant-visible", ), (vec!["help", "report", "stats"], "historical event"), diff --git a/polis-cli/crates/polis/tests/pass7.rs b/polis-cli/crates/polis/tests/pass7.rs index 17332ba7c..0a200cc02 100644 --- a/polis-cli/crates/polis/tests/pass7.rs +++ b/polis-cli/crates/polis/tests/pass7.rs @@ -100,7 +100,7 @@ fn public_statement_list_is_paginated_and_preserves_rows() { let (exit, v) = call( t.path(), &[ - "statement", + "comment", "list", "--conversation", "convA", @@ -126,7 +126,7 @@ fn statement_view_filters_exact_tid_and_returns_the_unchanged_row() { let s = server(t.path(), vec![json_res(page(json!([row.clone()])))]); let (exit, v) = parsed_call( t.path(), - &["statement", "view", "0", "--conversation", "convA"], + &["comment", "view", "0", "--conversation", "convA"], ); assert_eq!(exit, 0); assert_eq!(v["data"], row); @@ -136,8 +136,8 @@ fn statement_view_filters_exact_tid_and_returns_the_unchanged_row() { #[test] fn empty_list_succeeds_but_hidden_or_missing_single_is_unavailable() { for (args, expected) in [ - (vec!["statement", "list", "--conversation", "convA"], 0), - (vec!["statement", "view", "0", "--conversation", "convA"], 1), + (vec!["comment", "list", "--conversation", "convA"], 0), + (vec!["comment", "view", "0", "--conversation", "convA"], 1), ] { let t = tempfile::tempdir().unwrap(); let s = server(t.path(), vec![json_res(page(json!([])))]); @@ -167,7 +167,7 @@ fn mismatched_duplicate_or_malformed_statement_rows_are_errors() { let s = server(t.path(), vec![json_res(body)]); let (exit, v) = parsed_call( t.path(), - &["statement", "view", "0", "--conversation", "convA"], + &["comment", "view", "0", "--conversation", "convA"], ); assert_eq!(exit, 1); assert_eq!(v["error"]["code"], "invalid_response"); @@ -276,7 +276,7 @@ fn read_failures_keep_status_and_suppress_upstream_prose_without_retry() { for status in [200, 500] { for args in [ vec!["collective", "list", "--report", "rA"], - vec!["statement", "list", "--conversation", "convA"], + vec!["comment", "list", "--conversation", "convA"], ] { let t = tempfile::tempdir().unwrap(); let s = server( @@ -328,17 +328,10 @@ fn invalid_parameters_are_refused_before_http() { ) .unwrap(); for args in [ - vec!["statement", "view", "2147483648", "--conversation", "convA"], - vec!["statement", "view", "-1", "--conversation", "convA"], - vec!["statement", "list", "--conversation", "../x"], - vec![ - "statement", - "list", - "--conversation", - "convA", - "--limit", - "0", - ], + vec!["comment", "view", "2147483648", "--conversation", "convA"], + vec!["comment", "view", "-1", "--conversation", "convA"], + vec!["comment", "list", "--conversation", "../x"], + vec!["comment", "list", "--conversation", "convA", "--limit", "0"], vec!["collective", "list", "--report", "r?x"], vec!["collective", "view", ""], vec!["collective", "view", "a\nb"], @@ -354,8 +347,8 @@ fn invalid_parameters_are_refused_before_http() { fn manuals_and_schema_expose_the_stored_read_limits() { let t = tempfile::tempdir().unwrap(); for (args, text) in [ - (vec!["help", "statement", "list"], "participant"), - (vec!["help", "statement", "view"], "statement_unavailable"), + (vec!["help", "comment", "list"], "participant"), + (vec!["help", "comment", "view"], "statement_unavailable"), (vec!["help", "collective", "list"], "deduplication"), (vec!["help", "collective", "view"], "JSON strings"), ] { @@ -364,7 +357,7 @@ fn manuals_and_schema_expose_the_stored_read_limits() { assert!(v["data"]["help"].as_str().unwrap().contains(text)); } for args in [ - vec!["schema", "statement", "view"], + vec!["schema", "comment", "view"], vec!["schema", "collective", "view"], ] { let (exit, v) = call(t.path(), &args, None, false); diff --git a/polis-cli/crates/polis/tests/voting.rs b/polis-cli/crates/polis/tests/voting.rs index 0d459c6b9..87f3aaf0c 100644 --- a/polis-cli/crates/polis/tests/voting.rs +++ b/polis-cli/crates/polis/tests/voting.rs @@ -278,7 +278,7 @@ fn important_needs_one_explicit_vote_and_sends_nothing_otherwise() { .find(|a| a["name"] == "important") .unwrap(); assert_eq!(important["long"], "important"); - assert_eq!(important["help"], "Mark this statement as important to you"); + assert_eq!(important["help"], "Mark this comment as important to you"); } #[test] fn invite_vote_reuses_participant_and_preserves_returning_login_secret() { diff --git a/polis-cli/docs/admin-operations.md b/polis-cli/docs/admin-operations.md index d95a17487..6ff37de6f 100644 --- a/polis-cli/docs/admin-operations.md +++ b/polis-cli/docs/admin-operations.md @@ -43,8 +43,8 @@ This reconciles all 77 initially missing application routes against the current | GET | `/api/v3/dataExport` | `polis report export-start` | | GET | `/api/v3/notifications/subscribe` | `polis notification subscribe` | | GET | `/api/v3/notifications/unsubscribe` | `polis notification unsubscribe` | -| GET | `/api/v3/comments/translations` | `polis statement translations` | -| GET | `/api/v3/nextComment` | `polis statement next` | +| GET | `/api/v3/comments/translations` | `polis comment translations` | +| GET | `/api/v3/nextComment` | `polis comment next` | | GET | `/api/v3/participationInit` | Already covered: `polis join` | | GET | `/api/v3/reportNarrative` | `polis delphi narrative run` | | GET | `/api/v3/verify` | `polis account verify` | @@ -65,11 +65,11 @@ This reconciles all 77 initially missing application routes against the current | PUT | `/api/v3/topicAgenda/selections` | `polis agenda replace` | | DELETE | `/api/v3/topicAgenda/selections` | `polis agenda remove` | | POST | `/api/v3/votes` | Already covered: `polis vote` | -| POST | `/api/v3/ptptCommentMod` | `polis statement flag` | +| POST | `/api/v3/ptptCommentMod` | `polis comment flag` | | POST | `/api/v3/upvotes` | `polis conversation upvote` | -| POST | `/api/v3/stars` | `polis statement star` | -| POST | `/api/v3/trashes` | `polis statement trash` | -| POST | `/api/v3/reportCommentSelections` | `polis report statements select` | +| POST | `/api/v3/stars` | `polis comment star` | +| POST | `/api/v3/trashes` | `polis comment trash` | +| POST | `/api/v3/reportCommentSelections` | `polis report comments select` | | PUT | `/api/v3/users` | `polis account edit` | | POST | `/api/v3/mathUpdate` | `polis math refresh` | | PUT | `/api/v3/reports` | `polis report edit` | @@ -82,13 +82,13 @@ This reconciles all 77 initially missing application routes against the current | POST | `/api/v3/users/invite` | `polis account invite` | | POST | `/api/v3/contributors` | `polis support contribute` | -Counts: 65 dedicated operations in this packet, 7 already covered routes, and 5 retired/excluded routes. The dedicated next-statement command supplements the existing interactive vote loop. A route is not marked implemented merely because generic `api` can reach it. +Counts: 65 dedicated operations in this packet, 7 already covered routes, and 5 retired/excluded routes. The dedicated `comment next` command supplements the existing interactive vote loop. A route is not marked implemented merely because generic `api` can reach it. ## Request and output rules Account operations use the selected profile’s sign-in. Participant operations use only that profile/origin/conversation’s participant credential by default; `--account` explicitly selects the account instead. No participant action silently falls back to an administrator identity. An issued participant token is saved privately and removed from the receipt. Plain anonymous join and voting retain their existing meanings. -Every effectful operation requires `--yes`, including effectful GETs. The site still decides authority. A write receipt reports `response_received`, not completion or a confirmed readback; errors and lost responses must be inspected before retrying. Report edits and statement selection resolve the conversation from the report, so the CLI never submits independently chosen report/conversation pairs. No automatic retry is made. +Every effectful operation requires `--yes`, including effectful GETs. The site still decides authority. A write receipt reports `response_received`, not completion or a confirmed readback; errors and lost responses must be inspected before retrying. Report edits and report comment selection resolve the conversation from the report, so the CLI never submits independently chosen report/conversation pairs. No automatic retry is made. Downloads require `--output`, create a private file, and refuse overwrite. HTML/RSS is stored as untrusted bytes, never evaluated or opened. Public feed/performance reads have a separate exact path allowlist, never send credentials or follow redirects, and do not widen the raw API command’s prefix restriction. API responses and files are bounded to 8 MiB; input files to 500,000 bytes, secret files to 4,096 bytes. @@ -103,7 +103,7 @@ Wire vote projections are labeled with the existing shared vote contract; no rea - Upvote applies to the conversation and can be submitted once by an account. - Export results requires the complete export filename and saves the returned signed HTTPS URL to `--output`. It does not follow the redirect or verify that the object exists; the receipt and saved JSON explicitly say `artifact_verified: false`. - Provider/job commands may start paid work when a site enables them; their receipt is not a completed analysis. No provider or worker is started by the CLI itself. -- Topic moderation can partially apply explicit statement IDs before a missing topic store fails. +- Topic moderation can partially apply explicit comment IDs before a missing topic store fails. - Recent-conversation feeds and the global conversation list require Node developer authority; ordinary account ownership does not grant it. - Operator API access uses the site’s operator gate. The legacy performance route is public today; this client adds no gate or claim that it is private. - The XID capability export downloads the participant-to-XID map and requires the selected account’s bearer token. Sign in as an owner or moderator. The server must enforce that authority; older servers may still accept possession of the UUID. This CLI requires sign-in even on those servers. A UUID file alone is insufficient for this command. The command never uses a participant token or anonymous fallback. @@ -114,7 +114,7 @@ Wire vote projections are labeled with the existing shared vote contract; no rea The generated fixture tests current behavior without changing Node policy: -- Statement star can persist its row then fail because the handler expects `result.rows` from a rows-returning helper. Exit 7 is intentional; inspect the resource before retrying. The handler SHOULD consume the actual result shape. +- Comment star can persist its row then fail because the handler expects `result.rows` from a rows-returning helper. Exit 7 is intentional; inspect the resource before retrying. The handler SHOULD consume the actual result shape. - `as_unsure` is accepted by route middleware, while the current flag handler reads `unsure`; this choice does not persist as intended. The handler SHOULD use the parsed field. Other flags retain their existing behavior. - The translations GET route does not move query parameters into the parsed body. Its standard GET query is rejected; the route SHOULD use the same query parsing as other GET endpoints. The CLI does not send a nonstandard GET body to hide that defect. - Contributor agreement submission has no backing table in the repository migrations and returns unavailable. The server SHOULD explicitly retire it or provide its declared storage. @@ -167,8 +167,8 @@ Use `polis help ` or `polis schema ` for parser discovery. The | `notification subscribe` | `--conversation` id required; `--email` text (max 999) required; `--signature-file` secret_file required | | `notification unsubscribe` | `--conversation` id required; `--email` text (max 999) required; `--signature-file` secret_file required | | `notification set` | `--conversation` id required; `--state` mapped: subscribe, unsubscribe required; `--email` text (max 999) required | -| `statement translations` | `--conversation` id required; `--statement` uint optional; `--language` text (max 10) optional | -| `statement next` | `--conversation` id required | +| `comment translations` | `--conversation` id required; `--statement` uint optional; `--language` text (max 10) optional | +| `comment next` | `--conversation` id required | | `delphi narrative run` | `--report` id required | | `account verify` | `--code-file` secret_file required | | `participant tutorial` | `--step` uint required | @@ -179,11 +179,11 @@ Use `polis help ` or `polis schema ` for parser discovery. The | `agenda add` | `--conversation` id required; `--from` array_file required | | `agenda replace` | `--conversation` id required; `--from` array_file required | | `agenda remove` | `--conversation` id required | -| `statement flag` | `--conversation` id required; `--statement` uint required; `--as-abusive` bool optional; `--as-factual` bool optional; `--as-feeling` bool optional; `--as-important` bool optional; `--as-notfact` bool optional; `--as-notgoodidea` bool optional; `--as-notmyfeeling` bool optional; `--as-offtopic` bool optional; `--as-spam` bool optional; `--as-unsure` bool optional | +| `comment flag` | `--conversation` id required; `--statement` uint required; `--as-abusive` bool optional; `--as-factual` bool optional; `--as-feeling` bool optional; `--as-important` bool optional; `--as-notfact` bool optional; `--as-notgoodidea` bool optional; `--as-notmyfeeling` bool optional; `--as-offtopic` bool optional; `--as-spam` bool optional; `--as-unsure` bool optional | | `conversation upvote` | `--conversation` id required | -| `statement star` | `--conversation` id required; `--statement` uint required; `--state` mapped: on, off required | -| `statement trash` | `--conversation` id required; `--statement` uint required; `--state` mapped: on, off required | -| `report statements select` | `--report` id required; `--statement` uint required; `--include` bool required | +| `comment star` | `--conversation` id required; `--statement` uint required; `--state` mapped: on, off required | +| `comment trash` | `--conversation` id required; `--statement` uint required; `--state` mapped: on, off required | +| `report comments select` | `--report` id required; `--statement` uint required; `--include` bool required | | `account edit` | `--email` text (max 999) optional; `--name` text (max 9999) optional | | `math refresh` | `--conversation` id required; `--type` text: recompute, update required | | `report edit` | `--report` id required; `--name` text (max 999) optional; `--label-x-neg` text (max 999) optional; `--label-x-pos` text (max 999) optional; `--label-y-neg` text (max 999) optional; `--label-y-pos` text (max 999) optional; `--label-group-0` text (max 999) optional; `--label-group-1` text (max 999) optional; `--label-group-2` text (max 999) optional; `--label-group-3` text (max 999) optional; `--label-group-4` text (max 999) optional; `--label-group-5` text (max 999) optional; `--label-group-6` text (max 999) optional; `--label-group-7` text (max 999) optional; `--label-group-8` text (max 999) optional; `--label-group-9` text (max 999) optional | diff --git a/polis-cli/docs/json-output.md b/polis-cli/docs/json-output.md index ef3dc520c..34c0bb7be 100644 --- a/polis-cli/docs/json-output.md +++ b/polis-cli/docs/json-output.md @@ -43,9 +43,9 @@ instant. A failed or contradictory readback returns exit 7. Concurrent writes ma change it again; no compare-and-set guarantee is implied. Seed import without votes preserves `data.receipt` and `data.id_mapping`. -With votes, `data.seeds` retains the statement receipt/mapping and `data.votes` -records the separate stage. Complete statements followed by a `processing` vote -receipt exit 0 with `data.state:processing`. A partial statement response never +With votes, `data.seeds` retains the comment receipt/mapping and `data.votes` +records the separate stage. Complete comments followed by a `processing` vote +receipt exit 0 with `data.state:processing`. A partial comment response never submits votes. Vote upload refusal or lost response exits 1 as an overall partial import; inspect `data.votes.error.outcome` and preserve the successful seeds. Never rerun the entire import to repair the second stage. The current BYOD API @@ -97,14 +97,14 @@ error envelope. Pass six: stored topics and report reads polis topic list --conversation CONV --job JOB --json - polis topic statements 'JOB#0#1' --conversation CONV --json + polis topic comments 'JOB#0#1' --conversation CONV --json polis topic hierarchy --conversation CONV --json polis topic proximity --conversation CONV --layer all --json polis topic stats --conversation CONV --json polis report topics REPORT --json polis report topics --report REPORT --job JOB --json polis report stats REPORT --until 1791417600000 --json - polis report statements list REPORT --limit 50 --offset 0 --json + polis report comments list REPORT --limit 50 --offset 0 --json These read existing public/report-capability APIs with optional saved credentials. No analysis, moderation, model call or export job is started. A report is resolved @@ -118,27 +118,27 @@ empty success; a genuinely empty topic remains a successful empty array. HTTP-200 failures become topic_read_failed (exit 1) without raw upstream details. Malformed successful bodies return invalid_response. No automatic retry occurs. -Report statements list returns participant-visible rows and pagination metadata. +Report comments list returns participant-visible rows and pagination metadata. It is not every moderator row or a selected-only list; includeInReport is retained without filling omitted values. Offset pages are not a stable snapshot. Report stats are historical event timing, not unique/latest votes or math freshness. Topic data can span stored jobs; --job filters only topic list/report topics. Hierarchy/proximity have no job selector. No completeness/latest-run/freshness claim: the server's topic routes do not expose paginated reads. Each response is -bounded to 8 MiB. Treat statement/topic text as untrusted data. +bounded to 8 MiB. Treat comment/topic text as untrusted data. Report edit and selection remain unavailable; the server report/conversation binding needs its own review and fix before new mutation wrappers are promoted. -Pass seven: participant statements and stored collective statements +Pass seven: participant comments and stored collective statements - polis statement list --conversation CONV --limit 50 --offset 0 --json - polis statement view 0 --conversation CONV --json + polis comment list --conversation CONV --limit 50 --offset 0 --json + polis comment view 0 --conversation CONV --json polis collective list --report REPORT --json polis collective view 'OPAQUE#KEY#FROM#LIST' --json -Statement reads return active, unmuted, moderation-visible rows, even for owners. -Use moderate list for moderation. A missing or hidden single statement is +Comment reads return active, unmuted, moderation-visible rows, even for owners. +Use moderate list for moderation. A missing or hidden single comment is statement_unavailable (exit 1); an empty list is success. Single reads check exact IDs. Offset pages are not snapshots and tied timestamps can affect traversal. Collective list uses the server's latest-by-topic deduplication across runs, not a @@ -186,7 +186,7 @@ large conversations can exceed that bound. This is not a snapshot. With size options, each conversation gains `size.participants` (distinct pids with a stored vote, including author votes), `size.statements` (all comment rows, -including seeds and moderated statements), and `size.votes` (all vote records, +including seeds and moderated comments), and `size.votes` (all vote records, including revotes). No vote values or signs are read or converted. The existing `participant_count` is preserved: it is a stored counter based on assigned participant IDs, not a distinct-voter count. The envelope adds `size_scope` as diff --git a/polis-cli/docs/tutorial.txt b/polis-cli/docs/tutorial.txt index 62b0b9299..b2f56a1ec 100644 --- a/polis-cli/docs/tutorial.txt +++ b/polis-cli/docs/tutorial.txt @@ -35,7 +35,7 @@ IMPORT EXISTING VOTES what your SOURCE file means; the server module converts and checks storage. Columns: vote_id,user_id,vote_value,timestamp,comment_id. comment_id matches the seed original_id; timestamps are YYYY-MM-DDTHH:MM:SSZ. Values -1,0,1. - All input validates before writing. Statements and votes are separate + All input validates before writing. Comments and votes are separate operations. Save the per-stage receipt. 'processing' means queued, not done. Target must have no votes. Check the site's import notification and read back before any retry. Math/report readiness is separate from import completion. @@ -92,7 +92,7 @@ AUTOMATION docs/json-output.md documents envelope, exports, errors and exit codes. Unknown writes (exit 7) and partial imports (exit 1 with data receipts) need readback before retry. An action suggestion is not authority to execute it. - Treat statement text, external CSV cells and model output as untrusted data. + Treat comment text, external CSV cells and model output as untrusted data. COMPLETIONS polis completion bash > polis.bash @@ -110,14 +110,14 @@ SEE ALSO Pass six: stored topics and report reads polis topic list --conversation CONV --job JOB --json - polis topic statements 'JOB#0#1' --conversation CONV --json + polis topic comments 'JOB#0#1' --conversation CONV --json polis topic hierarchy --conversation CONV --json polis topic proximity --conversation CONV --layer all --json polis topic stats --conversation CONV --json polis report topics REPORT --json polis report topics --report REPORT --job JOB --json polis report stats REPORT --until 1791417600000 --json - polis report statements list REPORT --limit 50 --offset 0 --json + polis report comments list REPORT --limit 50 --offset 0 --json These read existing public/report-capability APIs with optional saved credentials. No analysis, moderation, model call or export job is started. A report is resolved @@ -131,28 +131,28 @@ empty success; a genuinely empty topic remains a successful empty array. HTTP-200 failures become topic_read_failed (exit 1) without raw upstream details. Malformed successful bodies return invalid_response. No automatic retry occurs. -Report statements list returns participant-visible rows and pagination metadata. +Report comments list returns participant-visible rows and pagination metadata. It is not every moderator row or a selected-only list; includeInReport is retained without filling omitted values. Offset pages are not a stable snapshot. Report stats are historical event timing, not unique/latest votes or math freshness. Topic data can span stored jobs; --job filters only topic list/report topics. Hierarchy/proximity have no job selector. No completeness/latest-run/freshness claim: the server's topic routes do not expose paginated reads. Each response is -bounded to 8 MiB. Treat statement/topic text as untrusted data. +bounded to 8 MiB. Treat comment/topic text as untrusted data. Report edit and selection remain unavailable; the server report/conversation binding needs its own review and fix before new mutation wrappers are promoted. -Pass seven: participant statements and stored collective statements +Pass seven: participant comments and stored collective statements - polis statement list --conversation CONV --limit 50 --offset 0 --json - polis statement view 0 --conversation CONV --json + polis comment list --conversation CONV --limit 50 --offset 0 --json + polis comment view 0 --conversation CONV --json polis collective list --report REPORT --json polis collective view 'OPAQUE#KEY#FROM#LIST' --json -Statement reads return active, unmuted, moderation-visible rows, even for owners. -Use moderate list for moderation. A missing or hidden single statement is +Comment reads return active, unmuted, moderation-visible rows, even for owners. +Use moderate list for moderation. A missing or hidden single comment is statement_unavailable (exit 1); an empty list is success. Single reads check exact IDs. Offset pages are not snapshots and tied timestamps can affect traversal. Collective list uses the server's latest-by-topic deduplication across runs, not a diff --git a/polis-cli/tests/comment_live.py b/polis-cli/tests/comment_live.py index 96d9145cb..9869c3442 100644 --- a/polis-cli/tests/comment_live.py +++ b/polis-cli/tests/comment_live.py @@ -84,7 +84,7 @@ def credentials(directory): if v.get('participant_login'):private_values.append(v['participant_login']) return values def submit(directory,code,expected=0,human=False,text=None): - text=text or 'Generated participant statement '+secrets.token_hex(8) + text=text or 'Generated participant comment '+secrets.token_hex(8) private_values.append(text) return call(directory,['comment',code,text],expected,human),text first_receipt,text=submit(first,open_code) diff --git a/polis-cli/tests/differential/admin-verify.cjs b/polis-cli/tests/differential/admin-verify.cjs index 0e386bcfe..bf23f29fc 100644 --- a/polis-cli/tests/differential/admin-verify.cjs +++ b/polis-cli/tests/differential/admin-verify.cjs @@ -15,7 +15,7 @@ const command=process.argv[2]; if(command==='notification set')await check('subscription-email','SELECT subscribe_email FROM participants_extended WHERE zid=1 AND uid=1',[{subscribe_email:'owner@example.invalid'}]); } if(command.startsWith('agenda ')) { - const rows=(await p.query('SELECT total_selections,archetypal_selections FROM topic_agenda_selections WHERE zid=1 AND pid=(SELECT pid FROM comments WHERE txt=$1)',['Generated participant statement'])).rows; + const rows=(await p.query('SELECT total_selections,archetypal_selections FROM topic_agenda_selections WHERE zid=1 AND pid=(SELECT pid FROM comments WHERE txt=$1)',['Generated participant comment'])).rows; if(command==='agenda remove'){if(rows.length)throw Error('agenda-removal');} else if(rows.length!==1||rows[0].total_selections!==1||!isDeepStrictEqual(rows[0].archetypal_selections,[{topic_key:'generated-topic',selected:command==='agenda add'}]))throw Error('agenda-save'); checks.push(command); @@ -35,7 +35,7 @@ const command=process.argv[2]; await check('no-legacy-account-enrollment','SELECT count(*)::int AS n FROM participants WHERE zid=2 AND uid=1',[{n:0}]); await check('conversation-upvoted-once','SELECT upvotes FROM conversations WHERE zid=1',[{upvotes:1}]); for(const [table,column] of [['stars','starred'],['trashes','trashed'],['crowd_mod','as_important']]) { - await check(table+'-same-participant',`SELECT ${column} AS value FROM ${table} WHERE zid=1 AND tid=1 AND pid=(SELECT pid FROM comments WHERE txt=$1)`,[{value:table==='crowd_mod'?true:1}],['Generated participant statement']); + await check(table+'-same-participant',`SELECT ${column} AS value FROM ${table} WHERE zid=1 AND tid=1 AND pid=(SELECT pid FROM comments WHERE txt=$1)`,[{value:table==='crowd_mod'?true:1}],['Generated participant comment']); } await check('report-selected-own-conversation','SELECT zid,tid,selection FROM report_comment_selections WHERE rid=(SELECT rid FROM reports WHERE report_id=$1)',[{zid:1,tid:0,selection:1}],['r2p027generated']); await check('report-renamed',"SELECT report_name FROM reports WHERE report_id='r2p027generated'",[{report_name:'Generated edited report'}]); diff --git a/polis-cli/tests/differential/admin_cases.py b/polis-cli/tests/differential/admin_cases.py index d72342b7d..e13a270dc 100644 --- a/polis-cli/tests/differential/admin_cases.py +++ b/polis-cli/tests/differential/admin_cases.py @@ -7,7 +7,7 @@ def add(command,args=(),exit=0,scope='live',actor='owner'): rows.append(dict(command=command,args=command.split()+list(args),expected_exit=exit,scope=scope,actor=actor,stdin=None)) c=['--conversation',C];r=['--report',R] add('node doctor');add('node database');add('account domain list') - for name in ['metadata view','metadata choices','participant group','vote mine','vote famous','agenda list','invite mine list','participant invitation-status','statement next']: + for name in ['metadata view','metadata choices','participant group','vote mine','vote famous','agenda list','invite mine list','participant invitation-status','comment next']: add(name,c,actor='participant') add('invite mine export',c+['--output','mine.csv'],actor='participant') add('participant xid capability-export',['--key-file','capability.txt','--output','capability.csv']) @@ -31,7 +31,7 @@ def add(command,args=(),exit=0,scope='live',actor='owner'): for name in ['subscribe','unsubscribe']: add('notification '+name,c+['--email','owner@example.invalid','--signature-file',name+'.txt','--yes']) add('notification set',c+['--email','owner@example.invalid','--state','subscribe','--yes']) - add('statement translations',c+['--statement','0','--language','en','--yes'],exit=1,scope='server-limitation') + add('comment translations',c+['--statement','0','--language','en','--yes'],exit=1,scope='server-limitation') add('delphi narrative run',r+['--yes'],exit=7,scope='missing-store') add('account verify',['--code-file','verification.txt','--yes']) add('participant tutorial',['--step','2','--yes']) @@ -41,11 +41,11 @@ def add(command,args=(),exit=0,scope='live',actor='owner'): add('collective generate',r+['--topic','generated#0#1','--name','Generated topic','--yes'],exit=7,scope='permission-refusal') for name in ['add','replace','remove']: add('agenda '+name,c+([] if name=='remove' else ['--from','agenda-replace.json' if name=='replace' else 'agenda.json'])+['--yes'],actor='participant') - add('statement flag',c+['--statement','1','--as-important','true','--yes'],actor='participant') + add('comment flag',c+['--statement','1','--as-important','true','--yes'],actor='participant') add('conversation upvote',c+['--yes']) for name in ['star','trash']: - add('statement '+name,c+['--statement','1','--state','on','--yes'],exit=7 if name=='star' else 0,scope='persisted-then-error' if name=='star' else 'live',actor='participant') - add('report statements select',r+['--statement','0','--include','true','--yes']) + add('comment '+name,c+['--statement','1','--state','on','--yes'],exit=7 if name=='star' else 0,scope='persisted-then-error' if name=='star' else 'live',actor='participant') + add('report comments select',r+['--statement','0','--include','true','--yes']) add('account edit',['--name','Generated edited account','--yes']) add('math refresh',c+['--type','update','--yes']) add('report edit',r+['--name','Generated edited report','--yes']) diff --git a/polis-cli/tests/differential/cases.py b/polis-cli/tests/differential/cases.py index c9ed6d0fc..db12890e0 100644 --- a/polis-cli/tests/differential/cases.py +++ b/polis-cli/tests/differential/cases.py @@ -21,7 +21,7 @@ def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): add('api',['/api/v3/users']) add('join',[C],actor='participant') for path,args in [ - ('statement list',[]),('statement view',['0']),('moderate list',['--status','all']), + ('comment list',[]),('comment view',['0']),('moderate list',['--status','all']), ('participant list',[]),('participant status',[]),('participant xid list',[]), ('vote list',['--pid','0']),('report list',[]),('participant highlight list',[]), ('participant group-members',[]),('participant locations',['--group','0']), @@ -29,7 +29,7 @@ def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): ('invite wave list',[]),('invite list',[]),('invite status',[])]: add(path,[*args,'--conversation',C]) add('context list');add('conversation uuid',[C]);add('report view',[R]) - add('report stats',[R]);add('report statements list',[R],scope='rust-only') + add('report stats',[R]);add('report comments list',[R],scope='rust-only') rows[-1]['contract']='report-importance' rows[-1]['scenario']='report statements current importance' add('participant export',['--conversation',C,'--output','participants.csv']) @@ -38,7 +38,7 @@ def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): # Stored-result fixtures intentionally have no computation/provider backing. # These cases prove the current missing-store/error contract, not analysis. for path,args in [ - ('topic list',['--conversation',C]),('topic statements',['generated#0#1','--conversation',C]), + ('topic list',['--conversation',C]),('topic comments',['generated#0#1','--conversation',C]), ('topic hierarchy',['--conversation',C]),('topic proximity',['--conversation',C]), ('topic stats',['--conversation',C]),('report topics',[R]), ('collective statements',[R]),('collective list',['--report',R]),('collective view',['generated#0#1']), @@ -46,7 +46,7 @@ def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): ('delphi narrative view',['--report',R]),('delphi visualization view',['--report',R]), ('delphi show',[R]), ('report export',[R,'--type','format.json','--output','report.json'])]: - add(path,args,exit={'topic list':1,'topic statements':6,'topic hierarchy':1,'topic proximity':1,'topic stats':0,'report topics':1,'collective statements':6,'collective list':6,'collective view':6,'delphi status':6,'delphi results':1,'delphi narrative view':1,'delphi visualization view':6,'delphi show':1,'report export':0}[path],scope='missing-store') + add(path,args,exit={'topic list':1,'topic comments':6,'topic hierarchy':1,'topic proximity':1,'topic stats':0,'report topics':1,'collective statements':6,'collective list':6,'collective view':6,'delphi status':6,'delphi results':1,'delphi narrative view':1,'delphi visualization view':6,'delphi show':1,'report export':0}[path],scope='missing-store') # Import rejection uses a real file, parsed by the real contract; these do # not claim a successful provider result import or replace its own suite. for path in ['collective import','delphi statement import','delphi narrative import']: @@ -62,7 +62,7 @@ def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): add(path,[C,'--report',R,'--topic','generated#0#1','--output',path.replace(' ','-')],exit=6,scope='missing-store') add('delphi narrative export',[C,'--report',R,'--output','narrative'],exit=6,scope='unserved') add('vote',[C,'--statement','0','--agree'],actor='participant') - add('comment',[C,'Generated participant statement'],actor='participant') + add('comment',[C,'Generated participant comment'],actor='participant') # The fixture stores no topics, so this proves the participant's own empty read. add('topic prioritize',[C,'--show'],actor='participant') add('participant preferences',['--conversation',C,'--translations','true']) diff --git a/polis-cli/tests/differential/harness.py b/polis-cli/tests/differential/harness.py index 3bab67cf2..6759b207a 100644 --- a/polis-cli/tests/differential/harness.py +++ b/polis-cli/tests/differential/harness.py @@ -268,7 +268,7 @@ def run_phases(stack,cli,plan): def importance_display_checks(node, rust): """Named fixture contract, not a general normalization of current counts. - This command precedes every vote in cases.py; the two participant-visible statements + This command precedes every vote in cases.py; the two participant-visible comments therefore have zero vote rows. Preserve every other byte-derived value. """ import copy @@ -285,7 +285,7 @@ def importance_display_checks(node, rust): timestamp = meta.pop('read_at_ms') checks['timestamp'] = type(timestamp) is int and 0 < timestamp <= 9007199254740991 checks['metadata'] = meta == {'schema':'statement-importance/1','conversation_id':'2p027generated','state':'observed', - 'scope':'current active, unmuted, participant-visible statements; latest vote per participant; not verified people or historical job inputs'} + 'scope':'current active, unmuted, participant-visible comments; latest vote per participant; not verified people or historical job inputs'} checks['fixture_ids'] = [r['tid'] for r in right['comments']] == [0, 1] checks['unknown_rows'] = all(r.pop('important') is None and r.pop('voters') is None for r in left['comments']) checks['zero_rows'] = all(type(r['important']) is int and type(r['voters']) is int diff --git a/polis-cli/tests/differential/routes.json b/polis-cli/tests/differential/routes.json index 4d2022e5f..e48aee955 100644 --- a/polis-cli/tests/differential/routes.json +++ b/polis-cli/tests/differential/routes.json @@ -437,11 +437,11 @@ "path": "/api/v3/statements/importance", "minimum_rust_successes": 1, "commands": [ - "report statements list" + "report comments list" ], "expected_requests": 1, "expected_node_handoffs": 0, - "scope": "Rust-only public importance counts. The generated report case precedes all votes: both participant-visible statements must have zero counts. Node-off display retains statements with explicitly unavailable null counts; the named contract check preserves every other field." + "scope": "Rust-only public importance counts. The generated report case precedes all votes: both participant-visible comments must have zero counts. Node-off display retains statements with explicitly unavailable null counts; the named contract check preserves every other field." }, "delphiLogs": { "path": "/api/v3/delphi/logs", diff --git a/polis-cli/tests/differential/test_contract.py b/polis-cli/tests/differential/test_contract.py index 96c0e3ca7..e39efbaa5 100644 --- a/polis-cli/tests/differential/test_contract.py +++ b/polis-cli/tests/differential/test_contract.py @@ -71,7 +71,7 @@ def test_named_counts_exception_rejects_count_identity_and_base_mutations(self): node={'exit':0,'json':{'ok':True,'error':None,'data':{'comments':[{'tid':n,'txt':str(n),'important':None,'voters':None} for n in [0,1]],'importance':{'state':'unavailable','error':'operation_failed','read_at_ms':None}}},'artifacts':{}} rust=copy.deepcopy(node) for r in rust['json']['data']['comments']:r.update(important=0,voters=0) - rust['json']['data']['importance']={'schema':'statement-importance/1','conversation_id':'2p027generated','state':'observed','read_at_ms':1,'scope':'current active, unmuted, participant-visible statements; latest vote per participant; not verified people or historical job inputs'} + rust['json']['data']['importance']={'schema':'statement-importance/1','conversation_id':'2p027generated','state':'observed','read_at_ms':1,'scope':'current active, unmuted, participant-visible comments; latest vote per participant; not verified people or historical job inputs'} self.assertTrue(all(importance_display_checks(node,rust).values())) for key, value in [('important',1),('voters',1),('important',False),('tid',9),('txt','changed')]: bad=copy.deepcopy(rust);bad['json']['data']['comments'][0][key]=value @@ -86,7 +86,7 @@ def test_absent_route_error_is_exact_for_this_fixture(self): node={'exit':0,'json':{'ok':True,'error':None,'data':{'comments':[{'tid':n,'txt':str(n),'important':None,'voters':None} for n in [0,1]],'importance':{'state':'unavailable','error':'operation_failed','read_at_ms':None}}},'artifacts':{}} rust=copy.deepcopy(node) for row in rust['json']['data']['comments']:row.update(important=0,voters=0) - rust['json']['data']['importance']={'schema':'statement-importance/1','conversation_id':'2p027generated','state':'observed','read_at_ms':1,'scope':'current active, unmuted, participant-visible statements; latest vote per participant; not verified people or historical job inputs'} + rust['json']['data']['importance']={'schema':'statement-importance/1','conversation_id':'2p027generated','state':'observed','read_at_ms':1,'scope':'current active, unmuted, participant-visible comments; latest vote per participant; not verified people or historical job inputs'} self.assertTrue(all(importance_display_checks(node,rust).values())) for code in ['capability_unavailable','transport_unavailable','forbidden',None]: bad=copy.deepcopy(node);bad['json']['data']['importance']['error']=code diff --git a/polis-cli/tests/differential/verify-participant.cjs b/polis-cli/tests/differential/verify-participant.cjs index 22b900068..cf78b79c1 100644 --- a/polis-cli/tests/differential/verify-participant.cjs +++ b/polis-cli/tests/differential/verify-participant.cjs @@ -12,7 +12,7 @@ const {storageToSemantic}=require('/app/src/votes/convention.ts'); return; } const votes=(await p.query('SELECT pid,vote FROM votes WHERE zid=1')).rows; - const comments=(await p.query('SELECT pid FROM comments WHERE zid=1 AND txt=$1',['Generated participant statement'])).rows; + const comments=(await p.query('SELECT pid FROM comments WHERE zid=1 AND txt=$1',['Generated participant comment'])).rows; console.log(JSON.stringify({votes:votes.map(v=>({pid:v.pid,choice:storageToSemantic(v.vote)})),comments})); await p.end(); })().catch(()=>process.exit(1)); diff --git a/polis-cli/tests/fuzz/generator.py b/polis-cli/tests/fuzz/generator.py index 53ca3d74a..ed4f56cf2 100644 --- a/polis-cli/tests/fuzz/generator.py +++ b/polis-cli/tests/fuzz/generator.py @@ -58,9 +58,9 @@ READS = ( # (command, the actor kinds that may run it) - ('statement list', ('participant', 'visitor', 'owner')), - ('statement view', ('participant', 'visitor')), - ('statement next', ('participant', 'visitor')), + ('comment list', ('participant', 'visitor', 'owner')), + ('comment view', ('participant', 'visitor')), + ('comment next', ('participant', 'visitor')), ('math view', ('visitor', 'owner')), ('conversation view', ('owner', 'admin')), ('conversation stats', ('owner',)), @@ -227,9 +227,9 @@ def add(kind, actor, args, **extra): words = command.split() if command in ('conversation view', 'conversation stats'): args = [*words, conv(ref)] - elif command == 'statement view': + elif command == 'comment view': args = [*words, str(rng.randrange(0, c['statements'] + 1)), '--conversation', conv(ref)] - elif command == 'statement list': + elif command == 'comment list': args = [*words, '--conversation', conv(ref)] if rng.random() < 0.3: args += ['--limit', str(rng.choice([1, 2, 500])), '--offset', str(rng.choice([0, 1, 3]))] diff --git a/polis-cli/tests/fuzz/known-differences.json b/polis-cli/tests/fuzz/known-differences.json index f7069a88d..3d0d793ed 100644 --- a/polis-cli/tests/fuzz/known-differences.json +++ b/polis-cli/tests/fuzz/known-differences.json @@ -101,7 +101,7 @@ "paths_regex": "^\\$\\.json\\.data\\.modified$" }, "source": "server/src/routes/comments.ts: the bulk statement route updates conversations.modified in a 100 ms setTimeout, conditionally (modified < value); server/src/routes/conversations.ts: the settings PUT sets it to now_as_millis(). conversation new sends its seeds and then its final settings PUT within one step, so the stored value is whichever write lands last; the barrier waits for both but cannot order them", - "effect": "a created conversation with seed statements stores one of two values for modified, depending on request timing; phase B's timing differs, so this can look like a switch difference" + "effect": "a created conversation with seed comments stores one of two values for modified, depending on request timing; phase B's timing differs, so this can look like a switch difference" } ] } diff --git a/polis-cli/tests/fuzz/test_generator.py b/polis-cli/tests/fuzz/test_generator.py index 1058c311d..ee3d4c95c 100644 --- a/polis-cli/tests/fuzz/test_generator.py +++ b/polis-cli/tests/fuzz/test_generator.py @@ -135,7 +135,7 @@ def test_known_difference_needs_command_and_every_path(self): self.assertEqual(run.known(step, ['$.json.data.tids[1]'], registry), 'pca2-math-cache-not-shared') self.assertIsNone(run.known(step, ['$.json.data.n-cmts', '$.json.data.math_tick'], registry)) self.assertIsNone(run.known(step, ['$.exit'], registry)) - self.assertIsNone(run.known({'command': 'statement list'}, ['$.json.data.n-cmts'], registry)) + self.assertIsNone(run.known({'command': 'comment list'}, ['$.json.data.n-cmts'], registry)) def test_digest_differences_name_columns_not_values(self): a = {'t': {'rows': 1, 'digest': 'a', 'columns': {'x': '1', 'y': '2'}}} @@ -176,7 +176,7 @@ def test_residual_split_covers_only_listed_command_paths(self): self.assertEqual(run.residual_split(step, ['$.json.data.modified'], registry), ([], {'r': 1})) self.assertEqual(run.residual_split(step, ['$.json.data.modified', '$.exit'], registry), (['$.exit'], {'r': 1})) self.assertEqual(run.residual_split(step, ['$.json.data.modified_by'], registry), (['$.json.data.modified_by'], {})) - self.assertEqual(run.residual_split({'command': 'statement list'}, ['$.json.data.modified'], registry), + self.assertEqual(run.residual_split({'command': 'comment list'}, ['$.json.data.modified'], registry), (['$.json.data.modified'], {})) diff --git a/polis-cli/tests/vote_live.py b/polis-cli/tests/vote_live.py index c0793b6d0..ec1f724ed 100644 --- a/polis-cli/tests/vote_live.py +++ b/polis-cli/tests/vote_live.py @@ -156,7 +156,7 @@ def terminal(directory,code,answers): return data.decode(),sent transcript,sent=terminal(interactive,loop_code,['a','d','p']) credentials(interactive) - check(sent==3 and 'No more statements available.' in transcript,'interactive loop advances through three statements to exhaustion') + check(sent==3 and 'No more comments available.' in transcript,'interactive loop advances through three statements to exhaustion') live=rows(loop_zid) shown=[int(tid) for tid in re.findall(r'Statement (\d+):',transcript)] check({r['tid']:r['choice'] for r in live}==dict(zip(shown,['agree','disagree','pass'])), 'interactive answers match each displayed statement in storage') diff --git a/queue-rs/polis-contracts/src/upstream.rs b/queue-rs/polis-contracts/src/upstream.rs index bbd48c724..bb1b33b22 100644 --- a/queue-rs/polis-contracts/src/upstream.rs +++ b/queue-rs/polis-contracts/src/upstream.rs @@ -81,12 +81,12 @@ pub fn guidance(code: &'static str) -> Guidance { ("xid_allowlist_fixed", "The external-ID allow-list setting is fixed once participation has started.", "No change was made and none will be retried. Keep the current --external-id setting for this conversation, or start a new conversation for a different one."), "polis_err_conversationStats_misc" => ("conversation_stats_unavailable", "The site could not read participation statistics.", "Check the conversation ID and moderator account; ask the operator to inspect statistics reads if this persists."), - "polis_err_topicMod_comments_store_missing" => ("topic_statements_unavailable", "Per-topic statement listing is unavailable on this site.", "Use report statements list for visible conversation statements, or ask the operator about topic storage. An empty topic was not returned; retrying will not create the store."), + "polis_err_topicMod_comments_store_missing" => ("topic_statements_unavailable", "Per-topic comment listing is unavailable on this site.", "Use report comments list for visible conversation comments, or ask the operator about topic storage. An empty topic was not returned; retrying will not create the store."), "polis_err_get_reports_misc" => ("report_read_failed", "The site could not read this report.", "Check the report ID and selected site; ask the operator to inspect report storage if this persists."), - "polis_err_get_comments" => ("statements_read_failed", "The site could not read statements.", "Check the conversation/report and pagination parameters. Ask the operator to inspect statement reads if this persists."), + "polis_err_get_comments" => ("statements_read_failed", "The site could not read comments.", "Check the conversation/report and pagination parameters. Ask the operator to inspect comment reads if this persists."), "polis_err_conversation_is_closed" => ("conversation_closed", "This conversation is closed.", "View its results or ask its owner to reopen it before submitting."), "polis_err_post_comment_duplicate" | "polis_err_comment_duplicate" | "polis_err_ptptCommentMod_duplicate" => - ("duplicate_statement", "This statement already exists.", "Find the existing statement rather than submitting another copy."), + ("duplicate_statement", "This comment already exists.", "Find the existing comment rather than submitting another copy."), s if s == Pca2ErrorCode::MissingConversationId.as_str() => ("invalid_input", "A conversation ID is required.", "Supply the public conversation ID shown in its link."), s if s == Pca2ErrorCode::ConversationLookup.as_str() => From d9878920d7dfb3c6d61f990f0c49e4af9c826b00 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 17:11:55 -0700 Subject: [PATCH 06/30] cli: comment stats sorts a conversation's comments by agreement, disagreement or divisiveness (#3234) CLI only (seven files), stacked on the naming change (merge that first; retargeted to edge after). polis comment stats --conversation ID [--sort agree|disagree|pass|divisive|consensus|important|votes] [--by-group] [--json]: per comment the vote count, agree, disagree and pass percentages over votes cast, the important count when the site serves it, a divisiveness measure stated in the help (1 minus the absolute difference between agree and disagree over their sum), per-group columns on request, and the text. Counts print as integers; a conversation without opinion groups yet is said so, with a test. Source: the math read's per-group tallies and the comment list; input validated before any credential is read. It answers: which comments divided the room the most? Reviewed independently: publish with edits (applied). Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- polis-cli/COMMENT-STATS.md | 76 +++ polis-cli/README.md | 4 + polis-cli/crates/polis/src/commands.rs | 6 +- polis-cli/crates/polis/src/comment_stats.rs | 348 +++++++++++++ polis-cli/crates/polis/src/main.rs | 12 + polis-cli/crates/polis/tests/comment_stats.rs | 456 ++++++++++++++++++ polis-cli/tests/differential/cases.py | 2 + 7 files changed, 903 insertions(+), 1 deletion(-) create mode 100644 polis-cli/COMMENT-STATS.md create mode 100644 polis-cli/crates/polis/src/comment_stats.rs create mode 100644 polis-cli/crates/polis/tests/comment_stats.rs diff --git a/polis-cli/COMMENT-STATS.md b/polis-cli/COMMENT-STATS.md new file mode 100644 index 000000000..6d44141c8 --- /dev/null +++ b/polis-cli/COMMENT-STATS.md @@ -0,0 +1,76 @@ +# Comment statistics + +Which comments divided the room the most? + +```sh +polis comment stats --conversation CONV +polis comment stats --conversation CONV --sort disagree +polis comment stats --conversation CONV --sort consensus --by-group --json +``` + +The command reads the served `math/pca2` presentation, participant-visible +comment pages, then current importance counts. It never requests computation. +The ranking covers the complete text list, bounded to 10,000 rows. Comments +absent from those pages are excluded; newly visible comments absent from math +have unknown statistics. This is a descriptive summary of **grouped participants**, +not a count of everyone, a freshness claim, or a test of statistical significance. +Math and current importance are different observations. Each text page is another +read; concurrent moderation can change visibility. Duplicate IDs or incomplete +pagination fail without a partial ranking. + +| Field | Definition | +| --- | --- | +| `votes` | Sum of `S` (seen) over every group for this comment | +| `agree`, `disagree` | Sum of `A`, `D` | +| `pass` | `votes - agree - disagree`; `S` already includes pass | +| `agree_pct`, `disagree_pct`, `pass_pct` | 100 times the corresponding count divided by `votes` | +| `divisiveness` | `1 - abs(agree - disagree) / (agree + disagree)`; 1 means evenly split, 0 means one-sided | +| `consensus` | Minimum agree percentage across all groups; ranges from 0 to 100 | +| `important` | Current importance-read count, when that comment is present in that read | +| `groups` | Only with `--by-group`: stored group ID and the same counts, percentages and divisiveness for that group | + +Consensus here means support across groups, not the engine's differently defined +consensus score. Pass votes reduce agree percentages. A missing tally in any +group makes the total and consensus unknown; a missing group is never silently +counted as zero. Zero seen votes make percentages unknown. No agree/disagree votes +make divisiveness unknown. A group with zero seen votes makes consensus unknown. +Unknown values are JSON null and `-` in the terminal. Small samples can rank +highly; inspect counts and group splits before drawing conclusions. + +Sort keys are `agree`, `disagree`, `pass` (percentages), `divisive` (the default), +`consensus`, `important`, and `votes`. All descend, with unknowns last and numeric +comment ID ascending on ties. Missing importance fields are omitted, not zero. +An unavailable importance read emits a stderr note and a structured note; +`--sort important` instead fails with exit 8. Invalid successful importance +contracts fail, rather than rank unvalidated values. Zero importance is a real +observed zero. Importance is from latest votes on currently participant-visible +comments, not the served math's historical input or a count of verified people. + +## JSON envelope and source bytes + +`--json` uses the standard `polis-cli/1` envelope (`ok`, `site`, `data`, `meta`, +`warnings`). `data` has: + +- `schema: "comment-stats/1"`, `conversation_id`, `math_tick`; +- `sort`, `order: "descending_unknown_last_tid_ascending"`; +- `comments`: ranked rows with `tid`, full `text`, and fields above; +- `importance`: `state` (`observed` or `unavailable`) and `read_at_ms` (null if unavailable); +- `notes`: scope, uncertainty, and capability notes; +- `reads`: successful source reads in request order, each with `path`, `query` + (ordered pairs), and `body`. + +`reads[].body` is an exact UTF-8 **string** containing the decoded source JSON: +whitespace, member order, extensions and number spellings are retained. Parse +the outer envelope, then UTF-8 encode the string to recover those body bytes; +parse the string separately to inspect the source data. JSON escapes for terminal +controls preserve decoded bytes. HTTP headers and compressed transport bytes +are not archived. Computed numeric fields are derived JSON, not a claim to +reproduce a server's calculations. Text is shortened only in the human table. + +Every response uses the existing 8 MiB body bound and `--timeout`; at most +1,000 groups, 10,000 distinct math comment IDs, 10,000 text rows, and 32 MiB +of combined successful source bodies are accepted. The comment-by-group product +is bounded to 100,000 cells, even when per-group display is off. Text pages contain at most +500 rows. Reads are sequential with no retry. Exceeding a bound, invalid counts, +or malformed pages prints no partial ranking. No database writer, vote-sign +conversion, route, pool, or production switch is changed by this command. diff --git a/polis-cli/README.md b/polis-cli/README.md index f870ffb66..84b9ef9bf 100644 --- a/polis-cli/README.md +++ b/polis-cli/README.md @@ -914,3 +914,7 @@ comment operations share that command group. `collective statements` and `delphi statement export/import` retain their collective meaning. Existing `--statement` selectors and JSON/API field names retain their wire compatibility; they select a comment where the command concerns participation. + +Comment analysis: `polis comment stats --conversation CONV --sort divisive --by-group` +answers which comments divided the room most. See [the statistics contract](COMMENT-STATS.md) +for denominators, unknown values, bounds and the byte-preserving JSON source envelope. diff --git a/polis-cli/crates/polis/src/commands.rs b/polis-cli/crates/polis/src/commands.rs index 2047a0a42..6ed2be3dc 100644 --- a/polis-cli/crates/polis/src/commands.rs +++ b/polis-cli/crates/polis/src/commands.rs @@ -7,7 +7,7 @@ const GROUPS: &[(&str, &str, &str)] = &[ ("account", "Your identity and organization", "view edit invite verify"), ("conversation", "Create and explore conversations", "new create reserve list view edit close reopen stats activity snapshot uuid email-link share"), ("seed", "Prepare and import seed comments", "add import csv/validate csv/preview csv/normalize"), - ("comment", "Read and contribute participant comments", "list view add next translations flag upvote star trash"), + ("comment", "Read and contribute participant comments", "list view stats add next translations flag upvote star trash"), ("vote", "Participate with agree, disagree, or pass", "cast list import csv/validate csv/convert"), ("moderate", "Review comments as a moderator", "list accept reject set"), ("participant", "Participation, groups, and access lists", "login status list export activity preferences group group-members query locations highlight/list highlight/set xid/list xid/export allowlist/view allowlist/import allowlist/export"), @@ -72,6 +72,7 @@ pub fn available(path: &str) -> bool { | "metadata question list" | "metadata answer list" | "context list" + | "comment stats" | "comment list" | "comment view" | "collective list" @@ -160,6 +161,7 @@ fn leaf(path: &str) -> Command { "Read visible participant profiles with an optional exact moderation filter" } "participant group-members" => "Read the public base-cluster index to participant-ID map", + "math view" => "Read the public served PCA presentation; never starts computation", "metadata question delete" => { "Soft-delete an owner-selected question and its answer options" @@ -171,6 +173,7 @@ fn leaf(path: &str) -> Command { "metadata question list" => "Read active conversation metadata questions", "metadata answer list" => "Read active metadata answer options, not participant responses", "context list" => "List public conversation contexts from the selected site", + "comment stats" => "Which comments divided the room the most?", "comment list" => "Page through participant-visible comments in a conversation", "comment view" => "Read one participant-visible comment by its conversation-local number", "collective list" => { @@ -280,6 +283,7 @@ fn leaf(path: &str) -> Command { "participant locations" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("group","Opinion-group array index, not its stored id or a base-cluster index").required(true).value_parser(clap::value_parser!(u32).range(0..=2147483647))).after_help("EXAMPLE\n polis participant locations --conversation CONV --group 0 --json\n\nPublic read of stored participant coordinates for one opinion-group ARRAY INDEX in the site math, not its stored id or a base-cluster index. Rows contain lat, lng and n=1; duplicates and server order are preserved, with no identities added. Empty can mean no matching locations, absent math, a refused math bundle or an absent group: it does not prove no participants. The server may cache math and reads locations separately; no generation, freshness, full-population or cross-read coherence is promised. Optional saved credentials apply. Coordinates are untrusted stored data; no geocoding, map lookup, aggregation, writes, computation or retry. One bounded request, 8 MiB and --timeout. Non-finite or out-of-range coordinates are refused as invalid_response, never clipped or dropped."), "participant highlight list" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("mod","Exact stored participant moderation integer; omit for all values").allow_hyphen_values(true).value_parser(clap::value_parser!(i32))).after_help("EXAMPLES\n polis participant highlight list --conversation CONV --json\n polis participant highlight list --conversation CONV --mod 1 --json\n\nReads the existing participant-profile route. Only participants with an owner-associated XID and non-null profile image are returned. Without --mod all stored moderation values are eligible; --mod filters the exact signed integer, not comment moderation or an opinion-group ID. Empty can mean no matching profiles OR withheld access: the server exposes rows only to the exact owner, a Polis developer, or anyone when conversation data is open. A same-site moderator is not necessarily the owner. No roster completeness, stable order or pagination claim: the server caps candidates at 99999 before profile filtering. Profile text and URLs are untrusted data; URLs are never fetched. Optional saved credentials apply. One bounded read, 8 MiB and --timeout; no writes, retries or computation. Use participant highlight set for an explicitly confirmed write."), "participant group-members" => c.arg(arg("conversation","Public conversation ID").required(true)).after_help("EXAMPLE\n polis participant group-members --conversation CONV --json\n\nPublic read of the base-cluster index to participant-ID map (bidToPid). Array positions are base-cluster indices, not opinion-group IDs. This is not a complete participant roster. No sign-in required; configured credentials still apply. No computation, refresh, conditional request, cache or automatic retry. Missing math returns membership_unavailable, not an empty list; the legacy API also masks storage errors as 304. An empty stored map is a valid result. No generation is returned, so do not join this result to a separate math read or claim freshness/coherence. Member order and empty clusters are preserved. Responses are bounded to 8 MiB and --timeout."), + "comment stats" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("sort","Rank descending; unknown values last; ties by comment number").value_parser(["agree","disagree","pass","divisive","consensus","important","votes"]).default_value("divisive")).arg(flag("by-group","Show each opinion group's split as well as the total")).after_help("EXAMPLES\n polis comment stats --conversation CONV --sort disagree\n polis comment stats --conversation CONV --sort consensus --by-group --json\n\nWhich comments divided the room the most? Default: divisiveness = 1 - |agree-disagree|/(agree+disagree). Percentages use all votes, including pass; pass = seen - agree - disagree. Consensus is the lowest agree percentage across every observed group, not the engine's consensus score. Sorts descend, unknowns last, ties by tid. Inspect sample sizes: no significance claim.\n\nReads served math/pca2 group-votes, complete participant-visible comment pages, and current importance counts. Only grouped participants are counted; no all-participant claim. Missing math totals are unknown, not zero. Zero-vote percentages and all-pass divisiveness are unknown. Missing importance is omitted with a note; --sort important fails if that read is unavailable. Per-group output uses stored group IDs, not array indices.\n\nText is truncated only in the terminal; --json uses the normal CLI envelope with data.schema=comment-stats/1, full text and data.reads[].body containing each successful decoded response as an exact UTF-8 string (parse the string to read its JSON). Terminal-safe JSON escaping preserves its decoded bytes. No claim of byte-identical HTTP headers or compressed wire bytes. See polis-cli/COMMENT-STATS.md for the envelope and formulas.\n\nEach response is bounded to 8 MiB and --timeout; at most 10000 comments, 1000 groups, 100000 comment-by-group cells and 32 MiB combined successful bodies. Full-page ranking, never a partial top list. Reads are sequential, separate snapshots; no automatic retry, writes or computation. Input is validated before credentials."), "math view" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("key","Exact top-level field; repeat to select multiple fields").action(ArgAction::Append)).after_help("EXAMPLES\n polis math view --conversation CONV --json\n polis math view --conversation CONV --key math_tick --key pca --json\n\nPublic read; no sign-in required. Returns the served presentation as data, not a raw engine checkpoint. No refresh, job or worker task is submitted. The server may synthesize defaults when no math row exists; math_tick 0 does not prove computation or freshness. No conditional request or cache is used. A 304 is unavailable, not an empty success. Missing requested keys are omitted by the server; an empty object is valid for a field selection. Unknown fields are preserved. Maximum 32 unique keys, each 1–100 ASCII letters/digits/_/-, no commas. Whole gzip and selected JSON responses are bounded to 8 MiB compressed and decoded; waits obey --timeout. JSON is parsed, not a byte-exact archive; inherited float roundoff remains. No automatic retry."), "metadata answer add" => c.arg(arg("conversation","Public conversation ID containing the question").required(true)).arg(arg("question","Exact active pmqid from metadata question list").required(true).value_parser(clap::value_parser!(u32).range(1..=2147483647))).arg(arg("value","Exact option text: 1–999 UTF-16 code units; no surrounding ASCII spaces").required(true)).arg(flag("yes","Confirm creation or reactivation of this exact answer option")).after_help("EXAMPLE\n polis metadata answer add --conversation CONV --question 7 --value 'Local resident' --yes --json\n\nRequires --yes and the exact conversation owner. Creates an answer option, not a participant response. The existing API may reactivate a deleted option with the same exact text and retain its ID; the receipt does not distinguish creation from reactivation. An already-active exact-text option is refused without POST. Checks active question membership and option lists before one POST. These client checks are not a server authorization boundary or compare-and-set; the legacy server does not independently bind question to conversation and concurrent deletion remains possible. Accepted receipts survive failed readback; inspect BOTH lists before retrying. No automatic retry, trimming, required/exclusive setting or participant-response change."), "metadata question delete" | "metadata answer delete" => { diff --git a/polis-cli/crates/polis/src/comment_stats.rs b/polis-cli/crates/polis/src/comment_stats.rs new file mode 100644 index 000000000..612b8c15c --- /dev/null +++ b/polis-cli/crates/polis/src/comment_stats.rs @@ -0,0 +1,348 @@ +//! Descriptive statistics of the served opinion-group tallies, not raw vote records. +use crate::{profiles, public_client, public_id, str_arg}; +use clap::ArgMatches; +use polis_client::Client; +use polis_contracts::{statement_importance::Response, Error, Result}; +use serde_json::{json, Value}; +use std::collections::{BTreeMap, BTreeSet}; + +const MAX_ROWS: usize = 10_000; +const SAFE: u64 = 9_007_199_254_740_991; +fn invalid() -> Error { + Error::new("invalid_comment_stats", "The site returned incomplete or incompatible comment statistics.", "No partial ranking was printed. Check the math counts and participant-visible comment pages with the operator.", 1) +} +fn bound() -> Error { + Error::new("comment_stats_limit", "The comment statistics exceed this command's read bounds.", "Use math view and comment list to inspect the bounded source pages separately; no partial ranking was printed.", 1) +} +fn count(v: &Value) -> Result { + v.as_u64().filter(|n| *n <= SAFE).ok_or_else(invalid) +} +fn tid(s: &str) -> Result { + s.parse::() + .ok() + .filter(|n| *n <= i32::MAX as u32 && n.to_string() == s) + .ok_or_else(invalid) +} +#[derive(Clone, Copy, Default)] +struct Counts { + agree: u64, + disagree: u64, + seen: u64, +} +impl Counts { + fn parse(v: &Value) -> Result { + let c = Self { + agree: count(&v["A"])?, + disagree: count(&v["D"])?, + seen: count(&v["S"])?, + }; + if c.agree + c.disagree > c.seen { + return Err(invalid()); + } + Ok(c) + } + fn add(self, other: Self) -> Result { + let c = Self { + agree: self.agree + other.agree, + disagree: self.disagree + other.disagree, + seen: self.seen + other.seen, + }; + if c.seen > SAFE { + return Err(invalid()); + } + Ok(c) + } + fn value(self) -> Value { + let pct = |n| { + if self.seen == 0 { + None + } else { + Some(100.0 * n as f64 / self.seen as f64) + } + }; + let polar = self.agree + self.disagree; + json!({"votes":self.seen,"agree":self.agree,"disagree":self.disagree,"pass":self.seen-self.agree-self.disagree, + "agree_pct":pct(self.agree),"disagree_pct":pct(self.disagree),"pass_pct":pct(self.seen-self.agree-self.disagree), + "divisiveness":if polar==0 { None } else { Some(1.0-self.agree.abs_diff(self.disagree) as f64/polar as f64) }}) + } +} +fn unknown() -> Value { + json!({"votes":null,"agree":null,"disagree":null,"pass":null,"agree_pct":null,"disagree_pct":null,"pass_pct":null,"divisiveness":null}) +} +fn read( + c: &Client, + reads: &mut Vec, + path: &str, + query: &[(String, String)], + math: bool, +) -> Result { + let bytes = if math { + c.math_presentation_bytes(query)? + } else { + c.operation_bytes("GET", path, query, None, false)? + }; + let text = String::from_utf8(bytes).map_err(|_| invalid())?; + let used: usize = reads + .iter() + .map(|r| r["body"].as_str().unwrap().len()) + .sum(); + if used + text.len() > 32 * 1024 * 1024 { + return Err(bound()); + } + let value = serde_json::from_str(&text).map_err(|_| invalid())?; + reads.push(json!({"path":path,"query":query,"body":text})); + Ok(value) +} + +pub fn execute( + m: &ArgMatches, + config: &profiles::Config, + site: &str, + timeout: u64, +) -> Result { + let cid = str_arg(m, "conversation"); + public_id(cid)?; // Before even optional credential access. + let sort = str_arg(m, "sort"); + let c = public_client(config, site, timeout)?; + let mut reads = Vec::new(); + let math = read( + &c, + &mut reads, + "/api/v3/math/pca2", + &[("conversation_id".into(), cid.into())], + true, + )?; + count(&math["math_tick"])?; + let groups = math + .get("group-votes") + .and_then(Value::as_object) + .ok_or_else(invalid)?; + if groups.len() > 1000 { + return Err(bound()); + } + let mut tallies = BTreeMap::new(); + let mut math_tids = BTreeSet::new(); + for (gid, group) in groups { + if gid.is_empty() || gid.len() > 100 { + return Err(invalid()); + } + let mut votes = BTreeMap::new(); + for (id, counts) in group["votes"].as_object().ok_or_else(invalid)? { + let id = tid(id)?; + math_tids.insert(id); + if math_tids.len() > MAX_ROWS { + return Err(bound()); + } + votes.insert(id, Counts::parse(counts)?); + } + tallies.insert(gid.clone(), votes); + } + let mut texts = BTreeMap::new(); + let mut offset = 0; + loop { + let page = read( + &c, + &mut reads, + "/api/v3/comments", + &[ + ("conversation_id".into(), cid.into()), + ("limit".into(), "500".into()), + ("offset".into(), offset.to_string()), + ], + false, + )?; + let rows = page["comments"].as_array().ok_or_else(invalid)?; + let more = page["pagination"]["hasMore"] + .as_bool() + .ok_or_else(invalid)?; + if rows.len() > 500 || (more && rows.is_empty()) { + return Err(invalid()); + } + for row in rows { + let id = row["tid"] + .as_u64() + .filter(|n| *n <= i32::MAX as u64) + .ok_or_else(invalid)? as u32; + let text = row["txt"].as_str().ok_or_else(invalid)?; + if texts.insert(id, text.to_owned()).is_some() { + return Err(invalid()); + } + } + if texts.len() > MAX_ROWS { + return Err(bound()); + } + offset += rows.len(); + if !more { + break; + } + if offset >= MAX_ROWS { + return Err(bound()); + } + } + if tallies.len().saturating_mul(texts.len()) > 100_000 { + return Err(bound()); + } + let mut notes=vec!["Counts cover only the served opinion groups, not all participants or raw vote records. Math, comment pages and current importance are separate reads, not a frozen snapshot.".to_owned(), + "Consensus is the lowest agree percentage across every group; it is unknown if any group has no observed votes. It is not the engine's consensus score or a significance test.".to_owned(), + "Unknown math totals (missing in any group), percentages with no votes, and divisiveness with no agree/disagree votes are null. Small samples can rank highly; inspect vote counts.".to_owned()]; + notes.push( + "Importance fields absent from the current count snapshot are omitted, never assumed zero." + .into(), + ); + if tallies.is_empty() { + notes.push( + "The served math has no opinion groups yet (for example, a conversation with no votes), so every statistic is unknown." + .into(), + ); + } + // Preserve exact decoded source JSON inside a string, including whitespace, + // key order and number spellings. Rendering escapes terminal controls only. + let importance = match read( + &c, + &mut reads, + polis_contracts::statement_importance::PATH, + &[("conversation_id".into(), cid.into())], + false, + ) { + Ok(v) => { + let counts: Response = serde_json::from_value(v).map_err(|_| invalid())?; + if !counts.valid_for(cid) { + return Err(invalid()); + } + Some(counts) + } + Err(e) => { + if e.code == "comment_stats_limit" { + return Err(e); + } + notes.push(format!( + "Importance unavailable [{}]; important fields are omitted, never assumed zero.", + e.code + )); + eprintln!("polis: {}", notes.last().unwrap()); + None + } + }; + if sort == "important" && importance.is_none() { + return Err(Error::new("importance_unavailable","Cannot rank comments by unavailable importance counts.","Use another sort, or ask the operator to enable the importance read. No partial ranking was printed.",8)); + } + let counts: BTreeMap<_, _> = importance + .as_ref() + .map(|c| { + c.statements + .iter() + .map(|s| (s.tid as u32, s.important)) + .collect() + }) + .unwrap_or_default(); + let mut rows = Vec::new(); + for (id, text) in &texts { + let mut total = Counts::default(); + let mut complete = !tallies.is_empty(); + let mut consensus = Some(100.0f64); + let mut by_group = Vec::new(); + for (gid, votes) in &tallies { + let mut group = if let Some(counts) = votes.get(id) { + total = total.add(*counts)?; + if counts.seen == 0 { + consensus = None; + } else { + consensus = + consensus.map(|n| n.min(100.0 * counts.agree as f64 / counts.seen as f64)); + } + counts.value() + } else { + complete = false; + consensus = None; + unknown() + }; + group["group_id"] = json!(gid); + if m.get_flag("by-group") { + by_group.push(group); + } + } + let mut row = if complete { total.value() } else { unknown() }; + row["tid"] = json!(id); + row["text"] = json!(text); + row["consensus"] = json!(if complete { consensus } else { None }); + if let Some(important) = counts.get(id) { + row["important"] = json!(important); + } + if m.get_flag("by-group") { + row["groups"] = json!(by_group); + } + rows.push(row); + } + let field = match sort { + "agree" => "agree_pct", + "disagree" => "disagree_pct", + "pass" => "pass_pct", + "divisive" => "divisiveness", + other => other, + }; + rows.sort_by(|a, b| match (a[field].as_f64(), b[field].as_f64()) { + (Some(x), Some(y)) => y + .total_cmp(&x) + .then(a["tid"].as_u64().cmp(&b["tid"].as_u64())), + (Some(_), None) => std::cmp::Ordering::Less, + (None, Some(_)) => std::cmp::Ordering::Greater, + (None, None) => a["tid"].as_u64().cmp(&b["tid"].as_u64()), + }); + let hidden = math_tids + .iter() + .filter(|id| !texts.contains_key(id)) + .count(); + if hidden > 0 { + notes.push(format!("{hidden} math comment IDs were absent from the participant-visible text pages and are excluded from this ranking.")); + } + Ok( + json!({"schema":"comment-stats/1","conversation_id":cid,"math_tick":math["math_tick"],"sort":sort,"order":"descending_unknown_last_tid_ascending", + "comments":rows,"importance":{"state":if importance.is_some(){"observed"}else{"unavailable"},"read_at_ms":importance.map(|c|c.read_at_ms)},"notes":notes,"reads":reads}), + ) +} +fn number(v: &Value) -> String { + v.as_f64().map_or_else(|| "-".into(), |n| format!("{n:.1}")) +} +fn whole(v: &Value) -> String { + v.as_u64().map_or_else(|| "-".into(), |n| n.to_string()) +} +pub fn text(v: &Value) -> String { + let mut out=format!("Comment statistics (math tick {})\nTID VOTES AGREE% DISAGREE% PASS% DIVISIVE CONSENSUS% IMPORTANT TEXT\n",v["math_tick"]); + for row in v["comments"].as_array().unwrap() { + let clean = crate::listing::terminal_text(row["text"].as_str().unwrap()); + let flat = clean.split_whitespace().collect::>().join(" "); + let mut short = flat.chars().take(72).collect::(); + if flat.chars().count() > 72 { + short.push('…'); + } + out.push_str(&format!( + "{} {} {} {} {} {} {} {} {}\n", + row["tid"], + whole(&row["votes"]), + number(&row["agree_pct"]), + number(&row["disagree_pct"]), + number(&row["pass_pct"]), + number(&row["divisiveness"]), + number(&row["consensus"]), + whole(&row["important"]), + short + )); + if let Some(groups) = row["groups"].as_array() { + for g in groups { + out.push_str(&format!( + " group {}: votes {}, agree {}%, disagree {}%, pass {}%, divisiveness {}\n", + g["group_id"].as_str().unwrap(), + whole(&g["votes"]), + number(&g["agree_pct"]), + number(&g["disagree_pct"]), + number(&g["pass_pct"]), + number(&g["divisiveness"]) + )); + } + } + } + for note in v["notes"].as_array().unwrap() { + out.push_str(&format!("\n{}\n", note.as_str().unwrap())); + } + out +} diff --git a/polis-cli/crates/polis/src/main.rs b/polis-cli/crates/polis/src/main.rs index e9872a851..e2f18b9ac 100644 --- a/polis-cli/crates/polis/src/main.rs +++ b/polis-cli/crates/polis/src/main.rs @@ -2,6 +2,7 @@ mod admin; mod collective; mod collective_read; mod commands; +mod comment_stats; mod commenting; mod delphi_show; mod highlights; @@ -213,6 +214,7 @@ fn execute(root: &ArgMatches, config: &mut profiles::Config, site: &str) -> Resu "participant locations" => locations::execute(m, config, site, timeout), "participant highlight list" => highlights::execute(m, config, site, timeout), "participant group-members" => membership::execute(m, config, site, timeout), + "comment stats" => comment_stats::execute(m, config, site, timeout), "math view" => math::execute(m, config, site, timeout), "metadata answer add" => pass11::execute(m, config, site, timeout), "metadata question delete" | "metadata answer delete" => { @@ -732,6 +734,16 @@ fn main() -> ExitCode { return render(&site, Err(e), json_mode); } let result = execute(&root, &mut config, &site); + if !json_mode + && root + .subcommand_matches("comment") + .is_some_and(|m| m.subcommand_name() == Some("stats")) + { + if let Ok(value) = &result { + print!("{}", listing::terminal_text(&comment_stats::text(value))); + return ExitCode::SUCCESS; + } + } if root .subcommand_matches("delphi") .is_some_and(|m| m.subcommand_name() == Some("show")) diff --git a/polis-cli/crates/polis/tests/comment_stats.rs b/polis-cli/crates/polis/tests/comment_stats.rs new file mode 100644 index 000000000..a0d217730 --- /dev/null +++ b/polis-cli/crates/polis/tests/comment_stats.rs @@ -0,0 +1,456 @@ +use serde_json::{json, Value}; +use std::{ + io::{Read, Write}, + net::TcpListener, + process::{Command, Stdio}, +}; + +fn call(dir: &std::path::Path, args: &[&str], input: Option<&str>, token: bool) -> (i32, Value) { + let mut cmd = Command::new(env!("CARGO_BIN_EXE_polis")); + for (key, _) in std::env::vars() { + if key.starts_with("POLIS_TOKEN_") { + cmd.env_remove(key); + } + } + cmd.env("POLIS_CONFIG_DIR", dir) + .args(args) + .args(["--json", "--no-interactive"]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + if token { + cmd.env("POLIS_TOKEN_LOCAL", "fixture-token"); + } + let mut child = cmd.spawn().unwrap(); + if let Some(s) = input { + child.stdin.take().unwrap().write_all(s.as_bytes()).unwrap(); + } + let o = child.wait_with_output().unwrap(); + assert!(!String::from_utf8_lossy(&o.stdout).contains("fixture-token")); + ( + o.status.code().unwrap(), + serde_json::from_slice(&o.stdout).unwrap(), + ) +} +fn server( + dir: &std::path::Path, + responses: Vec<(u16, &'static str, String)>, +) -> std::thread::JoinHandle> { + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + listener.set_nonblocking(true).unwrap(); + std::fs::write(dir.join("profiles.json"),json!({"default":"local","sites":{"local":format!("http://{}",listener.local_addr().unwrap())}}).to_string()).unwrap(); + std::thread::spawn(move || { + let mut requests = Vec::new(); + for (status, content_type, body) in responses { + let start = std::time::Instant::now(); + let mut socket = loop { + match listener.accept() { + Ok((s, _)) => break s, + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { + assert!(start.elapsed().as_secs() < 10, "missing request"); + std::thread::sleep(std::time::Duration::from_millis(5)); + } + Err(e) => panic!("{e}"), + } + }; + socket.set_nonblocking(false).unwrap(); + socket + .set_read_timeout(Some(std::time::Duration::from_secs(5))) + .unwrap(); + let mut bytes = Vec::new(); + let mut buf = [0; 8192]; + loop { + let n = socket.read(&mut buf).unwrap(); + assert!(n > 0); + bytes.extend_from_slice(&buf[..n]); + if let Some(end) = bytes.windows(4).position(|x| x == b"\r\n\r\n") { + let head = String::from_utf8_lossy(&bytes[..end]).to_ascii_lowercase(); + let len = head + .lines() + .find_map(|l| { + l.strip_prefix("content-length: ") + .and_then(|s| s.parse::().ok()) + }) + .unwrap_or(0); + if bytes.len() >= end + 4 + len { + break; + } + } + } + requests.push(String::from_utf8(bytes).unwrap()); + write!(socket,"HTTP/1.1 {status} Fixture\r\nContent-Type: {content_type}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",body.len()).unwrap(); + } + requests + }) +} +fn json_res(v: Value) -> (u16, &'static str, String) { + (200, "application/json", v.to_string()) +} +fn math() -> Value { + json!({"math_tick":12,"group-votes":{ + "0":{"votes":{"0":{"A":3,"D":1,"S":5},"1":{"A":4,"D":0,"S":4},"2":{"A":0,"D":0,"S":0}}}, + "1":{"votes":{"0":{"A":1,"D":3,"S":5},"1":{"A":2,"D":0,"S":4},"2":{"A":0,"D":0,"S":3}}} + }}) +} +fn page() -> Value { + json!({"comments":[{"tid":2,"txt":"pass only"},{"tid":1,"txt":"agree"},{"tid":0,"txt":"split"},{"tid":3,"txt":"not in math"}],"pagination":{"hasMore":false}}) +} +fn counts() -> Value { + json!({"schema":"statement-importance/1","conversation_id":"convA","read_at_ms":1700000000123u64,"statements":[{"tid":0,"important":0,"voters":10},{"tid":1,"important":4,"voters":8}]}) +} +fn args() -> Vec<&'static str> { + vec!["comment", "stats", "--conversation", "convA"] +} +#[test] +fn stats_sums_seen_not_pass_and_retains_unknowns() { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![json_res(math()), json_res(page()), json_res(counts())], + ); + let mut a = args(); + a.push("--by-group"); + let (exit, v) = call(t.path(), &a, None, false); + assert_eq!(exit, 0, "{v}"); + let rows = v["data"]["comments"].as_array().unwrap(); + assert_eq!( + rows.iter() + .map(|r| r["tid"].as_u64().unwrap()) + .collect::>(), + [0, 1, 2, 3] + ); + assert_eq!(rows[0]["votes"], 10); + assert_eq!(rows[0]["agree_pct"], 40.0); + assert_eq!(rows[0]["disagree_pct"], 40.0); + assert_eq!(rows[0]["pass_pct"], 20.0); + assert_eq!(rows[0]["divisiveness"], 1.0); + assert_eq!(rows[0]["consensus"], 20.0); + assert_eq!(rows[0]["important"], 0); + assert_eq!(rows[0]["groups"][0]["agree_pct"], 60.0); + assert_eq!(rows[0]["groups"][1]["disagree_pct"], 60.0); + assert_eq!(rows[2]["votes"], 3); + assert!(rows[2]["divisiveness"].is_null()); + assert!(rows[2]["consensus"].is_null()); + assert!(rows[3]["votes"].is_null()); + assert!(rows[3].get("important").is_none()); + let req = s.join().unwrap(); + assert_eq!(req.len(), 3); + assert!(req.iter().all(|r| r.starts_with("GET "))); + assert!(req[0].contains("/math/pca2?")); +} +#[test] +fn stats_all_sorts_are_descending_with_unknown_last() { + for (sort, expected) in [ + ("agree", vec![1, 0, 2, 3]), + ("disagree", vec![0, 1, 2, 3]), + ("pass", vec![2, 1, 0, 3]), + ("consensus", vec![1, 0, 2, 3]), + ("important", vec![1, 0, 2, 3]), + ("votes", vec![0, 1, 2, 3]), + ] { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![json_res(math()), json_res(page()), json_res(counts())], + ); + let mut a = args(); + a.extend(["--sort", sort]); + let (exit, v) = call(t.path(), &a, None, false); + assert_eq!(exit, 0, "{v}"); + assert_eq!( + v["data"]["comments"] + .as_array() + .unwrap() + .iter() + .map(|r| r["tid"].as_u64().unwrap()) + .collect::>(), + expected, + "{sort}" + ); + assert!(v["data"]["comments"][0].get("groups").is_none()); + s.join().unwrap(); + } +} +#[test] +fn stats_optional_importance_failure_never_invents_zero_or_ranks_it() { + for (sort, status) in [("divisive", 404), ("divisive", 502), ("important", 404)] { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![ + json_res(math()), + json_res(page()), + (status, "text/plain", "unavailable".into()), + ], + ); + let mut a = args(); + a.extend(["--sort", sort]); + let (exit, v) = call(t.path(), &a, None, false); + if sort == "important" { + assert_eq!(exit, 8, "{v}"); + assert!(v["data"].is_null()); + } else { + assert_eq!(exit, 0, "{v}"); + assert_eq!(v["data"]["importance"]["state"], "unavailable"); + assert!(v["data"]["comments"] + .as_array() + .unwrap() + .iter() + .all(|r| r.get("important").is_none())); + } + s.join().unwrap(); + } +} +#[test] +fn stats_json_preserves_source_body_bytes_and_full_text() { + let t = tempfile::tempdir().unwrap(); + let raw = "{ \"math_tick\" : 12, \"group-votes\": {}, \"extension\": 1.234567890123456789 }\n"; + let text = format!("{}\u{001b}[31m\u{202e}", "é".repeat(100)); + let p = json!({"comments":[{"tid":0,"txt":text}],"pagination":{"hasMore":false}}).to_string(); + let s = server( + t.path(), + vec![ + (200, "application/json", raw.into()), + (200, "application/json", p.clone()), + json_res(counts()), + ], + ); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 0, "{v}"); + assert_eq!(v["data"]["reads"][0]["body"], raw); + assert_eq!(v["data"]["reads"][1]["body"], p); + assert_eq!(v["data"]["comments"][0]["text"], text); + assert!(v["data"]["comments"][0]["votes"].is_null()); + s.join().unwrap(); +} +#[test] +fn stats_pages_before_ranking_and_ties_by_tid() { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![ + json_res(math()), + json_res(json!({"comments":[{"tid":1,"txt":"one"}],"pagination":{"hasMore":true}})), + json_res(json!({"comments":[{"tid":0,"txt":"zero"}],"pagination":{"hasMore":false}})), + json_res(counts()), + ], + ); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 0, "{v}"); + assert_eq!(v["data"]["comments"][0]["tid"], 0); + let r = s.join().unwrap(); + assert!(r[2].contains("offset=1")); +} +#[test] +fn stats_missing_group_entry_is_unknown_and_hidden_math_is_not_exposed() { + let t = tempfile::tempdir().unwrap(); + let mut m = math(); + m["group-votes"]["1"]["votes"] + .as_object_mut() + .unwrap() + .remove("0"); + m["group-votes"]["0"]["votes"]["99"] = json!({"A":3,"D":0,"S":3}); + let s = server( + t.path(), + vec![json_res(m), json_res(page()), json_res(counts())], + ); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 0, "{v}"); + let rows = v["data"]["comments"].as_array().unwrap(); + assert_eq!(rows.len(), 4); + assert!(rows.iter().find(|r| r["tid"] == 0).unwrap()["votes"].is_null()); + s.join().unwrap(); +} +#[test] +fn stats_rejects_malformed_math_before_text_or_importance() { + for (key, value) in [ + ("A", json!(-1)), + ("D", json!(1.5)), + ("S", json!(1)), + ("A", json!(9007199254740992u64)), + ("D", Value::Null), + ] { + let t = tempfile::tempdir().unwrap(); + let mut m = math(); + m["group-votes"]["0"]["votes"]["0"][key] = value; + let s = server(t.path(), vec![json_res(m)]); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 1, "{v}"); + assert!(v["data"].is_null()); + s.join().unwrap(); + } +} +#[test] +fn stats_rejects_duplicate_text_or_nonprogressing_pages() { + for p in [ + json!({"comments":[{"tid":0,"txt":"one"},{"tid":0,"txt":"two"}],"pagination":{"hasMore":false}}), + json!({"comments":[],"pagination":{"hasMore":true}}), + json!({"comments":[],"pagination":{}}), + ] { + let t = tempfile::tempdir().unwrap(); + let s = server(t.path(), vec![json_res(math()), json_res(p)]); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 1, "{v}"); + assert!(v["data"].is_null()); + s.join().unwrap(); + } +} +#[test] +fn stats_invalid_inputs_fail_before_credentials_or_network() { + for a in [ + vec!["comment", "stats", "--conversation", "bad/id"], + vec![ + "comment", + "stats", + "--conversation", + "convA", + "--sort", + "bogus", + ], + ] { + let t = tempfile::tempdir().unwrap(); + std::fs::write(t.path().join("credentials-local.json"), "broken").unwrap(); + let (exit, v) = call(t.path(), &a, None, false); + assert_eq!(exit, 2, "{v}"); + } +} +#[test] +fn stats_empty_and_pass_only_do_not_claim_consensus_or_division() { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![ + json_res(math()), + json_res(json!({"comments":[],"pagination":{"hasMore":false}})), + json_res(counts()), + ], + ); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 0, "{v}"); + assert_eq!(v["data"]["comments"], json!([])); + s.join().unwrap(); +} +#[test] +fn stats_terminal_is_truncated_and_control_safe() { + let t = tempfile::tempdir().unwrap(); + let mut p = page(); + p["comments"][0]["txt"] = json!(format!("\u{001b}[31m\u{202e}{}", "a".repeat(100))); + let s = server( + t.path(), + vec![json_res(math()), json_res(p), json_res(counts())], + ); + let out = Command::new(env!("CARGO_BIN_EXE_polis")) + .env("POLIS_CONFIG_DIR", t.path()) + .args(args()) + .arg("--by-group") + .output() + .unwrap(); + assert!(out.status.success()); + let text = String::from_utf8(out.stdout).unwrap(); + assert!(text.contains("AGREE%")); + assert!(text.contains("group 0:")); + assert!(text.contains('…')); + assert!(!text.contains(&"a".repeat(100))); + assert!(!text.contains('\u{001b}')); + assert!(!text.contains('\u{202e}')); + s.join().unwrap(); +} +#[test] +fn stats_rejects_excess_groups_tids_and_unsafe_sums() { + let mut too_many = math(); + too_many["group-votes"] = json!((0..1001) + .map(|i| (i.to_string(), json!({"votes":{}}))) + .collect::>()); + let mut too_many_tids = math(); + too_many_tids["group-votes"]["0"]["votes"] = json!((0..10001) + .map(|i| (i.to_string(), json!({"A":0,"D":0,"S":0}))) + .collect::>()); + for m in [too_many, too_many_tids] { + let t = tempfile::tempdir().unwrap(); + let s = server(t.path(), vec![json_res(m)]); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 1, "{v}"); + assert_eq!(v["error"]["code"], "comment_stats_limit"); + s.join().unwrap(); + } + let mut m = math(); + m["group-votes"]["0"]["votes"]["0"]["S"] = json!(9007199254740991u64); + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![json_res(m), json_res(page()), json_res(counts())], + ); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 1, "{v}"); + assert!(v["data"].is_null()); + s.join().unwrap(); +} +#[test] +fn stats_rejects_more_than_ten_thousand_text_rows_without_partial_output() { + let t = tempfile::tempdir().unwrap(); + let mut replies = vec![json_res(math())]; + for page in 0..20 { + replies.push(json_res(json!({"comments":(page*500..(page+1)*500).map(|tid|json!({"tid":tid,"txt":"generated"})).collect::>(),"pagination":{"hasMore":true}}))); + } + let s = server(t.path(), replies); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 1, "{v}"); + assert_eq!(v["error"]["code"], "comment_stats_limit"); + assert!(v["data"].is_null()); + assert_eq!(s.join().unwrap().len(), 21); +} +#[test] +fn stats_rejects_invalid_successful_importance_contract() { + let t = tempfile::tempdir().unwrap(); + let mut c = counts(); + c["conversation_id"] = json!("other"); + let s = server( + t.path(), + vec![json_res(math()), json_res(page()), json_res(c)], + ); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 1, "{v}"); + assert!(v["data"].is_null()); + s.join().unwrap(); +} + +#[test] +fn stats_legacy_snake_case_pagination_is_not_mistaken_for_a_complete_page() { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![ + json_res(math()), + json_res(json!({"comments":[],"pagination":{"has_more":false}})), + ], + ); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 1, "{v}"); + assert!(v["data"].is_null()); + s.join().unwrap(); +} +#[test] +fn stats_math_without_groups_marks_every_statistic_unknown() { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![ + json_res(json!({"math_tick":0,"group-votes":{}})), + json_res(page()), + json_res(counts()), + ], + ); + let (exit, v) = call(t.path(), &args(), None, false); + assert_eq!(exit, 0, "{v}"); + let rows = v["data"]["comments"].as_array().unwrap(); + assert_eq!(rows.len(), 4); + assert!(rows + .iter() + .all(|r| r["votes"].is_null() && r["consensus"].is_null())); + assert!(v["data"]["notes"] + .as_array() + .unwrap() + .iter() + .any(|n| n.as_str().unwrap().contains("no opinion groups"))); + s.join().unwrap(); +} diff --git a/polis-cli/tests/differential/cases.py b/polis-cli/tests/differential/cases.py index db12890e0..787a98695 100644 --- a/polis-cli/tests/differential/cases.py +++ b/polis-cli/tests/differential/cases.py @@ -18,6 +18,8 @@ def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): add('account view');add('plan view') add('conversation list');add('conversation view',[C]);add('conversation stats',[C]) add('math view',['--conversation',C]) + # Successful statistics/optional importance are covered by generated HTTP tests. + add('comment stats',['--conversation','invalid/id'],exit=2,scope='invalid-input') add('api',['/api/v3/users']) add('join',[C],actor='participant') for path,args in [ From 72bca65a3c9befbf42d26c3e821784b4fe419603 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 17:22:27 -0700 Subject: [PATCH 07/30] cli: polis questions, the patterns worth looking for and the command for each (#3235) CLI only (seven files), stacked on comment stats (merge order: naming, stats, questions). polis questions prints, with no sign-in, the ten patterns an organizer looks for in a conversation (what everyone agreed on; what divided the room; the groups and what defines each; what each group alone believes; what is important to people; what is new; what lacks votes; how it moved over time; the collective statements per topic; one participant against the room) with the exact command for each, plus a root help section and a JSON guide. All examples use the renamed commands. Reviewed independently: publish as-is. Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- polis-cli/README.md | 12 +++ polis-cli/crates/polis/src/commands.rs | 7 +- polis-cli/crates/polis/src/main.rs | 4 +- polis-cli/crates/polis/src/questions.rs | 30 ++++++++ polis-cli/crates/polis/tests/questions.rs | 92 +++++++++++++++++++++++ polis-cli/docs/questions.json | 66 ++++++++++++++++ polis-cli/tests/differential/cases.py | 2 +- 7 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 polis-cli/crates/polis/src/questions.rs create mode 100644 polis-cli/crates/polis/tests/questions.rs create mode 100644 polis-cli/docs/questions.json diff --git a/polis-cli/README.md b/polis-cli/README.md index 84b9ef9bf..9a89b10ff 100644 --- a/polis-cli/README.md +++ b/polis-cli/README.md @@ -918,3 +918,15 @@ they select a comment where the command concerns participation. Comment analysis: `polis comment stats --conversation CONV --sort divisive --by-group` answers which comments divided the room most. See [the statistics contract](COMMENT-STATS.md) for denominators, unknown values, bounds and the byte-preserving JSON source envelope. + +### Questions to ask about a conversation + +Run `polis questions` for ten plain-language analyst questions, the commands for +each, and what to look for. The guide starts with shared ground and divisions, +then covers groups, distinctive beliefs, importance, new comments, vote coverage, +change over time, collective statements, and comparing one participant by XID. +`polis questions --json` returns `data.schema=polis-questions/1`, the introduction, +ordered question entries (`id`, `question`, `commands`, `look_for`) and rendered +help. It works offline without a profile or credentials and runs none of the +listed commands. It distinguishes existing reads from comparisons an analyst +must make and from the consensus timeline the CLI does not yet provide. diff --git a/polis-cli/crates/polis/src/commands.rs b/polis-cli/crates/polis/src/commands.rs index 6ed2be3dc..c338ceafb 100644 --- a/polis-cli/crates/polis/src/commands.rs +++ b/polis-cli/crates/polis/src/commands.rs @@ -131,6 +131,7 @@ pub fn available(path: &str) -> bool { | "plan upgrade" | "plan manage" | "completion" + | "questions" | "tutorial" | "api" | "schema" @@ -218,6 +219,9 @@ fn leaf(path: &str) -> Command { } "completion" => "Generate shell completions from the command tree without accessing a site", "tutorial" => "Read the terminal getting-started manual", + "questions" => { + "Find questions worth asking about a conversation, and commands to answer them" + } "seed add" => "Add one seed comment through the moderator-enforced bulk API", "seed import" => "Validate a CSV, then import its seed comments as moderator", "seed csv validate" => "Validate UTF-8 CSV headers, lengths, duplicates, and row counts", @@ -493,10 +497,11 @@ report exports, stored Delphi results, and raw API.\nThe full product surface is "powershell", "elvish", ]))); + root = root.subcommand(leaf("questions").after_help(crate::questions::text())); for name in ["browse", "tutorial"] { root = root.subcommand(leaf(name).arg(pos("target", false))); } - root.after_help(format!("CONVERSATION RESERVATION\n polis conversation reserve --json\n\nPARTICIPANT PREFERENCES\n polis participant preferences --conversation --translations true --json\n\nPARTICIPANT LOCATIONS\n polis participant locations --conversation --group 0 --json\n\nPARTICIPANT PROFILES\n polis participant highlight list --conversation --json\n\nSTORED MEMBERSHIP\n polis participant group-members --conversation --json\n\nSTORED MATH\n polis math view --conversation --key math_tick --key pca --json\n\nSTART HERE\n polis auth login\n polis auth status\n polis conversation list --json\n polis conversation create --topic 'Our next chapter'\n polis seed import seeds.csv --conversation \n\nMETADATA OPTIONS\n polis metadata answer add --conversation --question --value 'Local resident' --yes\n\nMETADATA CLEANUP\n polis metadata question delete --conversation --question --yes\n polis metadata answer delete --conversation --question --answer --yes\n\nSECOND PASS\n polis moderate list --conversation --status pending\n polis moderate accept --conversation --tid 0\n polis moderate reject --conversation --tid 0\n polis participant status --conversation \n polis vote list --conversation --pid 0\n polis report view \n polis report export --type votes.csv --output votes.csv\n polis delphi status --report \n polis delphi results --report --job \n polis plan view\n\nDISCOVER THE PRODUCT\n{}\n\nAGENT CONTRACT\n --json --no-interactive Stable output; no prompts or automatic retries\n polis help Read a focused manual\n polis schema Discover commands and implementation status\n POLIS_TOKEN Token override; otherwise owner-only file (Keychain opt-in)\n POLIS_CONFIG_DIR Profile directory override (credentials/ holds saved sign-ins)\n POLIS_KEYCHAIN on opts into macOS Keychain; off is the default\n\nSign in to pol.is with polis auth login; no setup is required. Developer overrides use environment variables or profiles.json.\nQuota is reported as unavailable. Planned commands perform no action.",tree())) + root.after_help(format!("QUESTIONS ABOUT YOUR CONVERSATION\n polis questions\n Find shared ground, divisions, groups, importance, new comments, coverage, change, collective statements and participant comparisons.\n\nCONVERSATION RESERVATION\n polis conversation reserve --json\n\nPARTICIPANT PREFERENCES\n polis participant preferences --conversation --translations true --json\n\nPARTICIPANT LOCATIONS\n polis participant locations --conversation --group 0 --json\n\nPARTICIPANT PROFILES\n polis participant highlight list --conversation --json\n\nSTORED MEMBERSHIP\n polis participant group-members --conversation --json\n\nSTORED MATH\n polis math view --conversation --key math_tick --key pca --json\n\nSTART HERE\n polis auth login\n polis auth status\n polis conversation list --json\n polis conversation create --topic 'Our next chapter'\n polis seed import seeds.csv --conversation \n\nMETADATA OPTIONS\n polis metadata answer add --conversation --question --value 'Local resident' --yes\n\nMETADATA CLEANUP\n polis metadata question delete --conversation --question --yes\n polis metadata answer delete --conversation --question --answer --yes\n\nSECOND PASS\n polis moderate list --conversation --status pending\n polis moderate accept --conversation --tid 0\n polis moderate reject --conversation --tid 0\n polis participant status --conversation \n polis vote list --conversation --pid 0\n polis report view \n polis report export --type votes.csv --output votes.csv\n polis delphi status --report \n polis delphi results --report --job \n polis plan view\n\nDISCOVER THE PRODUCT\n{}\n\nAGENT CONTRACT\n --json --no-interactive Stable output; no prompts or automatic retries\n polis help Read a focused manual\n polis schema Discover commands and implementation status\n POLIS_TOKEN Token override; otherwise owner-only file (Keychain opt-in)\n POLIS_CONFIG_DIR Profile directory override (credentials/ holds saved sign-ins)\n POLIS_KEYCHAIN on opts into macOS Keychain; off is the default\n\nSign in to pol.is with polis auth login; no setup is required. Developer overrides use environment variables or profiles.json.\nQuota is reported as unavailable. Planned commands perform no action.",tree())) } pub fn tree() -> String { let mut lines = vec![ diff --git a/polis-cli/crates/polis/src/main.rs b/polis-cli/crates/polis/src/main.rs index e2f18b9ac..5f2246629 100644 --- a/polis-cli/crates/polis/src/main.rs +++ b/polis-cli/crates/polis/src/main.rs @@ -27,6 +27,7 @@ mod pass9; mod preferences; mod prioritize; mod profiles; +mod questions; mod reads; mod reserve; mod seeds; @@ -182,6 +183,7 @@ fn execute(root: &ArgMatches, config: &mut profiles::Config, site: &str) -> Resu Ok(json!({"help":cmd.bin_name(full_name).render_long_help().to_string()})) } } + "questions" => Ok(questions::execute()), "completion" => { let shell = str_arg(m, "shell") .parse::() @@ -713,7 +715,7 @@ fn main() -> ExitCode { // Help and schema never depend on credentials or profile files. if matches!( root.subcommand_name(), - Some("help" | "schema" | "agent" | "completion" | "tutorial") + Some("help" | "schema" | "agent" | "completion" | "tutorial" | "questions") ) { return render( "unresolved", diff --git a/polis-cli/crates/polis/src/questions.rs b/polis-cli/crates/polis/src/questions.rs new file mode 100644 index 000000000..7206d147a --- /dev/null +++ b/polis-cli/crates/polis/src/questions.rs @@ -0,0 +1,30 @@ +//! Offline questions an analyst can answer with the existing command surface. +use serde_json::{json, Value}; +fn guide() -> Value { + serde_json::from_str(include_str!("../../../docs/questions.json")) + .expect("validated questions guide") +} +pub fn text() -> String { + let guide = guide(); + let mut out = format!( + "Questions to ask about a Polis conversation\n\n{}\n", + guide["intro"].as_str().unwrap() + ); + for (i, row) in guide["questions"].as_array().unwrap().iter().enumerate() { + out.push_str(&format!( + "\n{}. {}\n", + i + 1, + row["question"].as_str().unwrap() + )); + for command in row["commands"].as_array().unwrap() { + out.push_str(&format!(" {}\n", command.as_str().unwrap())); + } + out.push_str(&format!("{}\n", row["look_for"].as_str().unwrap())); + } + out +} +pub fn execute() -> Value { + let mut guide = guide(); + guide["help"] = json!(text()); + guide +} diff --git a/polis-cli/crates/polis/tests/questions.rs b/polis-cli/crates/polis/tests/questions.rs new file mode 100644 index 000000000..2b202ba74 --- /dev/null +++ b/polis-cli/crates/polis/tests/questions.rs @@ -0,0 +1,92 @@ +use serde_json::Value; +use std::process::Command; +fn run(args: &[&str]) -> (i32, Value) { + let dir = tempfile::tempdir().unwrap(); + std::fs::write(dir.path().join("profiles.json"), "invalid-profile").unwrap(); + let o = Command::new(env!("CARGO_BIN_EXE_polis")) + .env("POLIS_CONFIG_DIR", dir.path()) + .args(args) + .arg("--json") + .output() + .unwrap(); + ( + o.status.code().unwrap(), + serde_json::from_slice(&o.stdout).unwrap(), + ) +} +#[test] +fn questions_are_offline_and_cover_the_ten_patterns_in_order() { + let (exit, v) = run(&["questions"]); + assert_eq!(exit, 0, "{v}"); + assert_eq!(v["data"]["schema"], "polis-questions/1"); + let rows = v["data"]["questions"].as_array().unwrap(); + assert_eq!(rows.len(), 10); + let ids: Vec<_> = rows.iter().map(|v| v["id"].as_str().unwrap()).collect(); + assert_eq!( + ids, + [ + "shared-ground", + "division", + "groups", + "distinctive-beliefs", + "importance", + "new-comments", + "needs-votes", + "change-over-time", + "collective-statements", + "participant-against-room" + ] + ); + for row in rows { + assert!(!row["look_for"].as_str().unwrap().is_empty()); + assert!(!row["commands"].as_array().unwrap().is_empty()); + } + assert!(v["data"]["help"] + .as_str() + .unwrap() + .contains("data.convention")); + assert!(v["data"]["help"] + .as_str() + .unwrap() + .contains("does not yet provide an automatic consensus timeline")); +} +#[test] +fn every_suggested_command_parses_without_loading_a_profile() { + let (exit, v) = run(&["questions"]); + assert_eq!(exit, 0, "{v}"); + for row in v["data"]["questions"].as_array().unwrap() { + for c in row["commands"].as_array().unwrap() { + let example = c + .as_str() + .unwrap() + .replace("CONV", "convA") + .replace("REPORT", "repA") + .replace("UNTIL_MS", "1700000000000") + .replace("PID", "0"); + let mut args: Vec<_> = example + .split_whitespace() + .skip(1) + .filter(|s| *s != "--json") + .collect(); + args.push("--help"); + let (exit, v) = run(&args); + assert_eq!(exit, 0, "{example}: {v}"); + } + } +} +#[test] +fn guide_is_discoverable_in_top_help_schema_and_its_own_help() { + for args in [ + vec!["--help"], + vec!["help"], + vec!["schema", "questions"], + vec!["questions", "--help"], + ] { + let (exit, v) = run(&args); + assert_eq!(exit, 0, "{v}"); + assert!(v.to_string().contains("questions")); + if args == ["questions", "--help"] { + assert!(v.to_string().contains("What divided us")); + } + } +} diff --git a/polis-cli/docs/questions.json b/polis-cli/docs/questions.json new file mode 100644 index 000000000..49a2325fc --- /dev/null +++ b/polis-cli/docs/questions.json @@ -0,0 +1,66 @@ +{ + "schema": "polis-questions/1", + "intro": "Start with shared ground, then examine differences. A comment is a participant's contribution; a statement is a collective statement. Replace CONV with a conversation ID, REPORT with its report ID, PID with a participant number, and UNTIL_MS with an exclusive positive UTC epoch-millisecond cutoff. These commands read existing data. This guide itself is offline and does not sign in or run any command.", + "questions": [ + { + "id": "shared-ground", + "question": "What did everyone agree on?", + "commands": ["polis comment stats --conversation CONV --sort consensus --by-group", "polis comment stats --conversation CONV --sort agree --json"], + "look_for": "Comments with high support in every opinion group, backed by enough votes in each. Consensus here is the lowest group agree percentage, not a claim that every person agreed. The math covers grouped participants only; unknown values and small samples need attention." + }, + { + "id": "division", + "question": "What divided us, and what drew the most disagreement?", + "commands": ["polis comment stats --conversation CONV --sort divisive --by-group", "polis comment stats --conversation CONV --sort disagree"], + "look_for": "Divisiveness finds an even agree/disagree split; disagreement sorts by the percentage disagreeing. They answer different questions. Compare the group splits and vote counts before interpreting a high rank; all-pass comments have no measured agree/disagree split." + }, + { + "id": "groups", + "question": "Which groups exist, and what defines each?", + "commands": ["polis math view --conversation CONV --key group-clusters --key group-votes --key repness --json"], + "look_for": "Read representative comments for each group, then inspect their counts. Group IDs are not array positions. The group-clusters members are base-cluster IDs, not participant IDs. Treat groups as patterns in this served math snapshot, not fixed kinds of people." + }, + { + "id": "distinctive-beliefs", + "question": "What does one group believe that the others do not?", + "commands": ["polis comment stats --conversation CONV --by-group --json", "polis math view --conversation CONV --key repness --json"], + "look_for": "Compare one group's agree percentage with every other group's for the same tid. Look for a large gap supported by enough votes, not merely a high within-group percentage. This is a comparison to make from the returned data, not an automatic test of a unique belief. Separate reads can refer to different math snapshots." + }, + { + "id": "importance", + "question": "What matters most to people?", + "commands": ["polis comment stats --conversation CONV --sort important --by-group"], + "look_for": "Importance marks identify comments people chose to emphasize; they do not mean agreement. Counts use the current importance read, separately from math. This sort exits 8 if that read is unavailable. Missing counts mean unknown, never zero." + }, + { + "id": "new-comments", + "question": "What is new in the conversation?", + "commands": ["polis comment list --conversation CONV --limit 500 --offset 0 --json"], + "look_for": "Inspect created timestamps and compare tids with a saved earlier list. Follow pagination.hasMore with the next offset to inspect later pages. One page is not the whole conversation, and offset pages can change during participation. Newly visible comments can be absent from served math." + }, + { + "id": "needs-votes", + "question": "Which comments have not received enough votes?", + "commands": ["polis comment stats --conversation CONV --sort votes --json"], + "look_for": "This sort is descending: examine the smallest observed votes counts, near the end before nulls, or sort data.comments by votes ascending yourself. Keep null counts separate; missing math is not zero votes. Compare coverage across groups. There is no universal enough-votes threshold." + }, + { + "id": "change-over-time", + "question": "How has participation or agreement changed over time?", + "commands": ["polis report stats REPORT --until UNTIL_MS --json", "polis comment stats --conversation CONV --by-group --json", "polis delphi show REPORT --json"], + "look_for": "Report stats supplies historical event timing, not historical opinion-group support. Save dated stats snapshots and compare matching tids; group IDs may not identify the same population across runs. Stored Delphi results supply run context. The CLI does not yet provide an automatic consensus timeline or reconstruct old group tallies from an until cutoff." + }, + { + "id": "collective-statements", + "question": "What do the collective statements say for each topic?", + "commands": ["polis collective statements REPORT", "polis delphi show REPORT --json"], + "look_for": "Read the topic statements and citations alongside their source comments. Delphi show supplies stored model/run context. These reads show stored results; they do not generate statements or call a model. Missing results are not proof of an empty conversation." + }, + { + "id": "participant-against-room", + "question": "How did one participant, identified by XID, vote compared with the room?", + "commands": ["polis participant xid list --conversation CONV --json", "polis vote list --conversation CONV --pid PID --json", "polis comment stats --conversation CONV --by-group --json", "polis report export REPORT --type format.json --output format.json"], + "look_for": "With the required permission, resolve the exact XID to its participant number, then join their votes to comment stats by tid. Preserve XIDs as opaque strings and join only within the same conversation. Access can be restricted; an empty or withheld mapping is not proof of no participant. Do not guess numeric vote signs: vote list returns data.convention for its wire values, while exports have a separate convention. Use that returned declaration and the export format metadata before comparing votes; do not assume wire and storage conventions are interchangeable. No automatic XID join is performed here." + } + ] +} diff --git a/polis-cli/tests/differential/cases.py b/polis-cli/tests/differential/cases.py index 787a98695..981d18545 100644 --- a/polis-cli/tests/differential/cases.py +++ b/polis-cli/tests/differential/cases.py @@ -11,7 +11,7 @@ def cases(): def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): rows.append(dict(command=command,args=command.split()+list(args),expected_exit=exit,scope=scope,stdin=stdin,actor=actor)) # Local discovery is exercised as commands, not substituted for API calls. - for command,args in [('schema',[]),('help',[]),('completion',['bash']),('tutorial',[]),('agent guide',[]),('conversation share',[C]),('plan upgrade',[]),('plan manage',[])]: + for command,args in [('schema',[]),('help',[]),('completion',['bash']),('tutorial',[]),('questions',[]),('agent guide',[]),('conversation share',[C]),('plan upgrade',[]),('plan manage',[])]: add(command,args,scope='local') add('auth login',['--with-token'],stdin='owner') add('auth status');add('auth token',scope='credential') From a19d3b936f6fb1f2ff04988892ba84906aa1760b Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 18:36:58 -0700 Subject: [PATCH 08/30] cli: one client, many sites: pol.is by default, named sites with --site, site add/list/use/remove (#3236) CLI only. pol.is stays the default with no configuration and every existing command is unchanged without one. A named site (a local stack, a self-hosted or regional instance) is added once with polis site add NAME URL, selected per command with --site NAME or made the saved default with polis site use NAME; polis site use default returns to pol.is. Sign-ins are kept per site, the config write is atomic and locked, and the active site is named in output whenever it is not pol.is. Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- polis-cli/README.md | 86 ++++ polis-cli/crates/polis/src/commands.rs | 18 +- polis-cli/crates/polis/src/main.rs | 32 +- polis-cli/crates/polis/src/profiles.rs | 40 +- polis-cli/crates/polis/src/sites.rs | 279 +++++++++++ polis-cli/crates/polis/tests/cli.rs | 62 ++- polis-cli/crates/polis/tests/invites.rs | 11 +- polis-cli/crates/polis/tests/sites.rs | 589 ++++++++++++++++++++++++ polis-cli/docs/development.md | 11 +- polis-cli/tests/differential/cases.py | 4 + 10 files changed, 1097 insertions(+), 35 deletions(-) create mode 100644 polis-cli/crates/polis/src/sites.rs create mode 100644 polis-cli/crates/polis/tests/sites.rs diff --git a/polis-cli/README.md b/polis-cli/README.md index 9a89b10ff..14fe5f077 100644 --- a/polis-cli/README.md +++ b/polis-cli/README.md @@ -43,6 +43,92 @@ binary as configuration. Authentication and credentials stay bound to that origi Developer overrides for local servers and preproduction are documented in [development configuration](docs/development.md). +## Sites + +One CLI works with pol.is, your local stack, a community's self-hosted installation, +and regional hosts. **pol.is is the default with no setup.** Add a name for another +site, then use `--site NAME` on any command to visit it just for that command: + +```sh +polis site add dev http://localhost:5000 +polis --site dev conversation list --json +polis conversation list --json # back on pol.is +polis site list +``` + +For a self-hosted site, ask its operator for the address and public sign-in +settings. These example.org addresses are placeholders: + +```sh +polis site add community https://polis.example.org \ + --issuer https://login.example.org/ --client-id PUBLIC_NATIVE_CLIENT_ID \ + --audience users --callback-port 53147 +polis --site community auth login +polis --site community conversation list +``` + +A local stack with OAuth uses the same options, with its loopback issuer and +native client ID. Otherwise use `polis --site dev auth login --with-token` with a +token issued by that stack. Adding a site never signs in or contacts a server; +pol.is sign-in settings are never copied to other sites. `--callback-port` is +optional; the browser callback defaults to port 53147. Its redirect address must +be registered by the site's operator. + +For repeated work on a regional site, save it as your preference. Return to +pol.is with one command: + +```sh +polis site add eu https://polis.eu.example.org \ + --issuer https://login.eu.example.org/ --client-id EU_PUBLIC_NATIVE_CLIENT_ID \ + --audience users +polis site use eu +polis auth login +polis conversation list +polis --site default conversation list # pol.is for just this command +polis site use default # pol.is for following commands too +``` + +`site use NAME` is an explicit sticky preference. Without a flag, commands use +that preference until `site use default` restores pol.is. `default` is reserved +and refers to the built-in `prod` profile; the older `prod` name still works. +The flag works before or after subcommands and never changes your saved preference. +When an operation targets an origin other than pol.is, a **Site: NAME (URL)** +header on stderr identifies it, including a developer override of the prod URL. +JSON mode has no header. Offline help, the questions guide, schema and shell +completion do not select a site and stay independent of configuration. + +You sign in separately at each site. Sign-ins and participant credentials are +bound to the **site name and origin**, and account sign-ins also bind the issuer, +client ID and audience. Two aliases never share a login even at the same host. +Credentials stay in the owner-only file store by default. Site management never +accesses credentials or the Keychain. + +```sh +polis --site community auth logout +polis site remove community +``` + +Removal changes only configuration. Log out first to revoke and clear an account +sign-in. Otherwise saved credentials remain; re-adding the same name and origin +can reuse them. Removing the saved preference returns to pol.is. Neither `prod` +nor `default` can be removed. Site commands do not change accounts or conversations. + +Aliases are saved in `~/.config/polis/profiles.json`. Names use 1–40 lowercase +letters, digits or underscores; existing names cannot be overwritten. Use a new +name when changing a host or sign-in provider. Only HTTPS origins are accepted, +with HTTP allowed on loopback for local stacks. Origins cannot contain credentials, +paths, query strings or fragments; an OAuth issuer may have a path. + +For developers, existing environment overrides still use these same profiles: +**`--site NAME` > `POLIS_SITE` > saved preference > pol.is on a fresh install**. +`site use default` changes the saved preference; an explicitly set `POLIS_SITE` +still wins until unset, or use `--site default`. `POLIS_URL_` and +`POLIS_AUTH_*_` still override that profile's origin and sign-in settings, +including prod; they are never written back by site commands. `site list --json` +shows effective origins and both the selected and saved site without reading tokens. +See [development configuration](docs/development.md) for custom certificate +authorities and `POLIS_CONFIG_DIR`. + ## Authentication On a fresh install, sign in without configuration: diff --git a/polis-cli/crates/polis/src/commands.rs b/polis-cli/crates/polis/src/commands.rs index c338ceafb..86e459f49 100644 --- a/polis-cli/crates/polis/src/commands.rs +++ b/polis-cli/crates/polis/src/commands.rs @@ -3,6 +3,7 @@ use serde_json::{json, Value}; // One declaration drives parser, nested help, full command tree, and JSON schema. const GROUPS: &[(&str, &str, &str)] = &[ + ("site", "Choose and manage Polis sites", "list add use remove"), ("auth", "Sign in and inspect your session", "login status logout token refresh"), ("account", "Your identity and organization", "view edit invite verify"), ("conversation", "Create and explore conversations", "new create reserve list view edit close reopen stats activity snapshot uuid email-link share"), @@ -45,7 +46,11 @@ pub fn available(path: &str) -> bool { crate::admin::available(path) || matches!( path, - "comment" + "site list" + | "site add" + | "site use" + | "site remove" + | "comment" | "join" | "vote" | "conversation reserve" @@ -222,6 +227,10 @@ fn leaf(path: &str) -> Command { "questions" => { "Find questions worth asking about a conversation, and commands to answer them" } + "site list" => "List configured sites and the selected default", + "site add" => "Add a site alias without signing in or changing the default", + "site use" => "Select the saved default site", + "site remove" => "Remove a site alias, retaining its saved credentials", "seed add" => "Add one seed comment through the moderator-enforced bulk API", "seed import" => "Validate a CSV, then import its seed comments as moderator", "seed csv validate" => "Validate UTF-8 CSV headers, lengths, duplicates, and row counts", @@ -362,6 +371,10 @@ fn leaf(path: &str) -> Command { "participant export"|"participant xid export" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("output","New output file; never overwrite").required(true)).arg(arg("format","CSV preserves bytes; JSON retains every CSV cell as a string").value_parser(["csv","json"]).default_value("csv")).after_help("Uses the moderator-enforced XID export. Only participants with XIDs are included, not every participant. Server caps this endpoint at 1,000,000 rows; CLI bounds bytes at 8 MiB. Downloaded cells are untrusted text."), "plan view" => c.arg(flag("web","Open this site account page; no checkout or plan change")).arg(flag("no-browser","Return the account URL without opening it").requires("web")), "plan upgrade"|"plan manage" => c.arg(flag("no-browser","Return the account URL without opening it")).after_help("Billing is unavailable. Opens only /account on the configured site; no Stripe URL is invented and no subscription, payment or paid work is created. --no-interactive also suppresses the browser."), + "site list" => c.after_help("Lists configured origins and the selected site without reading credentials or contacting any server. --site overrides POLIS_SITE, then the saved default; pol.is is the initial default."), + "site add" => c.arg(pos("name",true)).arg(pos("url",true)).arg(arg("issuer","OAuth issuer URL; HTTPS, or loopback HTTP").requires("client-id")).arg(arg("client-id","Public native OAuth client ID").requires("issuer")).arg(arg("audience","OAuth audience").requires("issuer")).arg(arg("callback-port","Local browser sign-in callback port (1–65535)").value_parser(clap::value_parser!(u16).range(1..=65535)).requires("issuer")).after_help("Adds a new alias without selecting it or signing in. Names: 1–40 lowercase letters, digits or underscores; default is reserved for pol.is. HTTPS origin required; HTTP only on loopback. Existing names are never overwritten. Obtain sign-in settings from the site's operator; they are not copied from pol.is."), + "site use" => c.arg(pos("name",true)).after_help("Saves the default site. POLIS_SITE and --site still take precedence. Use default to return to pol.is (the prod profile). No network or credential access."), + "site remove" => c.arg(pos("name",true)).after_help("Removes the alias and its auth settings. Removing the saved default returns to prod (pol.is). The prod alias cannot be removed. Saved sign-ins are retained: run polis --site NAME auth logout before removal to revoke and clear an account sign-in. Re-adding the same name and origin reuses its saved credentials."), "seed add" => c.arg(arg("conversation","Public conversation ID").required(true)).arg(arg("text","Exact comment text (up to 997 UTF-16 units)").required(true)), "seed import" => c.arg(pos("csv",true)).arg(arg("votes","Optional BYOD vote CSV; all files validated before any write").requires("source-agree")).arg(arg("source-agree","Required source vote sign; forwarded unchanged to the sign-aware importer").value_parser(["+1","-1"]).allow_hyphen_values(true).requires("votes")).arg(arg("conversation","Public conversation ID").required(true)).after_help("CSV requires comment_text,original_id headers (external original_id is mapped deterministically to a site/conversation-bound UUID; UUIDs are preserved); UTF-8 with optional BOM. All rows validated first. Optional --votes requires --source-agree=+1|-1 and the server's sign-aware vote importer. Vote columns: vote_id,user_id,vote_value,timestamp,comment_id; comment_id refers to original_id in this seed file. Vote values are never converted by the CLI. Comments are imported first; votes are only queued after complete comment receipts. This is NOT atomic across comments/votes; a processing receipt is NOT import completion. No trimming, silent drops, retries, or atomicity claim. JSON data.receipt is the per-row receipt; save it and read back before any retry."), "seed csv validate"|"seed csv preview" => c.arg(pos("csv",true)), @@ -401,6 +414,7 @@ pub fn command() -> Command { .about("Listen at scale. Bring Polis to your terminal.") .long_about("Listen at scale. Bring Polis to your terminal.\n\nConversations, comments, and shared understanding — for people and agents.\nWorking now: auth, conversations, seeds, moderation, participant/vote reads, report exports, stored Delphi results, and raw API.\nThe full product surface is discoverable below; planned commands return exit 8.") + .arg(arg("site","Use a site for this command; default selects pol.is (overrides POLIS_SITE and the saved default)").global(true)) .arg(flag("json","Emit the versioned polis-cli/1 JSON envelope (including errors and help)").global(true)) .arg(flag("no-interactive","Never prompt; saved file sign-ins, explicitly opted-in Keychain and environment tokens still work").global(true)) .arg(arg("timeout","Bound each HTTP request in seconds (1–300)").default_value("30").value_parser(clap::value_parser!(u64).range(1..=300)).global(true)) @@ -501,7 +515,7 @@ report exports, stored Delphi results, and raw API.\nThe full product surface is for name in ["browse", "tutorial"] { root = root.subcommand(leaf(name).arg(pos("target", false))); } - root.after_help(format!("QUESTIONS ABOUT YOUR CONVERSATION\n polis questions\n Find shared ground, divisions, groups, importance, new comments, coverage, change, collective statements and participant comparisons.\n\nCONVERSATION RESERVATION\n polis conversation reserve --json\n\nPARTICIPANT PREFERENCES\n polis participant preferences --conversation --translations true --json\n\nPARTICIPANT LOCATIONS\n polis participant locations --conversation --group 0 --json\n\nPARTICIPANT PROFILES\n polis participant highlight list --conversation --json\n\nSTORED MEMBERSHIP\n polis participant group-members --conversation --json\n\nSTORED MATH\n polis math view --conversation --key math_tick --key pca --json\n\nSTART HERE\n polis auth login\n polis auth status\n polis conversation list --json\n polis conversation create --topic 'Our next chapter'\n polis seed import seeds.csv --conversation \n\nMETADATA OPTIONS\n polis metadata answer add --conversation --question --value 'Local resident' --yes\n\nMETADATA CLEANUP\n polis metadata question delete --conversation --question --yes\n polis metadata answer delete --conversation --question --answer --yes\n\nSECOND PASS\n polis moderate list --conversation --status pending\n polis moderate accept --conversation --tid 0\n polis moderate reject --conversation --tid 0\n polis participant status --conversation \n polis vote list --conversation --pid 0\n polis report view \n polis report export --type votes.csv --output votes.csv\n polis delphi status --report \n polis delphi results --report --job \n polis plan view\n\nDISCOVER THE PRODUCT\n{}\n\nAGENT CONTRACT\n --json --no-interactive Stable output; no prompts or automatic retries\n polis help Read a focused manual\n polis schema Discover commands and implementation status\n POLIS_TOKEN Token override; otherwise owner-only file (Keychain opt-in)\n POLIS_CONFIG_DIR Profile directory override (credentials/ holds saved sign-ins)\n POLIS_KEYCHAIN on opts into macOS Keychain; off is the default\n\nSign in to pol.is with polis auth login; no setup is required. Developer overrides use environment variables or profiles.json.\nQuota is reported as unavailable. Planned commands perform no action.",tree())) + root.after_help(format!("QUESTIONS ABOUT YOUR CONVERSATION\n polis questions\n Find shared ground, divisions, groups, importance, new comments, coverage, change, collective statements and participant comparisons.\n\nCONVERSATION RESERVATION\n polis conversation reserve --json\n\nPARTICIPANT PREFERENCES\n polis participant preferences --conversation --translations true --json\n\nPARTICIPANT LOCATIONS\n polis participant locations --conversation --group 0 --json\n\nPARTICIPANT PROFILES\n polis participant highlight list --conversation --json\n\nSTORED MEMBERSHIP\n polis participant group-members --conversation --json\n\nSTORED MATH\n polis math view --conversation --key math_tick --key pca --json\n\nSTART HERE\n polis auth login\n polis auth status\n polis conversation list --json\n polis conversation create --topic 'Our next chapter'\n polis seed import seeds.csv --conversation \n\nMETADATA OPTIONS\n polis metadata answer add --conversation --question --value 'Local resident' --yes\n\nMETADATA CLEANUP\n polis metadata question delete --conversation --question --yes\n polis metadata answer delete --conversation --question --answer --yes\n\nSECOND PASS\n polis moderate list --conversation --status pending\n polis moderate accept --conversation --tid 0\n polis moderate reject --conversation --tid 0\n polis participant status --conversation \n polis vote list --conversation --pid 0\n polis report view \n polis report export --type votes.csv --output votes.csv\n polis delphi status --report \n polis delphi results --report --job \n polis plan view\n\nDISCOVER THE PRODUCT\n{}\n\nAGENT CONTRACT\n --json --no-interactive Stable output; no prompts or automatic retries\n polis help Read a focused manual\n polis schema Discover commands and implementation status\n POLIS_TOKEN Token override; otherwise owner-only file (Keychain opt-in)\n POLIS_CONFIG_DIR Profile directory override (credentials/ holds saved sign-ins)\n POLIS_KEYCHAIN on opts into macOS Keychain; off is the default\n\nSign in to pol.is with polis auth login; no setup is required. Use polis site add/use/list/remove to manage other sites, and --site NAME for one command. Use polis site use default to return to pol.is. POLIS_SITE and profile-specific environment overrides remain supported.\nQuota is reported as unavailable. Planned commands perform no action.",tree())) } pub fn tree() -> String { let mut lines = vec![ diff --git a/polis-cli/crates/polis/src/main.rs b/polis-cli/crates/polis/src/main.rs index 5f2246629..866090a8a 100644 --- a/polis-cli/crates/polis/src/main.rs +++ b/polis-cli/crates/polis/src/main.rs @@ -32,6 +32,7 @@ mod reads; mod reserve; mod seeds; mod setup; +mod sites; mod sizes; mod voting; use clap::ArgMatches; @@ -151,6 +152,9 @@ fn execute(root: &ArgMatches, config: &mut profiles::Config, site: &str) -> Resu return admin::execute(&path, m, config, site, timeout); } match path.as_str() { + "site list" | "site add" | "site use" | "site remove" => { + sites::execute(&path, m, config, site) + } "help" | "schema" => { if path == "help" && m.get_many::("command") @@ -727,7 +731,13 @@ fn main() -> ExitCode { json_mode || root.subcommand_name() == Some("schema"), ); } - let mut config = match profiles::Config::load() { + let selected = root.get_one::("site").map(String::as_str); + let loaded = if root.subcommand_name() == Some("site") { + sites::load(selected) + } else { + profiles::Config::load(selected) + }; + let mut config = match loaded { Ok(c) => c, Err(e) => return render("unresolved", Err(e), json_mode), }; @@ -735,7 +745,27 @@ fn main() -> ExitCode { if let Err(e) = profiles::name(&site) { return render(&site, Err(e), json_mode); } + if selected.is_some() { + if let Err(e) = config.url(&site) { + return render(&site, Err(e), json_mode); + } + } + let site_command = root.subcommand_name() == Some("site"); + if !json_mode && !site_command { + sites::print_header(&config, &site); + } let result = execute(&root, &mut config, &site); + if !json_mode && site_command { + // Site management reports the effective selection after a successful change. + if result.is_ok() { + match sites::load(selected) { + Ok(updated) => sites::print_header(&updated, &updated.default), + Err(_) => sites::print_header(&config, &site), + } + } else { + sites::print_header(&config, &site); + } + } if !json_mode && root .subcommand_matches("comment") diff --git a/polis-cli/crates/polis/src/profiles.rs b/polis-cli/crates/polis/src/profiles.rs index 3fffe567a..560828de1 100644 --- a/polis-cli/crates/polis/src/profiles.rs +++ b/polis-cli/crates/polis/src/profiles.rs @@ -37,7 +37,7 @@ pub fn name(raw: &str) -> Result<()> { } Ok(()) } -fn path() -> Result { +pub(crate) fn path() -> Result { if let Some(dir) = std::env::var_os("POLIS_CONFIG_DIR") { return Ok(PathBuf::from(dir).join("profiles.json")); } @@ -46,24 +46,50 @@ fn path() -> Result { .ok_or_else(|| Error::input("Set HOME or POLIS_CONFIG_DIR.")) } impl Config { - pub fn load() -> Result { - let mut config = match std::fs::read(path()?) { + pub(crate) fn load_saved() -> Result { + match std::fs::read(path()?) { Ok(bytes) => serde_json::from_slice(&bytes).map_err(|_| { Error::input("Invalid profiles.json. Correct the file before continuing.") }), Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(Self::default()), Err(_) => Err(Error::input("Cannot read profiles.json.")), - }?; - if let Ok(site) = std::env::var("POLIS_SITE") { + } + } + pub fn load(selected: Option<&str>) -> Result { + Self::load_saved()?.with_overrides(selected) + } + pub(crate) fn with_overrides(mut self, selected: Option<&str>) -> Result { + let config = &mut self; + if let Some(site) = selected + .map(str::to_owned) + .or_else(|| std::env::var("POLIS_SITE").ok()) + { name(&site)?; - config.default = site; + config.default = if site == "default" { + default_profile() + } else { + site + }; + } + // The reserved default name always resolves to the built-in profile. + // Older custom configurations may not contain that profile yet. + let defaults = Self::default(); + if !config.sites.contains_key(&defaults.default) { + config.sites.insert( + defaults.default.clone(), + defaults.sites[&defaults.default].clone(), + ); + config + .auth + .entry(defaults.default.clone()) + .or_insert_with(|| defaults.auth[&defaults.default].clone()); } for (site, origin) in &mut config.sites { if let Ok(value) = std::env::var(format!("POLIS_URL_{}", site.to_ascii_uppercase())) { *origin = polis_client::base_url(&value)?.to_string(); } } - Ok(config) + Ok(self) } pub fn url(&self, site: &str) -> Result<&str> { diff --git a/polis-cli/crates/polis/src/sites.rs b/polis-cli/crates/polis/src/sites.rs new file mode 100644 index 000000000..41a74832d --- /dev/null +++ b/polis-cli/crates/polis/src/sites.rs @@ -0,0 +1,279 @@ +use crate::profiles::{self, AuthConfig, Config}; +use clap::ArgMatches; +use polis_contracts::{Error, Result}; +use serde_json::{json, Value}; +use std::{ + fs::{File, OpenOptions}, + io::{Read, Write}, + os::{ + fd::AsRawFd, + unix::fs::{DirBuilderExt, MetadataExt, OpenOptionsExt}, + }, + path::Path, +}; + +fn unsafe_config() -> Error { + Error::input("Cannot safely update site configuration. Use an owned directory without group/other write access and a regular, owned profiles.json file; no symlinks or hard links.") +} + +fn check_file(file: &File) -> Result<()> { + let m = file.metadata().map_err(|_| unsafe_config())?; + if !m.is_file() + || m.uid() != unsafe { libc::geteuid() } + || m.nlink() != 1 + || m.mode() & 0o022 != 0 + { + return Err(unsafe_config()); + } + Ok(()) +} + +fn saved(path: &Path) -> Result { + let file = match OpenOptions::new() + .read(true) + .custom_flags(libc::O_NOFOLLOW | libc::O_NONBLOCK) + .open(path) + { + Ok(file) => file, + Err(e) if e.kind() == std::io::ErrorKind::NotFound => { + return Ok(serde_json::to_value(Config::default()).unwrap()) + } + Err(_) => return Err(unsafe_config()), + }; + check_file(&file)?; + let mut bytes = Vec::new(); + file.take(1024 * 1024 + 1) + .read_to_end(&mut bytes) + .map_err(|_| unsafe_config())?; + if bytes.len() > 1024 * 1024 { + return Err(Error::input("Site configuration exceeds 1 MiB.")); + } + serde_json::from_slice(&bytes) + .map_err(|_| Error::input("Invalid profiles.json. Correct the file before continuing.")) +} + +fn configuration_lock(path: &Path) -> Result { + let dir = path.parent().unwrap(); + std::fs::DirBuilder::new() + .recursive(true) + .mode(0o700) + .create(dir) + .map_err(|_| unsafe_config())?; + let m = std::fs::symlink_metadata(dir).map_err(|_| unsafe_config())?; + if !m.is_dir() || m.uid() != unsafe { libc::geteuid() } || m.mode() & 0o022 != 0 { + return Err(unsafe_config()); + } + let lock = OpenOptions::new() + .read(true) + .write(true) + .create(true) + .truncate(false) + .mode(0o600) + .custom_flags(libc::O_NOFOLLOW | libc::O_NONBLOCK) + .open(dir.join("profiles.lock")) + .map_err(|_| unsafe_config())?; + check_file(&lock)?; + if unsafe { libc::flock(lock.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) } != 0 { + return Err(Error::input( + "Another polis command is updating sites. Retry after it finishes.", + )); + } + Ok(lock) +} + +fn auth(m: &ArgMatches) -> Result { + let defaults = Config::default(); + let mut a = AuthConfig { + callback_port: defaults.auth[&defaults.default].callback_port, + ..AuthConfig::default() + }; + for (key, field) in [ + ("issuer", &mut a.issuer), + ("client-id", &mut a.client_id), + ("audience", &mut a.audience), + ] { + if let Some(value) = m.get_one::(key) { + if value.is_empty() || value.len() > 2048 || value.chars().any(char::is_control) { + return Err(Error::input( + "Authentication settings must be nonempty printable text, at most 2048 bytes.", + )); + } + *field = value.clone(); + } + } + if let Some(port) = m.get_one::("callback-port") { + a.callback_port = *port; + } + if !a.issuer.is_empty() { + let u = url::Url::parse(&a.issuer).map_err(|_| Error::input("Invalid issuer URL."))?; + let local = matches!(u.host_str(), Some("localhost" | "127.0.0.1" | "[::1]")); + if !(u.scheme() == "https" || (u.scheme() == "http" && local)) + || u.host_str().is_none() + || !u.username().is_empty() + || u.password().is_some() + || u.query().is_some() + || u.fragment().is_some() + { + return Err(Error::input("Issuer must use HTTPS (HTTP only on loopback), without credentials, query or fragment.")); + } + } + Ok(a) +} + +pub fn load(selected: Option<&str>) -> Result { + let config: Config = serde_json::from_value(saved(&profiles::path()?)?) + .map_err(|_| Error::input("Invalid profiles.json. Correct the file before continuing."))?; + config.with_overrides(selected) +} + +pub fn execute(path: &str, m: &ArgMatches, effective: &Config, selected: &str) -> Result { + if path == "site list" { + let stored: Config = serde_json::from_value(saved(&profiles::path()?)?).map_err(|_| { + Error::input("Invalid profiles.json. Correct the file before continuing.") + })?; + for (name, origin) in &effective.sites { + profiles::name(name)?; + if !origin.is_empty() { + polis_client::base_url(origin)?; + } + } + let rows: Vec = effective + .sites + .iter() + .map(|(name, origin)| { + json!({ + "name":name, "url":origin, "selected":name == selected, + "saved_default":name == &stored.default, + }) + }) + .collect(); + return Ok(json!({"sites":rows,"selected":selected,"saved_default":stored.default})); + } + let requested = m.get_one::("name").unwrap(); + profiles::name(requested)?; + let defaults = Config::default(); + if requested == "default" && path != "site use" { + return Err(Error::input( + "The name default is reserved for pol.is. Use site use default to return to it.", + )); + } + let name = if requested == "default" { + &defaults.default + } else { + requested + }; + // Validate all supplied values before creating directories or opening a lock. + let added = if path == "site add" { + let origin = polis_client::base_url(m.get_one::("url").unwrap())?.to_string(); + Some((origin, auth(m)?)) + } else { + None + }; + let file = profiles::path()?; + let _lock = configuration_lock(&file)?; + let mut raw = saved(&file)?; + let mut config: Config = serde_json::from_value(raw.clone()) + .map_err(|_| Error::input("Invalid profiles.json. Correct the file before continuing."))?; + let defaults = Config::default(); + let builtin = &defaults.default; + match path { + "site add" => { + if config.sites.contains_key(name) || name == builtin { + return Err(Error::input("Site name already exists. Choose another name; existing sign-in settings are never overwritten.")); + } + let (origin, auth) = added.unwrap(); + config.sites.insert(name.clone(), origin); + config.auth.insert(name.clone(), auth); + } + "site use" => { + if name == builtin && !config.sites.contains_key(builtin) { + config + .sites + .entry(builtin.clone()) + .or_insert_with(|| defaults.sites[builtin].clone()); + config + .auth + .entry(builtin.clone()) + .or_insert_with(|| defaults.auth[builtin].clone()); + } + config.url(name)?; + config.default = name.clone(); + } + "site remove" => { + if name == builtin { + return Err(Error::input("The built-in pol.is site cannot be removed.")); + } + if config.sites.remove(name).is_none() { + return Err(Error::input("Unknown site name.")); + } + config.auth.remove(name); + if config.default == *name { + config.default = builtin.clone(); + config + .sites + .entry(builtin.clone()) + .or_insert_with(|| defaults.sites[builtin].clone()); + config + .auth + .entry(builtin.clone()) + .or_insert_with(|| defaults.auth[builtin].clone()); + } + } + _ => unreachable!(), + } + // Preserve extension keys and never persist environment overrides. + raw["default"] = json!(config.default); + raw["sites"] = json!(config.sites); + let mut stored_auth = raw.get("auth").cloned().unwrap_or_else(|| json!({})); + if !stored_auth.is_object() { + return Err(Error::input("Invalid auth settings in profiles.json.")); + } + if path == "site add" { + stored_auth[name] = json!(config.auth[name]); + } + if path == "site remove" { + stored_auth.as_object_mut().unwrap().remove(name); + if stored_auth.get(builtin).is_none() { + if let Some(a) = config.auth.get(builtin) { + stored_auth[builtin] = json!(a); + } + } + } + if path == "site use" && name == builtin && stored_auth.get(builtin).is_none() { + if let Some(auth) = config.auth.get(builtin) { + stored_auth[builtin] = json!(auth); + } + } + raw["auth"] = stored_auth; + let bytes = serde_json::to_vec_pretty(&raw).unwrap(); + if bytes.len() > 1024 * 1024 { + return Err(Error::input("Site configuration exceeds 1 MiB.")); + } + let mut temp = + tempfile::NamedTempFile::new_in(file.parent().unwrap()).map_err(|_| unsafe_config())?; + temp.write_all(&bytes).map_err(|_| unsafe_config())?; + temp.as_file().sync_all().map_err(|_| unsafe_config())?; + temp.persist(&file).map_err(|_| unsafe_config())?; + Ok( + json!({"name":name,"saved_default":config.default,"state":match path {"site add"=>"added","site use"=>"selected",_=>"removed"}, + "note":"Site configuration only. Sign-ins are scoped to site name and origin. Removing an alias does not revoke or delete its sign-in; log out before removal if needed. POLIS_SITE and --site override the saved default."}), + ) +} + +/// Human context goes to stderr so raw tokens, exports and JSON stay pipeable. +pub fn print_header(config: &Config, site: &str) { + // The shipped default origin comes from defaults.json, not a literal. + let defaults = Config::default(); + let shipped = polis_client::base_url(&defaults.sites[&defaults.default]) + .map(|u| u.origin().ascii_serialization()) + .ok(); + match config.url(site).and_then(polis_client::base_url) { + Ok(url) => { + let origin = url.origin().ascii_serialization(); + if shipped.as_deref() != Some(origin.as_str()) { + eprintln!("Site: {site} ({origin})"); + } + } + Err(_) => eprintln!("Site: {site}"), + } +} diff --git a/polis-cli/crates/polis/tests/cli.rs b/polis-cli/crates/polis/tests/cli.rs index ab2dc155b..cebc3c725 100644 --- a/polis-cli/crates/polis/tests/cli.rs +++ b/polis-cli/crates/polis/tests/cli.rs @@ -124,10 +124,9 @@ fn list_prints_a_table_with_the_newest_report_of_each_conversation() { &["conversation", "list"], ); assert!(o.status.success()); - assert!( - o.stderr.is_empty(), - "{}", - String::from_utf8_lossy(&o.stderr) + assert_eq!( + String::from_utf8_lossy(&o.stderr), + format!("Site: local ({origin})\n") ); assert!(requests[0].starts_with("GET /api/v3/conversations?limit=100 ")); assert!( @@ -182,9 +181,11 @@ fn list_table_survives_a_failed_or_missing_reports_read() { assert!(stdout.contains(&format!(" {origin}/def\n")), "{stdout}"); assert!(!stdout.contains("/report/")); let stderr = String::from_utf8_lossy(&o.stderr); - assert_eq!(stderr.lines().count(), 1, "{stderr}"); + let header = format!("Site: local ({origin})\n"); + let warning = stderr.strip_prefix(&header).expect("effective site header"); + assert_eq!(warning.lines().count(), 1, "{stderr}"); assert!( - stderr.starts_with("polis: report links unavailable"), + warning.starts_with("polis: report links unavailable"), "{stderr}" ); assert!(!stderr.contains("polis_err_permissions") && !stderr.contains("old server")); @@ -219,14 +220,17 @@ fn list_table_cleans_and_truncates_text_but_never_links() { } #[test] fn list_without_conversations_reads_no_reports() { - let (o, requests, _) = sequence( + let (o, requests, origin) = sequence( &[(200, "application/json", "[]")], &["conversation", "list", "--search", "nothing"], ); assert!(o.status.success()); assert_eq!(requests.len(), 1); assert_eq!(text(&o), "No conversations.\n"); - assert!(o.stderr.is_empty()); + assert_eq!( + String::from_utf8_lossy(&o.stderr), + format!("Site: local ({origin})\n") + ); } #[test] fn list_json_envelope_is_unchanged_by_the_table() { @@ -261,7 +265,7 @@ fn all_help_and_schema_commands_are_reachable() { let out = run(tmp, &args); assert!(out.status.success(), "{path}"); assert_eq!(parsed(&out)["ok"], true); - assert!(!String::from_utf8_lossy(&out.stdout).contains("--site")); + assert!(String::from_utf8_lossy(&out.stdout).contains("--site")); *count += 1; for child in v["commands"].as_array().unwrap() { walk(child, tmp, count); @@ -612,31 +616,49 @@ fn profiles_preserve_configuration_and_require_origins() { assert_eq!(parsed(&o)["error"]["code"], "site_unconfigured"); } #[test] -fn site_selection_is_not_a_command_or_option() { +fn site_selection_is_discoverable_in_commands_options_and_completions() { let t = tempfile::tempdir().unwrap(); let schema = parsed(&run(t.path(), &["schema"])); - assert!(!schema["data"]["commands"] + let sites = schema["data"]["commands"] .as_array() .unwrap() .iter() - .any(|v| v["command"] == "polis site")); + .find(|v| v["command"] == "polis site") + .unwrap(); + for name in ["list", "add", "use", "remove"] { + assert!(sites["commands"] + .as_array() + .unwrap() + .iter() + .any(|v| v["command"] == format!("polis site {name}") && v["implemented"] == true)); + } for args in [ - vec!["auth", "login", "--site", "prod", "--json"], - vec!["site", "use", "prod", "--json"], + vec!["--site", "prod", "site", "list", "--json"], + vec!["site", "list", "--site", "prod", "--json"], ] { let o = run(t.path(), &args); - assert_eq!(o.status.code(), Some(2)); - assert_eq!(parsed(&o)["error"]["code"], "invalid_input"); + assert_eq!(o.status.code(), Some(0)); + assert_eq!(parsed(&o)["data"]["selected"], "prod"); } - let plain = run(t.path(), &["auth", "login", "--site", "prod"]); - assert_eq!(plain.status.code(), Some(2)); - assert!(!String::from_utf8_lossy(&plain.stderr).contains("--site")); + let unknown = run(t.path(), &["site", "list", "--site", "missing", "--json"]); + assert_eq!(unknown.status.code(), Some(2)); + assert_eq!(parsed(&unknown)["error"]["code"], "site_unconfigured"); for shell in ["bash", "zsh", "fish", "powershell", "elvish"] { let o = run(t.path(), &["completion", shell]); assert!(o.status.success()); - assert!(!String::from_utf8_lossy(&o.stdout).contains("--site")); + let declaration = if shell == "fish" { + " -l site " + } else { + "--site" + }; + assert!( + String::from_utf8_lossy(&o.stdout).contains(declaration), + "{shell}" + ); } + assert_eq!(std::fs::read_dir(t.path()).unwrap().count(), 0); } + #[test] fn different_site_does_not_reuse_local_token() { let t = tempfile::tempdir().unwrap(); diff --git a/polis-cli/crates/polis/tests/invites.rs b/polis-cli/crates/polis/tests/invites.rs index f8d344609..95b67a1c6 100644 --- a/polis-cli/crates/polis/tests/invites.rs +++ b/polis-cli/crates/polis/tests/invites.rs @@ -544,7 +544,16 @@ fn uuid_is_raw_only_when_explicitly_requested_and_errors_never_echo_key() { .unwrap(); assert!(out.status.success()); assert_eq!(out.stdout, format!("{key}\n").as_bytes()); - assert!(out.stderr.is_empty()); + let config: Value = + serde_json::from_slice(&std::fs::read(t.path().join("profiles.json")).unwrap()).unwrap(); + assert_eq!( + String::from_utf8_lossy(&out.stderr), + format!( + "Site: local ({})\n", + config["sites"]["local"].as_str().unwrap() + ) + ); + assert!(!String::from_utf8_lossy(&out.stderr).contains(key)); assert_get( &s.join().unwrap()[0], "/api/v3/conversationUuid?conversation_id=2demo", diff --git a/polis-cli/crates/polis/tests/sites.rs b/polis-cli/crates/polis/tests/sites.rs new file mode 100644 index 000000000..55e3fdbb7 --- /dev/null +++ b/polis-cli/crates/polis/tests/sites.rs @@ -0,0 +1,589 @@ +use serde_json::{json, Value}; +use std::{ + io::{Read, Write}, + net::TcpListener, + path::Path, + process::{Command, Stdio}, +}; + +fn call(dir: &Path, args: &[&str], env: &[(&str, &str)], input: Option<&str>) -> (i32, Value) { + let mut c = Command::new(env!("CARGO_BIN_EXE_polis")); + for (key, _) in std::env::vars_os() { + if key.to_string_lossy().starts_with("POLIS_") { + c.env_remove(key); + } + } + c.env("POLIS_CONFIG_DIR", dir) + .env("POLIS_KEYCHAIN", "off") + .envs(env.iter().copied()) + .args(args) + .args(["--json", "--no-interactive"]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + let mut child = c.spawn().unwrap(); + if let Some(input) = input { + child + .stdin + .take() + .unwrap() + .write_all(input.as_bytes()) + .unwrap(); + } + let out = child.wait_with_output().unwrap(); + let text = String::from_utf8(out.stdout).unwrap(); + assert!(!text.contains("fixture-secret")); + ( + out.status.code().unwrap(), + serde_json::from_str(&text).unwrap_or_else(|_| panic!("{text}")), + ) +} +fn ok(dir: &Path, args: &[&str]) -> Value { + let (code, v) = call(dir, args, &[], None); + assert_eq!(code, 0, "{v}"); + v["data"].clone() +} +fn stored(dir: &Path) -> Value { + serde_json::from_slice(&std::fs::read(dir.join("profiles.json")).unwrap()).unwrap() +} + +#[test] +fn fresh_install_lists_pol_is_without_creating_configuration_or_credentials() { + let t = tempfile::tempdir().unwrap(); + let v = ok(t.path(), &["site", "list"]); + assert_eq!(v["selected"], "prod"); + assert!(v["sites"] + .as_array() + .unwrap() + .iter() + .any(|r| r["name"] == "prod" && r["url"] == "https://pol.is")); + assert_eq!(std::fs::read_dir(t.path()).unwrap().count(), 0); +} + +#[test] +fn add_use_remove_and_auth_settings_preserve_default_and_private_file() { + use std::os::unix::fs::PermissionsExt; + let t = tempfile::tempdir().unwrap(); + ok( + t.path(), + &[ + "site", + "add", + "eu", + "https://eu.example.org", + "--issuer", + "https://login.example.org/tenant/", + "--client-id", + "public-client", + "--audience", + "users", + ], + ); + let v = stored(t.path()); + assert_eq!(v["default"], "prod"); + assert_eq!(v["sites"]["eu"], "https://eu.example.org/"); + assert_eq!( + v["auth"]["eu"]["issuer"], + "https://login.example.org/tenant/" + ); + assert_eq!(v["auth"]["eu"]["client_id"], "public-client"); + assert_eq!( + std::fs::metadata(t.path().join("profiles.json")) + .unwrap() + .permissions() + .mode() + & 0o777, + 0o600 + ); + ok(t.path(), &["site", "use", "eu"]); + assert_eq!(ok(t.path(), &["site", "list"])["selected"], "eu"); + ok(t.path(), &["site", "remove", "eu"]); + assert_eq!(stored(t.path())["default"], "prod"); + assert!(stored(t.path())["sites"].get("eu").is_none()); + assert!(stored(t.path())["auth"].get("eu").is_none()); + assert!(!t.path().join("credentials").exists()); +} + +#[test] +fn cli_site_wins_over_environment_and_environment_is_not_persisted() { + let t = tempfile::tempdir().unwrap(); + ok(t.path(), &["site", "add", "eu", "https://eu.example.org"]); + let env = [ + ("POLIS_SITE", "eu"), + ("POLIS_URL_EU", "https://override.example.org"), + ( + "POLIS_AUTH_ISSUER_EU", + "https://override-login.example.org/", + ), + ]; + let (code, v) = call(t.path(), &["site", "use", "local"], &env, None); + assert_eq!(code, 0, "{v}"); + assert_eq!(stored(t.path())["default"], "local"); + assert_eq!(stored(t.path())["sites"]["eu"], "https://eu.example.org/"); + assert_eq!(stored(t.path())["auth"]["eu"]["issuer"], ""); + assert_eq!( + call(t.path(), &["site", "list"], &env, None).1["data"]["selected"], + "eu" + ); + for args in [ + vec!["--site", "prod", "site", "list"], + vec!["site", "list", "--site", "prod"], + ] { + let (code, v) = call(t.path(), &args, &env, None); + assert_eq!(code, 0, "{v}"); + assert_eq!(v["data"]["selected"], "prod"); + } + assert_eq!( + call( + t.path(), + &["site", "list", "--site", "prod"], + &[("POLIS_SITE", "INVALID!")], + None + ) + .0, + 0 + ); +} + +#[test] +fn invalid_additions_do_not_write_configuration() { + for args in [ + vec!["site", "add", "BAD", "https://example.org"], + vec!["site", "add", "eu", "http://example.org"], + vec![ + "site", + "add", + "eu", + "https://user:fixture-secret@example.org", + ], + vec!["site", "add", "eu", "https://example.org/path"], + vec!["site", "add", "eu", "https://example.org/?x=1"], + vec!["site", "add", "eu", "https://example.org/#x"], + vec![ + "site", + "add", + "eu", + "https://example.org", + "--issuer", + "http://issuer.example.org", + "--client-id", + "client", + ], + vec![ + "site", + "add", + "eu", + "https://example.org", + "--issuer", + "https://issuer.example.org/", + ], + ] { + let t = tempfile::tempdir().unwrap(); + assert_eq!(call(t.path(), &args, &[], None).0, 2, "{args:?}"); + assert_eq!(std::fs::read_dir(t.path()).unwrap().count(), 0); + } +} + +#[test] +fn duplicates_unknown_sites_and_removing_prod_fail_without_changing_config() { + let t = tempfile::tempdir().unwrap(); + ok(t.path(), &["site", "add", "dev", "http://127.0.0.1:5000"]); + let before = std::fs::read(t.path().join("profiles.json")).unwrap(); + for args in [ + vec!["site", "add", "dev", "https://different.example.org"], + vec!["site", "remove", "prod"], + vec!["site", "remove", "missing"], + vec!["site", "use", "missing"], + vec!["site", "use", "preprod"], + ] { + assert_eq!(call(t.path(), &args, &[], None).0, 2, "{args:?}"); + assert_eq!( + std::fs::read(t.path().join("profiles.json")).unwrap(), + before + ); + } +} + +#[test] +fn updates_preserve_unknown_config_and_auth_fields() { + let t = tempfile::tempdir().unwrap(); + std::fs::write(t.path().join("profiles.json"), json!({"default":"custom","sites":{"custom":"https://example.org"},"future":{"opaque":true},"auth":{"custom":{"issuer":"","future_auth":5}}}).to_string()).unwrap(); + ok(t.path(), &["site", "add", "eu", "https://eu.example.org"]); + ok(t.path(), &["site", "remove", "custom"]); + let v = stored(t.path()); + assert_eq!(v["future"]["opaque"], true); + assert_eq!(v["default"], "prod"); + assert_eq!(v["sites"]["prod"], "https://pol.is"); + assert!(v["auth"]["prod"]["client_id"].is_string()); + ok( + t.path(), + &["site", "add", "other", "https://other.example.org"], + ); + let mut v = stored(t.path()); + v["auth"]["other"]["future_auth"] = json!(5); + std::fs::write(t.path().join("profiles.json"), v.to_string()).unwrap(); + ok(t.path(), &["site", "use", "eu"]); + assert_eq!(stored(t.path())["auth"]["other"]["future_auth"], 5); +} + +#[test] +fn symlinks_hardlinks_and_shared_write_permissions_are_refused() { + use std::os::unix::fs::{symlink, PermissionsExt}; + for kind in ["symlink", "hardlink", "writable"] { + let t = tempfile::tempdir().unwrap(); + let original = t.path().join("original.json"); + let bytes = json!({"default":"prod","sites":{"prod":"https://pol.is"}}).to_string(); + std::fs::write(&original, &bytes).unwrap(); + let config = t.path().join("profiles.json"); + match kind { + "symlink" => symlink(&original, &config).unwrap(), + "hardlink" => std::fs::hard_link(&original, &config).unwrap(), + _ => { + std::fs::copy(&original, &config).unwrap(); + std::fs::set_permissions(&config, std::fs::Permissions::from_mode(0o666)).unwrap(); + } + } + assert_eq!( + call( + t.path(), + &["site", "add", "eu", "https://eu.example.org"], + &[], + None + ) + .0, + 2 + ); + assert_eq!(std::fs::read_to_string(&original).unwrap(), bytes); + assert_eq!(std::fs::read_to_string(&config).unwrap(), bytes); + } +} + +#[test] +fn site_commands_do_not_read_credential_store() { + let t = tempfile::tempdir().unwrap(); + std::fs::write(t.path().join("credentials"), "unreadable-as-a-directory").unwrap(); + ok(t.path(), &["site", "add", "eu", "https://eu.example.org"]); + ok(t.path(), &["site", "use", "eu"]); + ok(t.path(), &["site", "list"]); + ok(t.path(), &["site", "remove", "eu"]); +} + +#[test] +fn listing_rejects_credential_bearing_urls_without_echoing_them() { + let t = tempfile::tempdir().unwrap(); + std::fs::write(t.path().join("profiles.json"), json!({ + "default":"prod", "sites":{"prod":"https://pol.is","unsafe":"https://user:fixture-secret@example.org"} + }).to_string()).unwrap(); + assert_eq!(call(t.path(), &["site", "list"], &[], None).0, 2); +} + +#[test] +fn concurrent_configuration_writer_is_refused_without_lost_updates() { + use std::os::fd::AsRawFd; + let t = tempfile::tempdir().unwrap(); + ok(t.path(), &["site", "add", "one", "https://one.example.org"]); + let before = std::fs::read(t.path().join("profiles.json")).unwrap(); + let lock = std::fs::File::open(t.path().join("profiles.lock")).unwrap(); + assert_eq!( + unsafe { libc::flock(lock.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) }, + 0 + ); + let (code, v) = call( + t.path(), + &["site", "add", "two", "https://two.example.org"], + &[], + None, + ); + assert_eq!(code, 2, "{v}"); + assert!(v["error"]["message"] + .as_str() + .unwrap() + .contains("Another polis command")); + assert_eq!( + std::fs::read(t.path().join("profiles.json")).unwrap(), + before + ); + drop(lock); + ok(t.path(), &["site", "add", "two", "https://two.example.org"]); + assert_eq!(stored(t.path())["sites"]["one"], "https://one.example.org/"); + assert_eq!(stored(t.path())["sites"]["two"], "https://two.example.org/"); +} + +#[test] +fn account_signins_are_separate_even_for_aliases_on_the_same_origin() { + let t = tempfile::tempdir().unwrap(); + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + listener.set_nonblocking(true).unwrap(); + let origin = format!("http://{}", listener.local_addr().unwrap()); + let server = std::thread::spawn(move || { + let mut requests = Vec::new(); + for _ in 0..4 { + let start = std::time::Instant::now(); + let mut socket = loop { + match listener.accept() { + Ok((s, _)) => break s, + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { + assert!(start.elapsed().as_secs() < 10); + std::thread::sleep(std::time::Duration::from_millis(5)); + } + Err(e) => panic!("{e}"), + } + }; + socket + .set_read_timeout(Some(std::time::Duration::from_secs(5))) + .unwrap(); + let mut bytes = Vec::new(); + while !bytes.windows(4).any(|w| w == b"\r\n\r\n") { + let mut buf = [0; 1024]; + let n = socket.read(&mut buf).unwrap(); + assert!(n > 0); + bytes.extend_from_slice(&buf[..n]); + } + requests.push(String::from_utf8(bytes).unwrap()); + socket.write_all(b"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 2\r\nConnection: close\r\n\r\n{}").unwrap(); + } + requests + }); + for name in ["one", "two"] { + ok(t.path(), &["site", "add", name, &origin]); + } + assert_eq!( + call( + t.path(), + &["--site", "one", "auth", "login", "--with-token"], + &[], + Some("fixture-secret-one\n") + ) + .0, + 0 + ); + assert_eq!( + call(t.path(), &["--site", "two", "auth", "status"], &[], None).0, + 3 + ); + assert_eq!( + call( + t.path(), + &["--site", "one", "auth", "status"], + &[("POLIS_URL_ONE", "http://127.0.0.1:1")], + None + ) + .0, + 3 + ); + assert_eq!( + call( + t.path(), + &["--site", "two", "auth", "login", "--with-token"], + &[], + Some("fixture-secret-two\n") + ) + .0, + 0 + ); + ok(t.path(), &["--site", "one", "auth", "status"]); + ok(t.path(), &["--site", "two", "auth", "status"]); + let requests = server.join().unwrap(); + for (r, token) in requests.iter().zip(["one", "two", "one", "two"]) { + assert!(r + .to_ascii_lowercase() + .contains(&format!("authorization: bearer fixture-secret-{token}"))); + } + // Removing configuration neither reads nor changes the credentials. + let credentials: Vec<_> = std::fs::read_dir(t.path().join("credentials")) + .unwrap() + .map(|p| { + let p = p.unwrap().path(); + (p.clone(), std::fs::read(p).unwrap()) + }) + .collect(); + ok(t.path(), &["site", "remove", "one"]); + for (p, bytes) in credentials { + assert_eq!(std::fs::read(p).unwrap(), bytes); + } +} + +#[test] +fn default_reset_and_one_command_override_preserve_aliases() { + let t = tempfile::tempdir().unwrap(); + ok(t.path(), &["site", "add", "eu", "https://eu.example.org"]); + ok(t.path(), &["site", "use", "eu"]); + assert_eq!(ok(t.path(), &["site", "list"])["selected"], "eu"); + assert_eq!( + ok(t.path(), &["--site", "default", "site", "list"])["selected"], + "prod" + ); + assert_eq!(stored(t.path())["default"], "eu"); + ok(t.path(), &["site", "use", "default"]); + assert_eq!(stored(t.path())["default"], "prod"); + assert_eq!(ok(t.path(), &["site", "list"])["selected"], "prod"); + assert_eq!(stored(t.path())["sites"]["eu"], "https://eu.example.org/"); + assert!(!t.path().join("credentials").exists()); + for args in [ + vec!["site", "add", "default", "https://example.org"], + vec!["site", "remove", "default"], + ] { + assert_eq!(call(t.path(), &args, &[], None).0, 2); + } +} + +#[test] +fn default_reset_restores_missing_builtin_profile() { + let t = tempfile::tempdir().unwrap(); + std::fs::write( + t.path().join("profiles.json"), + json!({"default":"custom","sites":{"custom":"https://example.org"}}).to_string(), + ) + .unwrap(); + ok(t.path(), &["site", "use", "default"]); + assert_eq!( + ok(t.path(), &["conversation", "share", "2p027generated"])["participation_url"], + "https://pol.is/2p027generated" + ); + assert!(stored(t.path())["auth"]["prod"]["client_id"].is_string()); +} + +#[test] +fn callback_port_is_persisted_and_invalid_values_never_write() { + let t = tempfile::tempdir().unwrap(); + ok( + t.path(), + &[ + "site", + "add", + "eu", + "https://eu.example.org", + "--issuer", + "https://login.example.org/", + "--client-id", + "native-client", + "--callback-port", + "54321", + ], + ); + assert_eq!(stored(t.path())["auth"]["eu"]["callback_port"], 54321); + for port in ["0", "65536", "-1", "not-a-port"] { + let t = tempfile::tempdir().unwrap(); + assert_eq!( + call( + t.path(), + &[ + "site", + "add", + "eu", + "https://eu.example.org", + "--issuer", + "https://login.example.org/", + "--client-id", + "native-client", + "--callback-port", + port + ], + &[], + None + ) + .0, + 2 + ); + assert_eq!(std::fs::read_dir(t.path()).unwrap().count(), 0); + } +} + +fn human(dir: &Path, args: &[&str], env: &[(&str, &str)]) -> std::process::Output { + let mut c = Command::new(env!("CARGO_BIN_EXE_polis")); + for (key, _) in std::env::vars_os() { + if key.to_string_lossy().starts_with("POLIS_") { + c.env_remove(key); + } + } + c.env("POLIS_CONFIG_DIR", dir) + .env("POLIS_KEYCHAIN", "off") + .envs(env.iter().copied()) + .args(args) + .arg("--no-interactive") + .output() + .unwrap() +} + +#[test] +fn human_headers_identify_effective_origin_and_json_stays_clean() { + let t = tempfile::tempdir().unwrap(); + ok(t.path(), &["site", "add", "eu", "https://eu.example.org"]); + let args = ["--site", "eu", "conversation", "share", "2p027generated"]; + let out = human(t.path(), &args, &[]); + assert!(out.status.success()); + assert!(String::from_utf8_lossy(&out.stderr).starts_with("Site: eu (https://eu.example.org)\n")); + let value: Value = serde_json::from_slice(&out.stdout).unwrap(); + assert_eq!( + value["participation_url"], + "https://eu.example.org/2p027generated" + ); + let out = human( + t.path(), + &[ + "--site", + "eu", + "conversation", + "share", + "2p027generated", + "--json", + ], + &[], + ); + assert!(out.status.success()); + assert!(out.stderr.is_empty()); + assert_eq!( + serde_json::from_slice::(&out.stdout).unwrap()["site"], + "eu" + ); + let out = human(t.path(), &["conversation", "share", "2p027generated"], &[]); + assert!(out.stderr.is_empty()); + let out = human( + t.path(), + &["conversation", "share", "2p027generated"], + &[("POLIS_URL_PROD", "http://127.0.0.1:5000")], + ); + assert!( + String::from_utf8_lossy(&out.stderr).starts_with("Site: prod (http://127.0.0.1:5000)\n") + ); + let out = human(t.path(), &["site", "use", "eu"], &[]); + assert!(String::from_utf8_lossy(&out.stderr).starts_with("Site: eu (https://eu.example.org)\n")); + let out = human(t.path(), &["site", "use", "default"], &[]); + assert!(out.status.success()); + assert!(out.stderr.is_empty()); +} + +#[test] +fn site_headers_cover_errors_but_do_not_change_offline_discovery() { + let t = tempfile::tempdir().unwrap(); + ok(t.path(), &["site", "add", "eu", "https://eu.example.org"]); + ok(t.path(), &["site", "use", "eu"]); + let out = human( + t.path(), + &["comment", "stats", "--conversation", "invalid/id"], + &[], + ); + assert_eq!(out.status.code(), Some(2)); + assert!(String::from_utf8_lossy(&out.stderr).starts_with("Site: eu (https://eu.example.org)\n")); + for args in [vec!["help"], vec!["questions"], vec!["completion", "bash"]] { + let out = human(t.path(), &args, &[]); + assert!(out.status.success()); + assert!(out.stderr.is_empty()); + } +} + +#[test] +fn headers_use_a_normalized_origin_without_terminal_controls() { + let t = tempfile::tempdir().unwrap(); + std::fs::write( + t.path().join("profiles.json"), + json!({"default":"custom","sites":{"custom":"\nhttps://example.org\t"}}).to_string(), + ) + .unwrap(); + let out = human(t.path(), &["conversation", "share", "2p027generated"], &[]); + assert!(out.status.success()); + assert_eq!( + String::from_utf8_lossy(&out.stderr), + "Site: custom (https://example.org)\n" + ); +} diff --git a/polis-cli/docs/development.md b/polis-cli/docs/development.md index 5dbde4dce..3789848fc 100644 --- a/polis-cli/docs/development.md +++ b/polis-cli/docs/development.md @@ -6,7 +6,8 @@ public issuer, native client ID, audience and registered callback port. The callback uses HTTP on 127.0.0.1 at that port and the fixed `/oauth/callback` path. These public registration values are configuration, not secrets. -For development or tests, select a profile with `POLIS_SITE=local` or +For saved aliases, use `polis site add/use/list/remove` and `--site NAME`; see +the README Sites section. For development or tests, select a profile with `POLIS_SITE=local` or `POLIS_SITE=preprod`. The latter needs an origin. Environment settings override configuration for the matching profile: @@ -29,9 +30,11 @@ provider registrations must use their registered port. Alternatively put a complete `profiles.json` in `~/.config/polis/`, or set `POLIS_CONFIG_DIR` to an isolated directory. `profiles.example.json` shows the -format. Existing files remain complete overrides, including their `default`; -upgrading does not rewrite them, move credentials or change their selected server. -`POLIS_SITE` takes precedence over that default without writing the file. Unknown +format. Existing files retain their saved default and settings. The built-in +pol.is profile is available when absent, so `--site default` can select it; +`site use default` saves that choice. Existing profile origins and auth settings +are preserved. Loading configuration does not rewrite files or move credentials. +`--site NAME` takes precedence over `POLIS_SITE`, which takes precedence over that default without writing the file. Unknown or unconfigured profiles fail rather than falling back to production. Origins and auth overrides apply on fresh installs too. Custom names must first exist in the configuration's `sites` map. Auth entries that omit the callback port retain the shipped default port; use diff --git a/polis-cli/tests/differential/cases.py b/polis-cli/tests/differential/cases.py index 981d18545..7333d90ae 100644 --- a/polis-cli/tests/differential/cases.py +++ b/polis-cli/tests/differential/cases.py @@ -18,6 +18,10 @@ def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): add('account view');add('plan view') add('conversation list');add('conversation view',[C]);add('conversation stats',[C]) add('math view',['--conversation',C]) + add('site list',scope='local') + add('site add',['example','https://example.invalid'],scope='local') + add('site use',['local'],scope='local') + add('site remove',['example'],scope='local') # Successful statistics/optional importance are covered by generated HTTP tests. add('comment stats',['--conversation','invalid/id'],exit=2,scope='invalid-input') add('api',['/api/v3/users']) From 050dd04e7e6d9154e259a8addaa1e2229a768489 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Mon, 19 Oct 2026 22:07:52 -0700 Subject: [PATCH 09/30] cli: raw data out of every read, as JSON and as CSV where tabular (#3237) CLI only. Every command has --json; the 77 tabular reads gain --csv (RFC 4180 quoting and line endings, a header row, byte-stable for the same response). No output gains an identity field a route does not return; participant-visible reads carry no xid; owner and moderator outputs keep xid where the route gives it. The README shows an organizer joining their own member list to the votes export on xid. Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- polis-cli/README.md | 111 +++++++ polis-cli/crates/polis/src/admin.rs | 7 + polis-cli/crates/polis/src/commands.rs | 4 +- polis-cli/crates/polis/src/main.rs | 32 +- polis-cli/crates/polis/src/raw_output.rs | 180 +++++++++++ polis-cli/crates/polis/tests/raw_output.rs | 346 +++++++++++++++++++++ polis-cli/examples/join-member-votes.py | 69 ++++ polis-cli/tests/raw_data/test_join.py | 69 ++++ scripts/test-polis-cli.sh | 3 + 9 files changed, 819 insertions(+), 2 deletions(-) create mode 100644 polis-cli/crates/polis/src/raw_output.rs create mode 100644 polis-cli/crates/polis/tests/raw_output.rs create mode 100644 polis-cli/examples/join-member-votes.py create mode 100644 polis-cli/tests/raw_data/test_join.py diff --git a/polis-cli/README.md b/polis-cli/README.md index 14fe5f077..15cbe1ec0 100644 --- a/polis-cli/README.md +++ b/polis-cli/README.md @@ -1016,3 +1016,114 @@ ordered question entries (`id`, `question`, `commands`, `look_for`) and rendered help. It works offline without a profile or credentials and runs none of the listed commands. It distinguishes existing reads from comparisons an analyst must make and from the consensus timeline the CLI does not yet provide. + +## Raw data + +Every command accepts `--json`, including reads, help and errors. It keeps the +existing `polis-cli/1` envelope and each command's documented data contract. +Existing route-provided PIDs and authorized XIDs remain unchanged. Locations +have no identity; the CLI does not add one or perform an extra identity lookup. + +Use `--csv` for read-result rows on stdout: + +```sh +polis comment list --conversation CONVERSATION --csv > comments.csv +polis comment stats --conversation CONVERSATION --by-group --csv > stats.csv +polis participant locations --conversation CONVERSATION --group 0 --csv > locations.csv +polis participant xid list --conversation CONVERSATION --csv > xids-list.csv +polis conversation list --csv > conversations.csv +``` + +`polis schema --json` marks supported commands with `csv: true`. `--csv` and +`--json` are mutually exclusive. `topic prioritize` accepts CSV only with `--show`; `api` accepts it only +with the default `--method GET`. CSV is a presentation of the same bounded read; +it adds no fetches, pagination, sorting or identity enrichment. CSV conversation +lists use the JSON read path without the human table's optional report lookup. +Existing limits still apply. Use `--json` to inspect cursors, truncation, scope, +notes and provenance before treating a result as complete. These reads are not +an atomic snapshot. A failed read preserves its exit code, writes its error to +stderr, and emits no CSV rows. Site headers and warnings also stay on stderr. + +CSV refuses more than one million cells or 64 MiB of encoded output before +writing rows. Narrow the read or use JSON for those shapes. + +CSV columns are the sorted union of fields in the returned rows; no text is +truncated. Quoting preserves commas, quotes, Unicode and newlines. Missing +fields are empty cells, explicit null is `null`, and objects/arrays are compact +JSON cells. Scalar or mixed arrays use a single `value` column; an empty array +is a header-only `value` table. A single object is one row. CSV does not preserve +JSON scalar types; use JSON when the distinction between a string such as +`"null"`, an empty string and a missing field matters. Formula-like strings are +preserved as data: import CSV columns as text, not executable spreadsheet formulas. + +For the following commands the CSV rows come from the named data field: + +| Commands | Row field | +| --- | --- | +| `site list` | `sites` | +| `seed csv preview` | `rows` | +| `conversation list` | `conversations` | +| `comment list`, `comment stats`, `report comments list`, `topic comments` | `comments` | +| `participant list` | `participants` (the signed-in account only, not a roster) | +| `vote list` | `votes` | +| `vote mine`, `vote famous` | `data` | +| `invite code list`, `invite list` | `codes`, `invites` respectively | +| `collective list`, `collective statements` | `statements` | +| `topic list`, `report topics` | `topics`, when present; otherwise the complete object | +| `topic proximity` | `proximity_data` | +| `delphi status` | `jobs` | + +Other read results retain their full object or top-level array. Nested structures, +including `bidToPid` group arrays and per-group statistics, remain JSON cells; +empty groups and duplicate points are not removed. Wrapper metadata is available +in `--json`, rather than repeated in every CSV row. File/document exports keep +their existing `--output` and `--format` interfaces; `--json` describes the download +receipt and does not replace the downloaded file. + +### Join an organizer's members to votes + +Use the XID export you are authorized to download for **the same conversation** +as the vote export. The existing votes CSV contains `voter-id` (a PID), not XID. +Join `votes.voter-id` to `xids.pid` first, then `xids.xid` to your member list's +`xid`. PIDs are conversation-local; never reuse a mapping from another conversation +or site. Verify the report belongs to that conversation with `report view`. +Neither CSV includes sufficient context to detect a mistaken cross-conversation +join automatically. + +```sh +polis auth login +polis report view REPORT --json +polis participant xid export --conversation CONVERSATION --output xids.csv +polis report export REPORT --type votes.csv --output votes.csv +polis report export REPORT --type format.json --output format.json +``` + +The XID export requires owner/moderator authority and contains only participants +with XIDs. Anonymous/unmapped votes must remain unmatched. Locations cannot be +joined to members. Public group membership does not provide an XID map. Exports +can be capped; separate reads can observe changes. Check the JSON receipts and +the site's limits before claiming a complete member or voter roster. + +For example, your own `members.csv` might be: + +```csv +xid,member_label +member-north,North district +member-south,South district +``` + +From a source checkout, run the included Python standard-library example: + +```sh +python3 polis-cli/examples/join-member-votes.py \ + --members members.csv --xids xids.csv --votes votes.csv --output member-votes.csv +``` + +This left join keeps every vote row in its original order, including repeated +votes. It appends `xid`, `member_label` and `member_match` (`matched`, `no_member` +or `no_xid`). The output is owner-only on Unix. It preserves string IDs, leading zeroes and every original vote +cell, rejects ambiguous duplicate keys and refuses to overwrite an output file. +Use it only with files you have verified belong together; keep identity-linked +files private. Read `format.json` for the export's vote convention. `vote list` +uses the wire convention documented by its JSON response; changing the output +format performs no sign conversion. The join does not change vote values either. diff --git a/polis-cli/crates/polis/src/admin.rs b/polis-cli/crates/polis/src/admin.rs index 144956e4e..c85a20f88 100644 --- a/polis-cli/crates/polis/src/admin.rs +++ b/polis-cli/crates/polis/src/admin.rs @@ -83,6 +83,13 @@ pub(crate) fn operations() -> &'static [Operation] { pub fn available(path: &str) -> bool { operations().iter().any(|o| o.command == path) } +pub fn csv_available(path: &str) -> bool { + operations().iter().any(|o| { + o.command == path + && !o.effect + && matches!(o.response, Response::Json | Response::PublicJson) + }) +} pub fn command(path: &str) -> Option { let o = operations().iter().find(|o| o.command == path)?; let mut c=Command::new(path.split(' ').next_back().unwrap().to_owned()) diff --git a/polis-cli/crates/polis/src/commands.rs b/polis-cli/crates/polis/src/commands.rs index 86e459f49..a56331ab9 100644 --- a/polis-cli/crates/polis/src/commands.rs +++ b/polis-cli/crates/polis/src/commands.rs @@ -415,7 +415,8 @@ pub fn command() -> Command { .long_about("Listen at scale. Bring Polis to your terminal.\n\nConversations, comments, and shared understanding — for people and agents.\nWorking now: auth, conversations, seeds, moderation, participant/vote reads, report exports, stored Delphi results, and raw API.\nThe full product surface is discoverable below; planned commands return exit 8.") .arg(arg("site","Use a site for this command; default selects pol.is (overrides POLIS_SITE and the saved default)").global(true)) - .arg(flag("json","Emit the versioned polis-cli/1 JSON envelope (including errors and help)").global(true)) + .arg(flag("json","Emit the versioned polis-cli/1 JSON envelope (including errors and help)").global(true).conflicts_with("csv-output")) + .arg(flag("csv-output","Write read-result rows as CSV on stdout; nested fields are JSON, no text truncation (see README Raw data)").long("csv").global(true).conflicts_with("json")) .arg(flag("no-interactive","Never prompt; saved file sign-ins, explicitly opted-in Keychain and environment tokens still work").global(true)) .arg(arg("timeout","Bound each HTTP request in seconds (1–300)").default_value("30").value_parser(clap::value_parser!(u64).range(1..=300)).global(true)) .disable_help_subcommand(true).subcommand_required(true).arg_required_else_help(true); @@ -555,6 +556,7 @@ pub fn schema(cmd: &Command, prefix: &str) -> Value { format!("{prefix} {}", cmd.get_name()) }; json!({"command":path,"description":cmd.get_about().map(|v|v.to_string()),"implemented":available(path.strip_prefix("polis ").unwrap_or(&path)), + "csv":crate::raw_output::available(path.strip_prefix("polis ").unwrap_or(&path)), "arguments":cmd.get_arguments().map(|a|json!({"name":a.get_id().as_str(),"long":a.get_long(),"required":a.is_required_set(),"global":a.is_global_set(),"values":a.get_value_parser().possible_values().map(|v|v.map(|p|p.get_name().to_owned()).collect::>()),"defaults":a.get_default_values().iter().map(|v|v.to_string_lossy()).collect::>(),"help":a.get_help().map(|h|h.to_string()),"action":format!("{:?}",a.get_action())})).collect::>(), "commands":cmd.get_subcommands().map(|c|schema(c,&path)).collect::>()}) } diff --git a/polis-cli/crates/polis/src/main.rs b/polis-cli/crates/polis/src/main.rs index 866090a8a..8ff6505cd 100644 --- a/polis-cli/crates/polis/src/main.rs +++ b/polis-cli/crates/polis/src/main.rs @@ -28,6 +28,7 @@ mod preferences; mod prioritize; mod profiles; mod questions; +mod raw_output; mod reads; mod reserve; mod seeds; @@ -392,7 +393,7 @@ fn execute(root: &ArgMatches, config: &mut profiles::Config, site: &str) -> Resu eprintln!("polis: sizes rank only returned owned rows; the site reached --limit, so larger conversations may be absent."); } } - if m.get_flag("json") { + if m.get_flag("json") || m.get_flag("csv-output") { return Ok(listing); } // People get a table. Its report column needs a second read, which is @@ -715,6 +716,23 @@ fn main() -> ExitCode { return ExitCode::from(if display { 0 } else { 2 }); } }; + let csv_mode = root.get_flag("csv-output"); + let mut leaf = &root; + let mut parts = Vec::new(); + while let Some((name, child)) = leaf.subcommand() { + parts.push(name); + leaf = child; + } + let path = parts.join(" "); + if csv_mode + && (!raw_output::available(&path) + || (path == "topic prioritize" && !leaf.get_flag("show")) + || (path == "api" && str_arg(leaf, "method") != "GET")) + { + return render("unresolved", Err(Error::input( + "CSV is available for read results only. Use --json, or the export command's --format and --output options." + )), false); + } profiles::noninteractive(root.get_flag("no-interactive")); // Help and schema never depend on credentials or profile files. if matches!( @@ -755,6 +773,18 @@ fn main() -> ExitCode { sites::print_header(&config, &site); } let result = execute(&root, &mut config, &site); + if csv_mode { + return match result.and_then(|value| raw_output::csv(&path, &value)) { + Ok(bytes) => { + use std::io::Write; + match std::io::stdout().lock().write_all(&bytes) { + Ok(()) => ExitCode::SUCCESS, + Err(_) => render(&site, Err(Error::input("Cannot write CSV output.")), false), + } + } + Err(e) => render(&site, Err(e), false), + }; + } if !json_mode && site_command { // Site management reports the effective selection after a successful change. if result.is_ok() { diff --git a/polis-cli/crates/polis/src/raw_output.rs b/polis-cli/crates/polis/src/raw_output.rs new file mode 100644 index 000000000..cf116e6ce --- /dev/null +++ b/polis-cli/crates/polis/src/raw_output.rs @@ -0,0 +1,180 @@ +//! CSV presentation of existing reads; no requests or identity enrichment. +use polis_contracts::{Error, Result}; +use serde_json::Value; +use std::collections::BTreeSet; + +pub fn available(path: &str) -> bool { + crate::admin::csv_available(path) + || matches!( + path, + "api" + | "seed csv preview" + | "site list" + | "auth status" + | "account view" + | "plan view" + | "conversation list" + | "conversation view" + | "conversation stats" + | "conversation share" + | "comment list" + | "comment view" + | "comment stats" + | "comment next" + | "comment translations" + | "moderate list" + | "participant list" + | "participant status" + | "participant xid list" + | "participant locations" + | "participant highlight list" + | "participant group-members" + | "vote list" + | "report list" + | "report view" + | "report stats" + | "report comments list" + | "report topics" + | "math view" + | "math correlation" + | "metadata question list" + | "metadata answer list" + | "context list" + | "invite code list" + | "invite wave list" + | "invite list" + | "invite status" + | "topic list" + | "topic comments" + | "topic hierarchy" + | "topic proximity" + | "topic prioritize" + | "topic stats" + | "collective list" + | "collective view" + | "collective statements" + | "delphi status" + | "delphi results" + | "delphi narrative view" + | "delphi visualization view" + | "delphi show" + ) +} + +/// Select only documented row containers. Everything else stays one complete +/// object (nested arrays/objects are JSON cells), rather than guessing a table. +fn rows<'a>(path: &str, value: &'a Value) -> &'a Value { + let key = match path { + "site list" => "sites", + "seed csv preview" => "rows", + "conversation list" => "conversations", + "comment list" | "comment stats" | "report comments list" | "topic comments" => "comments", + "participant list" => "participants", + "vote list" => "votes", + "vote mine" | "vote famous" => "data", + "invite code list" => "codes", + "invite list" => "invites", + "collective list" | "collective statements" => "statements", + "topic list" | "report topics" => "topics", + "topic proximity" => "proximity_data", + "delphi status" => "jobs", + _ => return value, + }; + value.get(key).filter(|v| v.is_array()).unwrap_or(value) +} + +pub fn csv(path: &str, value: &Value) -> Result> { + let value = rows(path, value); + let rows: Vec<&Value> = match value { + Value::Array(rows) => rows.iter().collect(), + _ => vec![value], + }; + let objects = !rows.is_empty() && rows.iter().all(|r| r.is_object()); + let mut headers = BTreeSet::new(); + if objects { + for row in &rows { + headers.extend(row.as_object().unwrap().keys().map(String::as_str)); + } + } + // Header-only `value` is also the representation of an empty result. For + // mixed/scalar rows the single cell keeps the complete value. + let object_columns = objects && !headers.is_empty(); + if !object_columns { + headers.insert("value"); + } + if rows.len().saturating_add(1).saturating_mul(headers.len()) > 1_000_000 { + return Err(Error::input( + "CSV would exceed one million cells. Narrow the read or use --json.", + )); + } + let mut writer = csv::WriterBuilder::new() + .terminator(csv::Terminator::CRLF) + .from_writer(Vec::new()); + let error = |_| Error::input("Cannot encode CSV output."); + writer.write_record(&headers).map_err(error)?; + for row in rows { + let cells: Vec = if object_columns { + headers + .iter() + .map(|key| row.get(*key).map(cell).unwrap_or_default()) + .collect() + } else { + vec![cell(row)] + }; + writer.write_record(cells).map_err(error)?; + if writer.get_ref().len() > 64 * 1024 * 1024 { + return Err(Error::input( + "CSV exceeds 64 MiB. Narrow the read or use --json.", + )); + } + } + let bytes = writer + .into_inner() + .map_err(|_| Error::input("Cannot finish CSV output."))?; + if bytes.len() > 64 * 1024 * 1024 { + return Err(Error::input( + "CSV exceeds 64 MiB. Narrow the read or use --json.", + )); + } + Ok(bytes) +} +fn cell(value: &Value) -> String { + match value { + Value::String(text) => text.clone(), + _ => value.to_string(), + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + + #[test] + fn sparse_columns_cannot_expand_a_small_read_without_bound() { + let rows: Vec<_> = (0..1000).map(|n| json!({format!("field{n}"): n})).collect(); + assert!(csv("context list", &json!(rows)).is_err()); + } + + #[test] + fn mixed_rows_keep_every_value_and_order() { + let input = json!([{"value": "x"}, [0, null], true, "comma,quote\"", null]); + let bytes = csv("context list", &input).unwrap(); + let mut reader = csv::Reader::from_reader(bytes.as_slice()); + assert_eq!( + reader.headers().unwrap(), + &csv::StringRecord::from(vec!["value"]) + ); + let cells: Vec<_> = reader.records().map(|r| r.unwrap()[0].to_owned()).collect(); + assert_eq!( + cells, + vec![ + r#"{"value":"x"}"#, + "[0,null]", + "true", + "comma,quote\"", + "null" + ] + ); + } +} diff --git a/polis-cli/crates/polis/tests/raw_output.rs b/polis-cli/crates/polis/tests/raw_output.rs new file mode 100644 index 000000000..eb370dda1 --- /dev/null +++ b/polis-cli/crates/polis/tests/raw_output.rs @@ -0,0 +1,346 @@ +use serde_json::{json, Value}; +use std::{ + io::{Read, Write}, + net::TcpListener, + process::{Command, Output}, +}; + +fn call(dir: &std::path::Path, args: &[&str]) -> Output { + let mut cmd = Command::new(env!("CARGO_BIN_EXE_polis")); + for (key, _) in std::env::vars() { + if key.starts_with("POLIS_") { + cmd.env_remove(key); + } + } + cmd.env("POLIS_CONFIG_DIR", dir) + .env("POLIS_KEYCHAIN", "off") + .env("POLIS_TOKEN_LOCAL", "generated-token") + .args(args) + .arg("--no-interactive") + .output() + .unwrap() +} +fn table(o: &Output) -> (Vec, Vec>) { + assert!(o.status.success(), "{}", String::from_utf8_lossy(&o.stderr)); + let mut r = csv::Reader::from_reader(o.stdout.as_slice()); + let headers = r.headers().unwrap().iter().map(str::to_owned).collect(); + let rows = r + .records() + .map(|r| r.unwrap().iter().map(str::to_owned).collect()) + .collect(); + (headers, rows) +} +fn response(v: Value) -> (u16, &'static str, String) { + (200, "application/json", v.to_string()) +} +fn server( + dir: &std::path::Path, + responses: Vec<(u16, &'static str, String)>, +) -> std::thread::JoinHandle> { + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + listener.set_nonblocking(true).unwrap(); + std::fs::write(dir.join("profiles.json"),json!({"default":"local","sites":{"local":format!("http://{}",listener.local_addr().unwrap())}}).to_string()).unwrap(); + std::thread::spawn(move || { + let mut requests = Vec::new(); + for (status, content_type, body) in responses { + let start = std::time::Instant::now(); + let mut socket = loop { + match listener.accept() { + Ok((s, _)) => break s, + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { + assert!(start.elapsed().as_secs() < 10, "missing request"); + std::thread::sleep(std::time::Duration::from_millis(5)); + } + Err(e) => panic!("{e}"), + } + }; + socket.set_nonblocking(false).unwrap(); + socket + .set_read_timeout(Some(std::time::Duration::from_secs(5))) + .unwrap(); + let mut bytes = Vec::new(); + let mut buf = [0; 8192]; + loop { + let n = socket.read(&mut buf).unwrap(); + assert!(n > 0); + bytes.extend_from_slice(&buf[..n]); + if let Some(end) = bytes.windows(4).position(|x| x == b"\r\n\r\n") { + let head = String::from_utf8_lossy(&bytes[..end]).to_ascii_lowercase(); + let len = head + .lines() + .find_map(|l| { + l.strip_prefix("content-length: ") + .and_then(|s| s.parse::().ok()) + }) + .unwrap_or(0); + if bytes.len() >= end + 4 + len { + break; + } + } + } + requests.push(String::from_utf8(bytes).unwrap()); + write!(socket,"HTTP/1.1 {status} Fixture\r\nContent-Type: {content_type}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",body.len()).unwrap(); + } + requests + }) +} + +#[test] +fn csv_locations_preserves_duplicates_extensions_and_text_without_identity() { + let t = tempfile::tempdir().unwrap(); + let value = json!([{"lat":1.5,"lng":2.0,"n":1,"text":"=formula,\"quoted\"\r\n雪","nested":{"a":[true,null]}},{"lat":1.5,"lng":2.0,"n":1}]); + let s = server(t.path(), vec![response(value)]); + let o = call( + t.path(), + &[ + "participant", + "locations", + "--conversation", + "convA", + "--group", + "0", + "--csv", + ], + ); + let (h, r) = table(&o); + assert_eq!(h, ["lat", "lng", "n", "nested", "text"]); + assert_eq!(r.len(), 2); + assert_eq!(r[0][4], "=formula,\"quoted\"\r\n雪"); + assert_eq!(r[0][3], r#"{"a":[true,null]}"#); + assert_eq!(r[1][3], ""); + assert_eq!(s.join().unwrap().len(), 1); +} +#[test] +fn json_and_csv_preserve_existing_group_pids_and_empty_groups() { + for mode in ["--json", "--csv"] { + let t = tempfile::tempdir().unwrap(); + let value = json!({"bidToPid":[[],[0,7]],"future":null}); + let s = server(t.path(), vec![response(value.clone())]); + let o = call( + t.path(), + &[ + "participant", + "group-members", + "--conversation", + "convA", + mode, + ], + ); + assert!(o.status.success()); + if mode == "--json" { + assert_eq!( + serde_json::from_slice::(&o.stdout).unwrap()["data"], + value + ); + } else { + let (h, r) = table(&o); + assert_eq!(h, ["bidToPid", "future"]); + assert_eq!(r, vec![vec!["[[],[0,7]]", "null"]]); + } + assert_eq!(s.join().unwrap().len(), 1); + } +} +#[test] +fn csv_owner_conversations_uses_only_the_json_read_with_no_report_lookup() { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![response( + json!([{"is_owner":true,"conversation_id":"convA","topic":"a very long topic with commas, and unicode 雪"}]), + )], + ); + let o = call(t.path(), &["--csv", "conversation", "list"]); + let (h, r) = table(&o); + assert_eq!(h, ["conversation_id", "is_owner", "topic"]); + assert_eq!(r[0][2], "a very long topic with commas, and unicode 雪"); + let requests = s.join().unwrap(); + assert_eq!(requests.len(), 1); + assert!(requests[0].starts_with("GET /api/v3/conversations?")); +} +#[test] +fn csv_owner_xids_keep_leading_zeroes_and_empty_values() { + let t = tempfile::tempdir().unwrap(); + let s = server( + t.path(), + vec![response( + json!([{"pid":0,"xid":"00123"},{"pid":7,"xid":""}]), + )], + ); + let o = call( + t.path(), + &[ + "participant", + "xid", + "list", + "--conversation", + "convA", + "--csv", + ], + ); + let (h, r) = table(&o); + assert_eq!(h, ["pid", "xid"]); + assert_eq!(r, vec![vec!["0", "00123"], vec!["7", ""]]); + let requests = s.join().unwrap(); + assert_eq!(requests.len(), 1); + assert!(requests[0] + .to_lowercase() + .contains("authorization: bearer generated-token")); +} +#[test] +fn csv_votes_preserve_wire_values_and_do_not_add_xids() { + let t = tempfile::tempdir().unwrap(); + let vote = polis_contracts::votes::wire_values()["agree"].clone(); + assert!(!vote.is_null()); + let s = server(t.path(), vec![response(json!([{"tid":0,"vote":vote}]))]); + let o = call( + t.path(), + &[ + "vote", + "list", + "--conversation", + "convA", + "--pid", + "0", + "--csv", + ], + ); + let (h, r) = table(&o); + assert_eq!(h, ["tid", "vote"]); + assert_eq!(r[0][1], vote.to_string()); + assert_eq!(s.join().unwrap().len(), 1); +} +#[test] +fn empty_tables_are_header_only_and_errors_emit_no_csv() { + for (status, body) in [(200, "[]"), (403, r#"{"error":"denied"}"#)] { + let t = tempfile::tempdir().unwrap(); + let s = server(t.path(), vec![(status, "application/json", body.into())]); + let o = call( + t.path(), + &[ + "participant", + "xid", + "list", + "--conversation", + "convA", + "--csv", + ], + ); + if status == 200 { + assert_eq!(o.stdout, b"value\r\n"); + assert!(o.status.success()); + } else { + assert_eq!(o.status.code(), Some(4)); + assert!(o.stdout.is_empty()); + } + assert_eq!(s.join().unwrap().len(), 1); + } +} +#[test] +fn csv_is_rejected_before_configuration_for_writes_and_conflicting_modes() { + let t = tempfile::tempdir().unwrap(); + std::fs::write(t.path().join("profiles.json"), "broken").unwrap(); + for args in [ + vec!["site", "use", "default", "--csv"], + vec!["comment", "convA", "text", "--csv"], + vec!["site", "list", "--csv", "--json"], + ] { + let o = call(t.path(), &args); + assert_eq!(o.status.code(), Some(2)); + assert_eq!( + std::fs::read_to_string(t.path().join("profiles.json")).unwrap(), + "broken" + ); + } +} +#[test] +fn every_implemented_command_has_json_help_and_csv_discovery() { + let t = tempfile::tempdir().unwrap(); + std::fs::write(t.path().join("profiles.json"), "broken").unwrap(); + let o = call(t.path(), &["schema", "--json"]); + assert!(o.status.success()); + let schema: Value = serde_json::from_slice(&o.stdout).unwrap(); + fn visit(v: &Value, t: &std::path::Path, count: &mut usize) { + if v["implemented"] == true { + *count += 1; + let mut args: Vec<_> = v["command"] + .as_str() + .unwrap() + .split_whitespace() + .skip(1) + .collect(); + args.extend(["--help", "--json"]); + let o = call(t, &args); + assert!(o.status.success(), "{args:?}"); + let help: Value = serde_json::from_slice(&o.stdout).unwrap(); + assert_eq!(help["ok"], true); + assert!(help["data"]["help"].as_str().unwrap().contains("--json")); + assert!(v["csv"].is_boolean()); + } + for c in v["commands"].as_array().unwrap() { + visit(c, t, count); + } + } + let mut count = 0; + visit(&schema["data"], t.path(), &mut count); + assert!(count >= 161); +} + +#[test] +fn csv_flag_does_not_replace_the_seed_csv_input_argument() { + let t = tempfile::tempdir().unwrap(); + std::fs::write( + t.path().join("profiles.json"), + r#"{"default":"local","sites":{"local":"http://127.0.0.1:9"}}"#, + ) + .unwrap(); + let input = t.path().join("seeds.csv"); + std::fs::write( + &input, + "comment_text,original_id\nGenerated seed,external-one\n", + ) + .unwrap(); + let o = call( + t.path(), + &["seed", "csv", "preview", input.to_str().unwrap(), "--csv"], + ); + let (headers, rows) = table(&o); + assert_eq!(rows.len(), 1); + assert!(headers.iter().any(|h| h == "comment_text")); + assert!(rows[0].iter().any(|cell| cell == "Generated seed")); +} + +#[test] +fn csv_generic_api_is_get_only_before_configuration() { + let t = tempfile::tempdir().unwrap(); + std::fs::write(t.path().join("profiles.json"), "broken").unwrap(); + let o = call( + t.path(), + &["api", "/api/v3/users", "--method", "POST", "--csv"], + ); + assert_eq!(o.status.code(), Some(2)); + assert!(String::from_utf8_lossy(&o.stderr).contains("read results only")); +} + +#[test] +fn csv_participant_metadata_query_uses_existing_post_read() { + let t = tempfile::tempdir().unwrap(); + let s = server(t.path(), vec![response(json!([{"pid":0},{"pid":7}]))]); + let o = call( + t.path(), + &[ + "participant", + "query", + "--conversation", + "convA", + "--answers", + "1", + "--csv", + ], + ); + let (headers, rows) = table(&o); + assert_eq!(headers, ["pid"]); + assert_eq!(rows, vec![vec!["0"], vec!["7"]]); + let requests = s.join().unwrap(); + assert_eq!(requests.len(), 1); + assert!(requests[0].starts_with("POST /api/v3/query_participants_by_metadata ")); +} diff --git a/polis-cli/examples/join-member-votes.py b/polis-cli/examples/join-member-votes.py new file mode 100644 index 000000000..b9c19ce34 --- /dev/null +++ b/polis-cli/examples/join-member-votes.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +"""Join one conversation's owner XID export and vote export to a member list. + +All cells remain strings. No identities are inferred and vote values are unchanged. +""" +import argparse +import csv +import os +from pathlib import Path + + +def read(path, required): + with Path(path).open(encoding="utf-8-sig", newline="") as stream: + reader = csv.DictReader(stream, strict=True) + headers = reader.fieldnames or [] + if len(headers) != len(set(headers)) or not required <= set(headers): + raise ValueError("Missing or duplicate CSV headers") + rows = list(reader) + if any(None in row or None in row.values() for row in rows): + raise ValueError("CSV row width does not match its header") + return headers, rows + + +def index(rows, key): + result = {} + for row in rows: + value = row[key] + if not value or value in result: + raise ValueError("Empty or duplicate join key; resolve it before joining") + result[value] = row + return result + + +def join(members_path, xids_path, votes_path, output): + _, members = read(members_path, {"xid", "member_label"}) + _, xids = read(xids_path, {"pid", "xid"}) + headers, votes = read(votes_path, {"voter-id", "vote"}) + columns = ["xid", "member_label", "member_match"] + if set(columns) & set(headers): + raise ValueError("Vote export already contains a join output column") + members = index(members, "xid") + xids = index(xids, "pid") + # Validate every input before creating a file; never overwrite an earlier join. + fd = os.open(output, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600) + with os.fdopen(fd, "w", encoding="utf-8", newline="") as stream: + writer = csv.DictWriter(stream, fieldnames=headers + columns) + writer.writeheader() + for vote in votes: + xid = xids.get(vote["voter-id"], {}).get("xid", "") + member = members.get(xid) + writer.writerow({**vote, "xid": xid, + "member_label": member["member_label"] if member else "", + "member_match": "matched" if member is not None else + "no_member" if xid else "no_xid"}) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + for name in ["members", "xids", "votes", "output"]: + parser.add_argument("--" + name, required=True) + args = parser.parse_args() + try: + join(args.members, args.xids, args.votes, args.output) + except (ValueError, OSError, csv.Error) as error: + parser.exit(2, f"Join refused: {type(error).__name__}. Check input headers, unique keys and output path.\n") + + +if __name__ == "__main__": + main() diff --git a/polis-cli/tests/raw_data/test_join.py b/polis-cli/tests/raw_data/test_join.py new file mode 100644 index 000000000..85498247c --- /dev/null +++ b/polis-cli/tests/raw_data/test_join.py @@ -0,0 +1,69 @@ +import csv +import importlib.util +import os +import stat +from pathlib import Path +import tempfile +import unittest + +SPEC = importlib.util.spec_from_file_location("join_example", Path(__file__).resolve().parents[2] / "examples/join-member-votes.py") +JOIN = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(JOIN) + + +class JoinTests(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) + self.write("members", ["xid", "member_label"], [["001", "North, 雪"], ["unused", "No votes"]]) + self.write("xids", ["pid", "xid", "vote_count"], [["0", "001", "2"], ["7", "not-a-member", "1"], ["8", "", "1"]]) + self.write("votes", ["voter-id", "vote", "comment-id"], [["0", "original-export-value", "3"], ["0", "other-export-value", "3"], ["7", "unchanged", "3"], ["8", "unchanged", "3"], ["9", "unchanged", "3"]]) + + def write(self, name, headers, rows): + with (self.root / name).open("w", encoding="utf-8", newline="") as stream: + writer = csv.writer(stream) + writer.writerow(headers) + writer.writerows(rows) + + def run_join(self): + JOIN.join(*(self.root / p for p in ["members", "xids", "votes", "output"])) + + def test_left_join_preserves_votes_duplicates_order_and_string_ids(self): + self.run_join() + if os.name != "nt": + self.assertEqual(stat.S_IMODE((self.root / "output").stat().st_mode), 0o600) + with (self.root / "output").open(encoding="utf-8", newline="") as stream: + rows = list(csv.DictReader(stream)) + self.assertEqual(len(rows), 5) + self.assertEqual([r["member_match"] for r in rows], ["matched", "matched", "no_member", "no_xid", "no_xid"]) + self.assertEqual(rows[0]["xid"], "001") + self.assertEqual(rows[0]["member_label"], "North, 雪") + _, original = JOIN.read(self.root / "votes", {"vote"}) + self.assertEqual([{k: row[k] for k in original[0]} for row in rows], original) + + def test_duplicate_member_key_refused_without_output(self): + self.write("members", ["xid", "member_label"], [["001", "a"], ["001", "b"]]) + with self.assertRaises(ValueError): self.run_join() + self.assertFalse((self.root / "output").exists()) + + def test_duplicate_pid_refused_without_output(self): + self.write("xids", ["pid", "xid"], [["0", "001"], ["0", "002"]]) + with self.assertRaises(ValueError): self.run_join() + self.assertFalse((self.root / "output").exists()) + + def test_no_overwrite(self): + (self.root / "output").write_text("keep") + with self.assertRaises(FileExistsError): self.run_join() + self.assertEqual((self.root / "output").read_text(), "keep") + + def test_missing_duplicate_headers_and_short_rows_refused(self): + for content in ["pid\n0\n", "pid,xid,xid\n0,a,b\n", "pid,xid\n0\n"]: + (self.root / "xids").write_text(content) + with self.assertRaises(ValueError): self.run_join() + self.assertFalse((self.root / "output").exists()) + + def test_output_column_collision_refused(self): + self.write("votes", ["voter-id", "vote", "xid"], [["0", "unchanged", "existing"]]) + with self.assertRaises(ValueError): self.run_join() + self.assertFalse((self.root / "output").exists()) diff --git a/scripts/test-polis-cli.sh b/scripts/test-polis-cli.sh index a8b1508a9..236c48808 100755 --- a/scripts/test-polis-cli.sh +++ b/scripts/test-polis-cli.sh @@ -33,3 +33,6 @@ cargo test --locked -p polis --features fixture-ids --bin polis seeds::fixture_t # Release archive/provenance checks share the same local and hosted entry point. PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s ../scripts/tests -p test_polis_cli_release.py + +# The documented local member/vote join preserves export cells and unmatched rows. +PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests/raw_data -p 'test_*.py' From 9faad3e942834ec12a06136adf9e462c4b9547c4 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Tue, 20 Oct 2026 16:20:30 -0700 Subject: [PATCH 10/30] nginx: switch a Rust route on or off without an outage (#3238) * nginx: switch a Rust route on or off without an outage Observable changes: none for any request by default. Every Rust route stays off unless RUST_API_ROUTES names it, as before. What changes when an operator flips RUST_API_ROUTES: - nginx regenerates its Rust map and reloads in place; the nginx-proxy container is never recreated. Before this, a flip recreated nginx-proxy and polis-api together (about 11 s), and every route through nginx, votes and comments included, failed for that long. - polis-api starts or stops without touching nginx; nginx tolerates the upstream being absent while every route is off (no failed startup, no 502 on Node-served routes). - A container start always obeys its RUST_API_ROUTES environment: unset or off overrides any previously persisted selection. - Rendering holds a kernel flock that dies with its process, so a hard stop can never leave a stale lock that blocks nginx startup. Proof on a local stack: four 50 ms probe streams on participationInit, nextComment, POST votes and POST comments plus pca2 and testConnection, with real votes and comments arriving, across pca2 on and off: 3152/3152 requests succeeded; nginx, Node and dependency container ids unchanged; only polis-api had lifecycle events. Hard-stop-with-stale-lock and env-off-after-persisted-on restarts both come back serving Node. Local checks: nginx-routing.sh 62/62; file-server/nginx/test-rust-reload.sh 10/10 (2238 stub probes, 0 failures). Files: docker-compose.yml, file-server/nginx.Dockerfile, the nginx entrypoint and two render scripts, test-rust-reload.sh, file-server/nginx/README.md, scripts/rust-api-switch.sh. No Node change. No schema change. How a production deploy would carry the reload path is documented separately as a proposal and is not part of this change. Review round 1 by the second reviewer; corrections applied and re-proven. Co-Authored-By: Claude Fable 5.1 * differential: the CLI check builds the production nginx image and switches routes by reload The differential harness mounted the split entrypoint into a stock nginx image without the route helper it now calls, so the proxy exited before nginx started, in the Node phase too. The harness now builds the image from file-server/nginx.Dockerfile, gives the proxy its own routing volume, and enters each phase through the reload helper instead of recreating the container; the access log is truncated after old workers drain so each phase's counts stay independent. No product code, expectation or bound changed. Co-Authored-By: Claude Fable 5.1 --------- Co-authored-by: Claude Fable 5.1 --- docker-compose.yml | 9 +- file-server/nginx.Dockerfile | 7 +- file-server/nginx/README.md | 81 +++++ file-server/nginx/docker-entrypoint.sh | 376 +--------------------- file-server/nginx/render-rust-api.sh | 366 +++++++++++++++++++++ file-server/nginx/rust-routes.sh | 91 ++++++ file-server/nginx/test-rust-reload.sh | 182 +++++++++++ polis-cli/tests/differential/README.md | 12 +- polis-cli/tests/differential/compose.yml | 8 +- polis-cli/tests/differential/harness.py | 8 +- scripts/prepare-polis-cli-differential.sh | 3 +- scripts/rust-api-switch.sh | 47 +++ 12 files changed, 800 insertions(+), 390 deletions(-) create mode 100644 file-server/nginx/README.md create mode 100644 file-server/nginx/render-rust-api.sh create mode 100644 file-server/nginx/rust-routes.sh create mode 100644 file-server/nginx/test-rust-reload.sh create mode 100644 scripts/rust-api-switch.sh diff --git a/docker-compose.yml b/docker-compose.yml index d1a6d4a61..34bc42142 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -434,11 +434,12 @@ services: polis_tag: ${TAG:-dev} environment: - API_SERVER_PORT=${API_SERVER_PORT:-5000} - # Comma-separated routes polis-api serves instead of Node (today only - # "pca2"). Unset: every request goes to Node, as before. Set it only - # with the polis-api service running (`--profile rust-api`). + # Authoritative selection on every nginx startup, even with an existing + # routing volume. Use scripts/rust-api-switch.sh for live reloads. - RUST_API_ROUTES=${RUST_API_ROUTES:-} - RUST_API_UPSTREAM=${RUST_API_UPSTREAM:-polis-api:5100} + volumes: + - nginx-routing:/var/lib/polis-routing depends_on: - "client-participation-alpha" - "server" @@ -635,6 +636,8 @@ networks: polis-net: volumes: + nginx-routing: + delphi-queue-state: math-backfill-state: diff --git a/file-server/nginx.Dockerfile b/file-server/nginx.Dockerfile index 65700f0aa..9d26abecc 100644 --- a/file-server/nginx.Dockerfile +++ b/file-server/nginx.Dockerfile @@ -6,8 +6,11 @@ COPY nginx/nginx-ssl.site.default.conf /etc/nginx/conf.d/default.conf.template # Rust API route templates, rendered by the entrypoint only when # RUST_API_ROUTES is set. COPY nginx/rust-api/ /etc/nginx/rust-api-templates/ -RUN mkdir -p /etc/nginx/rust-api \ - && touch /etc/nginx/rust-api/upstreams.conf /etc/nginx/rust-api/locations.conf +RUN mkdir -p /var/lib/polis-routing \ + && ln -s /var/lib/polis-routing/current /etc/nginx/rust-api +COPY nginx/render-rust-api.sh /usr/local/bin/render-rust-api +COPY nginx/rust-routes.sh /usr/local/bin/polis-rust-routes +RUN chmod +x /usr/local/bin/render-rust-api /usr/local/bin/polis-rust-routes # Copy entrypoint script COPY nginx/docker-entrypoint.sh /docker-entrypoint.sh diff --git a/file-server/nginx/README.md b/file-server/nginx/README.md new file mode 100644 index 000000000..10fd2c2f1 --- /dev/null +++ b/file-server/nginx/README.md @@ -0,0 +1,81 @@ +# Changing Rust route selection + +Every nginx startup renders `RUST_API_ROUTES` from its container environment +(empty by default), including on an initialized routing volume. An unset or +empty list starts all routes on Node regardless of the persisted selection. +`/var/lib/polis-routing/current/routes` records the last applied live selection; +it does not override deployment settings. A hot switch lasts until the next +switch or startup. Persist the desired list in the deployment environment too +if it should survive replacement. `docker compose restart` retains the old +container environment; use the ordinary deployment/recreation flow to apply +changed environment settings. + +After installing this nginx image, apply the desired complete route list from +the repository root, with the same Compose project and files as the running +stack: + +```sh +bash scripts/rust-api-switch.sh pca2 -p polis -f docker-compose.yml +bash scripts/rust-api-switch.sh '' -p polis -f docker-compose.yml +``` + +For an installation using the standalone Compose executable, set +`POLIS_COMPOSE_BIN=/usr/local/bin/docker-compose`. Existing route-specific Rust +flags, database configuration, grants and admission restrictions still apply; +this command does not enable additional Rust handlers or change their defaults. + +The command validates the candidate, reloads nginx to Node, and waits for old +workers to finish their responses. It then starts/reconfigures only `polis-api`, +checks its health from nginx's network, and reloads the selected routes. An empty +list stops only `polis-api`, after the drain. Nginx, Node and their dependencies +are never recreated by this command. An absent Rust upstream cannot prevent +all-off nginx startup; existing per-route DNS and fallback rules are unchanged. + +Rendering creates an immutable generation and atomically swaps its directory +link. A rejected render or `nginx -t` restores the prior generation without a +reload. The default drain deadline is 30 seconds. If the deadline is exceeded, +the command fails and leaves Rust running: it never kills a response that has +already sent headers. Inspect the active selection and retry after the old +workers finish, or retry immediately: the retry also waits for every earlier +shutting-down worker. Rust health has at most 30 attempts, each with a 2-second request +timeout and a 1-second interval; failure leaves selection on Node. + +A switch temporarily routes all selected reads through Node. Routes without a +Node equivalent retain their existing fallback limitations. This is not a +blue/green rollout of Node or nginx and does not remove interruption from the +first installation of a new nginx image or a normal application deployment. + +A lifecycle lock and a render lock serialize changes. The render lock uses +`flock`: a process/container crash releases it automatically. Never remove +`/var/lib/polis-routing/render.flock`, since a new inode could bypass a live +lock. Old `render.lock` directories are ignored, including at startup. +After replacing a dead container, its obsolete directory can be removed with +`docker compose exec nginx-proxy rmdir /var/lib/polis-routing/render.lock`; +this cleanup is optional and has no effect on the current lock. + +The separate `switch.lock` directory protects the whole host-driven lifecycle. +If that caller is killed without cleanup, confirm it has exited and inspect +nginx's workers and the upstream before removing the stale directory. Startup +does not take that lifecycle lock. Do not run independent reload or Compose +recreation commands during a switch. + +First installation replaces the nginx image once; it can interrupt requests. +An empty startup environment now guarantees Node-only bootstrap on both fresh +and initialized volumes. After readiness, apply the desired list with the +helper. Full application deployment and any proposed route-only deployment +integration remain separate from this helper. + +Local Docker checks, also callable by CI: + +```sh +bash file-server/nginx/test-rust-reload.sh +queue-rs/polis-api/conformance/nginx-routing.sh +``` + +The first creates a unique project, exercises concurrent read/write streams, +invalid candidates, environment authority after replacement, crash recovery, +live-lock exclusion, failed health checks and immediate retry during draining, +then removes only that project's containers, network, volume and built image +tag. Diagnostic logs are printed before cleanup. The second is +the existing route-contract suite; set `X54_NGINX_PREFIX` uniquely when sharing a +Docker host. diff --git a/file-server/nginx/docker-entrypoint.sh b/file-server/nginx/docker-entrypoint.sh index 4ecf4d35a..5cf8a659b 100644 --- a/file-server/nginx/docker-entrypoint.sh +++ b/file-server/nginx/docker-entrypoint.sh @@ -1,378 +1,6 @@ #!/bin/sh -set -e - -# Set default value for API_SERVER_PORT +set -eu export API_SERVER_PORT=${API_SERVER_PORT:-5000} - -# Replace environment variables in the Nginx config envsubst '${API_SERVER_PORT}' /etc/nginx/conf.d/default.conf - -# Rust API routes. RUST_API_ROUTES is a comma-separated list of routes that -# polis-api serves instead of Node ("pca2", "owner-conversations", "comments" and "nextComment"). Unset or empty, both -# include files below stay empty and the rendered config routes everything to -# Node exactly as before. No value of these settings can take the proxy down: -# a name that is not a known route, an upstream or resolver that is not a -# plain host[:port] list, or a rendered configuration that nginx -t refuses -# is reported loudly and every route stays on Node. A route named twice is -# rendered once. -mkdir -p /etc/nginx/rust-api -: >/etc/nginx/rust-api/upstreams.conf -: >/etc/nginx/rust-api/locations.conf -RUST_API_MAP_ENTRIES="" -rust_api_locations="" -rust_api_unknown="" -export RUST_API_UPSTREAM=${RUST_API_UPSTREAM:-polis-api:5100} -for route in $(echo "${RUST_API_ROUTES:-}" | tr ',' ' '); do - case "$route" in - pca2) - case " $rust_api_locations " in *" pca2 "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/math/pca2 ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} pca2" - ;; - owner-conversations) - case " $rust_api_locations " in *" owner-conversations "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/owner/conversations ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} owner-conversations" - ;; - comments) - case " $rust_api_locations " in *" comments "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/comments ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} comments" - ;; - nextComment) - case " $rust_api_locations " in *" nextComment "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/nextComment ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} nextComment" - ;; - about) - case " $rust_api_locations " in *" about "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /about ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} about" - ;; - treeviteMyInvites) - case " $rust_api_locations " in *" treeviteMyInvites "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/myInvites ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} treeviteMyInvites" - ;; - robots) - case " $rust_api_locations " in *" robots "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /robots.txt ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} robots" - ;; - domainWhitelist) - case " $rust_api_locations " in *" domainWhitelist "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/domainWhitelist ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} domainWhitelist" - ;; - metadataAnswers) - case " $rust_api_locations " in *" metadataAnswers "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata/answers ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} metadataAnswers" - ;; - metadataRead) - case " $rust_api_locations " in *" metadataRead "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} metadataRead" - ;; - recentActivity) - case " $rust_api_locations " in *" recentActivity "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversations/recent_activity ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} recentActivity" - ;; - allConversations) - case " $rust_api_locations " in *" allConversations "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/all_conversations ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} allConversations" - ;; - reportsRead) - case " $rust_api_locations " in *" reportsRead "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/reports ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} reportsRead" - ;; - bidToPid) - case " $rust_api_locations " in *" bidToPid "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/bidToPid ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} bidToPid" - ;; - conversationStats) - case " $rust_api_locations " in *" conversationStats "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversationStats ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} conversationStats" - ;; - statementImportance) - case " $rust_api_locations " in *" statementImportance "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/statements/importance ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} statementImportance" - ;; - topicSelections) - case " $rust_api_locations " in *" topicSelections "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/topicAgenda/selections ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} topicSelections" - ;; - einvitesRead) - case " $rust_api_locations " in *" einvitesRead "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/einvites ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} einvitesRead" - ;; - createPage) - case " $rust_api_locations " in *" createPage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/conversation/create ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} createPage" - ;; - userCreatePage) - case " $rust_api_locations " in *" userCreatePage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/user/create(/.*)?$ ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} userCreatePage" - ;; - userLoginPage) - case " $rust_api_locations " in *" userLoginPage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/user/login(/.*)?$ ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} userLoginPage" - ;; - settingsPage) - case " $rust_api_locations " in *" settingsPage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/settings(/.*)?$ ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} settingsPage" - ;; - userLogoutPage) - case " $rust_api_locations " in *" userLogoutPage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/user/logout(/.*)?$ ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} userLogoutPage" - ;; - adminPage) - case " $rust_api_locations " in *" adminPage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/m/[0-9][0-9A-Za-z]+ ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} adminPage" - ;; - integratePage) - case " $rust_api_locations " in *" integratePage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/integrate ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} integratePage" - ;; - otherConversationsPage) - case " $rust_api_locations " in *" otherConversationsPage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/other-conversations ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} otherConversationsPage" - ;; - delphiRead) - case " $rust_api_locations " in *" delphiRead "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} delphiRead" - ;; - delphiReports) - case " $rust_api_locations " in *" delphiReports "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/reports ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} delphiReports" - ;; - delphiVisualizations) - case " $rust_api_locations " in *" delphiVisualizations "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/visualizations ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} delphiVisualizations" - ;; - topicStats) - case " $rust_api_locations " in *" topicStats "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/topicStats ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} topicStats" - ;; - delphiLogs) - case " $rust_api_locations " in *" delphiLogs "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/logs ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} delphiLogs" - ;; - delphiRun) - case " $rust_api_locations " in *" delphiRun "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/run ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} delphiRun" - ;; - delphiResult) - case " $rust_api_locations " in *" delphiResult "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/api/v3/delphi/runs/[^/]+$ ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} delphiResult" - ;; - collectiveStatement) - case " $rust_api_locations " in *" collectiveStatement "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/collectiveStatement ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} collectiveStatement" - ;; - opsWhoami) - case " $rust_api_locations " in *" opsWhoami "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/ops/whoami ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} opsWhoami" - ;; - opsPage) - case " $rust_api_locations " in *" opsPage "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/api/v3/ops/page/ ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} opsPage" - ;; - opsCatchall) - case " $rust_api_locations " in *" opsCatchall "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/api/v3/ops(?:$|/(?!whoami(?:/|$)|page(?:/|$))) ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} opsCatchall" - ;; - xidReport) - case " $rust_api_locations " in *" xidReport "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/api/v3/xid/[^/]+$ ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} xidReport" - ;; - topicPrioritize) - case " $rust_api_locations " in *" topicPrioritize "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/participation/topicPrioritize ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} topicPrioritize" - ;; - legacyConversations) - case " $rust_api_locations " in *" legacyConversations "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversations ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} legacyConversations" - ;; - treeviteMe) - case " $rust_api_locations " in *" treeviteMe "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/me ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} treeviteMe" - ;; - recentStarted) - case " $rust_api_locations " in *" recentStarted "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversations/recently_started ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} recentStarted" - ;; - metadataChoices) - case " $rust_api_locations " in *" metadataChoices "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata/choices ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} metadataChoices" - ;; - treeviteInvites) - case " $rust_api_locations " in *" treeviteInvites "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/invites ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} treeviteInvites" - ;; - treeviteCsv) - case " $rust_api_locations " in *" treeviteCsv "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/invites/csv ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} treeviteCsv" - ;; - conversationPreload) - case " $rust_api_locations " in *" conversationPreload "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversations/preload ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} conversationPreload" - ;; - participationRead) - case " $rust_api_locations " in *" participationRead "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/participation ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} participationRead" - ;; - treeviteWaves) - case " $rust_api_locations " in *" treeviteWaves "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/waves ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} treeviteWaves" - ;; - metadataQuestions) - case " $rust_api_locations " in *" metadataQuestions "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata/questions ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} metadataQuestions" - ;; - contexts) - case " $rust_api_locations " in *" contexts "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/contexts ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} contexts" - ;; - testDatabase) - case " $rust_api_locations " in *" testDatabase "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/testDatabase ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} testDatabase" - ;; - legacyPca) - case " $rust_api_locations " in *" legacyPca "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/math/pca ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} legacyPca" - ;; - testConnection) - case " $rust_api_locations " in *" testConnection "*) continue ;; esac - RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/testConnection ${RUST_API_UPSTREAM}; -" - rust_api_locations="${rust_api_locations} testConnection" - ;; - *) - rust_api_unknown="${rust_api_unknown} ${route}" - ;; - esac -done -export RUST_API_RESOLVER=${RUST_API_RESOLVER:-127.0.0.11} -if [ -n "$rust_api_unknown" ]; then - echo "ERROR RUST_API_ROUTES: unknown route(s):${rust_api_unknown} (known: pca2 owner-conversations comments nextComment testConnection testDatabase contexts domainWhitelist metadataQuestions metadataAnswers metadataRead metadataChoices recentStarted recentActivity legacyPca treeviteWaves treeviteInvites treeviteCsv conversationPreload participationRead allConversations reportsRead bidToPid conversationStats statementImportance topicSelections treeviteMyInvites treeviteMe topicPrioritize xidReport opsCatchall opsPage opsWhoami collectiveStatement topicStats delphiLogs delphiRun delphiResult delphiVisualizations delphiReports delphiRead otherConversationsPage integratePage adminPage userLogoutPage settingsPage userLoginPage userCreatePage createPage einvitesRead legacyConversations robots about). Every route stays on Node." >&2 -elif [ -n "$RUST_API_MAP_ENTRIES" ] && - ! echo "$RUST_API_UPSTREAM" | grep -Eqx '[A-Za-z0-9._-]+:[0-9]{1,5}'; then - echo "ERROR RUST_API_UPSTREAM: '${RUST_API_UPSTREAM}' is not host:port. Every route stays on Node." >&2 -elif [ -n "$RUST_API_MAP_ENTRIES" ] && - ! echo "$RUST_API_RESOLVER" | grep -Eqx '[][A-Za-z0-9.:_-]+( [][A-Za-z0-9.:_=-]+)*'; then - echo "ERROR RUST_API_RESOLVER: '${RUST_API_RESOLVER}' is not a list of resolver addresses. Every route stays on Node." >&2 -elif [ -n "$RUST_API_MAP_ENTRIES" ]; then - export RUST_API_MAP_ENTRIES - envsubst '${RUST_API_RESOLVER} ${RUST_API_MAP_ENTRIES}' \ - /etc/nginx/rust-api/upstreams.conf - for route in $rust_api_locations; do - cat /etc/nginx/rust-api-templates/${route}.location.conf.template >>/etc/nginx/rust-api/locations.conf - done - envsubst '${API_SERVER_PORT}' \ - >/etc/nginx/rust-api/locations.conf - if ! rust_api_check=$(nginx -t -q 2>&1); then - : >/etc/nginx/rust-api/upstreams.conf - : >/etc/nginx/rust-api/locations.conf - echo "ERROR RUST_API_ROUTES: nginx refused the rendered Rust API configuration; every route stays on Node. nginx -t said: ${rust_api_check}" >&2 - else - echo "nginx: Rust API routes enabled:${rust_api_locations} -> ${RUST_API_UPSTREAM}, Node as fallback" - fi -fi - -# Execute the original Docker entrypoint with the provided arguments +/usr/local/bin/polis-rust-routes --startup exec "$@" diff --git a/file-server/nginx/render-rust-api.sh b/file-server/nginx/render-rust-api.sh new file mode 100644 index 000000000..8c7e701c9 --- /dev/null +++ b/file-server/nginx/render-rust-api.sh @@ -0,0 +1,366 @@ +#!/bin/sh +set -eu +export API_SERVER_PORT=${API_SERVER_PORT:-5000} +# Rust API routes. RUST_API_ROUTES is a comma-separated list of routes that +# polis-api serves instead of Node ("pca2", "owner-conversations", "comments" and "nextComment"). Unset or empty, both +# include files below stay empty and the rendered config routes everything to +# Node exactly as before. No value of these settings can take the proxy down: +# a name that is not a known route, an upstream or resolver that is not a +# plain host[:port] list, or a rendered configuration that nginx -t refuses +# is reported loudly and every route stays on Node. A route named twice is +# rendered once. +mkdir -p "$1" +: >${1}/upstreams.conf +: >${1}/locations.conf +RUST_API_MAP_ENTRIES="" +rust_api_locations="" +rust_api_unknown="" +export RUST_API_UPSTREAM=${RUST_API_UPSTREAM:-polis-api:5100} +for route in $(echo "${RUST_API_ROUTES:-}" | tr ',' ' '); do + case "$route" in + pca2) + case " $rust_api_locations " in *" pca2 "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/math/pca2 ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} pca2" + ;; + owner-conversations) + case " $rust_api_locations " in *" owner-conversations "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/owner/conversations ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} owner-conversations" + ;; + comments) + case " $rust_api_locations " in *" comments "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/comments ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} comments" + ;; + nextComment) + case " $rust_api_locations " in *" nextComment "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/nextComment ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} nextComment" + ;; + about) + case " $rust_api_locations " in *" about "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /about ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} about" + ;; + treeviteMyInvites) + case " $rust_api_locations " in *" treeviteMyInvites "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/myInvites ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} treeviteMyInvites" + ;; + robots) + case " $rust_api_locations " in *" robots "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /robots.txt ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} robots" + ;; + domainWhitelist) + case " $rust_api_locations " in *" domainWhitelist "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/domainWhitelist ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} domainWhitelist" + ;; + metadataAnswers) + case " $rust_api_locations " in *" metadataAnswers "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata/answers ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} metadataAnswers" + ;; + metadataRead) + case " $rust_api_locations " in *" metadataRead "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} metadataRead" + ;; + recentActivity) + case " $rust_api_locations " in *" recentActivity "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversations/recent_activity ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} recentActivity" + ;; + allConversations) + case " $rust_api_locations " in *" allConversations "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/all_conversations ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} allConversations" + ;; + reportsRead) + case " $rust_api_locations " in *" reportsRead "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/reports ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} reportsRead" + ;; + bidToPid) + case " $rust_api_locations " in *" bidToPid "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/bidToPid ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} bidToPid" + ;; + conversationStats) + case " $rust_api_locations " in *" conversationStats "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversationStats ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} conversationStats" + ;; + statementImportance) + case " $rust_api_locations " in *" statementImportance "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/statements/importance ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} statementImportance" + ;; + topicSelections) + case " $rust_api_locations " in *" topicSelections "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/topicAgenda/selections ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} topicSelections" + ;; + einvitesRead) + case " $rust_api_locations " in *" einvitesRead "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/einvites ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} einvitesRead" + ;; + createPage) + case " $rust_api_locations " in *" createPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/conversation/create ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} createPage" + ;; + userCreatePage) + case " $rust_api_locations " in *" userCreatePage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/user/create(/.*)?$ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} userCreatePage" + ;; + userLoginPage) + case " $rust_api_locations " in *" userLoginPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/user/login(/.*)?$ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} userLoginPage" + ;; + settingsPage) + case " $rust_api_locations " in *" settingsPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/settings(/.*)?$ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} settingsPage" + ;; + userLogoutPage) + case " $rust_api_locations " in *" userLogoutPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/user/logout(/.*)?$ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} userLogoutPage" + ;; + adminPage) + case " $rust_api_locations " in *" adminPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/m/[0-9][0-9A-Za-z]+ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} adminPage" + ;; + integratePage) + case " $rust_api_locations " in *" integratePage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/integrate ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} integratePage" + ;; + otherConversationsPage) + case " $rust_api_locations " in *" otherConversationsPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/other-conversations ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} otherConversationsPage" + ;; + delphiRead) + case " $rust_api_locations " in *" delphiRead "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} delphiRead" + ;; + delphiReports) + case " $rust_api_locations " in *" delphiReports "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/reports ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} delphiReports" + ;; + delphiVisualizations) + case " $rust_api_locations " in *" delphiVisualizations "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/visualizations ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} delphiVisualizations" + ;; + topicStats) + case " $rust_api_locations " in *" topicStats "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/topicStats ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} topicStats" + ;; + delphiLogs) + case " $rust_api_locations " in *" delphiLogs "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/logs ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} delphiLogs" + ;; + delphiRun) + case " $rust_api_locations " in *" delphiRun "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/delphi/run ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} delphiRun" + ;; + delphiResult) + case " $rust_api_locations " in *" delphiResult "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/api/v3/delphi/runs/[^/]+$ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} delphiResult" + ;; + collectiveStatement) + case " $rust_api_locations " in *" collectiveStatement "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/collectiveStatement ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} collectiveStatement" + ;; + opsWhoami) + case " $rust_api_locations " in *" opsWhoami "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/ops/whoami ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} opsWhoami" + ;; + opsPage) + case " $rust_api_locations " in *" opsPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/api/v3/ops/page/ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} opsPage" + ;; + opsCatchall) + case " $rust_api_locations " in *" opsCatchall "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/api/v3/ops(?:$|/(?!whoami(?:/|$)|page(?:/|$))) ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} opsCatchall" + ;; + xidReport) + case " $rust_api_locations " in *" xidReport "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/api/v3/xid/[^/]+$ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} xidReport" + ;; + topicPrioritize) + case " $rust_api_locations " in *" topicPrioritize "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/participation/topicPrioritize ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} topicPrioritize" + ;; + legacyConversations) + case " $rust_api_locations " in *" legacyConversations "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversations ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} legacyConversations" + ;; + treeviteMe) + case " $rust_api_locations " in *" treeviteMe "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/me ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} treeviteMe" + ;; + recentStarted) + case " $rust_api_locations " in *" recentStarted "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversations/recently_started ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} recentStarted" + ;; + metadataChoices) + case " $rust_api_locations " in *" metadataChoices "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata/choices ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} metadataChoices" + ;; + treeviteInvites) + case " $rust_api_locations " in *" treeviteInvites "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/invites ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} treeviteInvites" + ;; + treeviteCsv) + case " $rust_api_locations " in *" treeviteCsv "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/invites/csv ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} treeviteCsv" + ;; + conversationPreload) + case " $rust_api_locations " in *" conversationPreload "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/conversations/preload ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} conversationPreload" + ;; + participationRead) + case " $rust_api_locations " in *" participationRead "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/participation ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} participationRead" + ;; + treeviteWaves) + case " $rust_api_locations " in *" treeviteWaves "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/waves ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} treeviteWaves" + ;; + metadataQuestions) + case " $rust_api_locations " in *" metadataQuestions "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata/questions ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} metadataQuestions" + ;; + contexts) + case " $rust_api_locations " in *" contexts "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/contexts ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} contexts" + ;; + testDatabase) + case " $rust_api_locations " in *" testDatabase "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/testDatabase ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} testDatabase" + ;; + legacyPca) + case " $rust_api_locations " in *" legacyPca "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/math/pca ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} legacyPca" + ;; + testConnection) + case " $rust_api_locations " in *" testConnection "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/testConnection ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} testConnection" + ;; + *) + rust_api_unknown="${rust_api_unknown} ${route}" + ;; + esac +done +export RUST_API_RESOLVER=${RUST_API_RESOLVER:-127.0.0.11} +if [ -n "$rust_api_unknown" ]; then + echo "ERROR RUST_API_ROUTES: unknown route(s):${rust_api_unknown} (known: pca2 owner-conversations comments nextComment testConnection testDatabase contexts domainWhitelist metadataQuestions metadataAnswers metadataRead metadataChoices recentStarted recentActivity legacyPca treeviteWaves treeviteInvites treeviteCsv conversationPreload participationRead allConversations reportsRead bidToPid conversationStats statementImportance topicSelections treeviteMyInvites treeviteMe topicPrioritize xidReport opsCatchall opsPage opsWhoami collectiveStatement topicStats delphiLogs delphiRun delphiResult delphiVisualizations delphiReports delphiRead otherConversationsPage integratePage adminPage userLogoutPage settingsPage userLoginPage userCreatePage createPage einvitesRead legacyConversations robots about). Selection rejected." >&2 + exit 1 +elif [ -n "$RUST_API_MAP_ENTRIES" ] && + ! echo "$RUST_API_UPSTREAM" | grep -Eqx '[A-Za-z0-9._-]+:[0-9]{1,5}'; then + echo "ERROR RUST_API_UPSTREAM: '${RUST_API_UPSTREAM}' is not host:port. Selection rejected." >&2 + exit 1 +elif [ -n "$RUST_API_MAP_ENTRIES" ] && + ! echo "$RUST_API_RESOLVER" | grep -Eqx '[][A-Za-z0-9.:_-]+( [][A-Za-z0-9.:_=-]+)*'; then + echo "ERROR RUST_API_RESOLVER: '${RUST_API_RESOLVER}' is not a list of resolver addresses. Selection rejected." >&2 + exit 1 +elif [ -n "$RUST_API_MAP_ENTRIES" ]; then + export RUST_API_MAP_ENTRIES + envsubst '${RUST_API_RESOLVER} ${RUST_API_MAP_ENTRIES}' \ + ${1}/upstreams.conf + for route in $rust_api_locations; do + cat /etc/nginx/rust-api-templates/${route}.location.conf.template >>${1}/locations.conf + done + envsubst '${API_SERVER_PORT}' \ + >${1}/locations.conf +fi +[ -z "$rust_api_unknown" ] || exit 1 diff --git a/file-server/nginx/rust-routes.sh b/file-server/nginx/rust-routes.sh new file mode 100644 index 000000000..ef5c9313b --- /dev/null +++ b/file-server/nginx/rust-routes.sh @@ -0,0 +1,91 @@ +#!/bin/sh +# One immutable include generation per reload. Running workers retain their +# parsed configuration until they drain; no request sees half a rendered map. +set -eu +mode=${1:?usage: polis-rust-routes --startup|--check|--reload} +case "$mode" in --startup|--check|--reload) ;; *) exit 2;; esac +state=/var/lib/polis-routing +mkdir -p "$state" +# Keep the inode: removing it could let two callers lock different files. +# The kernel releases this lock even after SIGKILL or container replacement. +# Legacy render.lock directories are inert; no live lock is ever removed. +exec 9>"$state/render.flock" +flock -n 9 || { echo 'Another route render is active' >&2; exit 1; } +previous=$(readlink "$state/current" || true) +candidate=$(mktemp -d "$state/generation.XXXXXX") +published=0 +keep=0 +cleanup() { + if [ "$published" = 1 ] && [ "$keep" = 0 ]; then + if [ -n "$previous" ]; then + ln -s "$previous" "$state/restore.$$" + mv -Tf "$state/restore.$$" "$state/current" + else + rm -f "$state/current" + fi + fi + [ "$keep" = 1 ] || rm -rf "$candidate" +} +trap cleanup EXIT +trap 'exit 1' HUP INT TERM +# Every startup obeys the container environment, including an unset/off list. +# The persisted map records live reload state, never deployment intent. +if ! /usr/local/bin/render-rust-api "$candidate"; then + [ "$mode" = --startup ] || exit 1 + echo 'Invalid startup selection; serving every route through Node' >&2 + RUST_API_ROUTES= /usr/local/bin/render-rust-api "$candidate" + RUST_API_ROUTES= +fi +printf '%s\n' "${RUST_API_ROUTES:-}" >"$candidate/routes" +ln -s "$candidate" "$state/next.$$" +mv -Tf "$state/next.$$" "$state/current" +published=1 +if ! nginx -t -q; then + [ "$mode" = --startup ] || exit 1 + echo 'ERROR RUST_API_ROUTES: nginx refused the rendered Rust API configuration; every route stays on Node.' >&2 + RUST_API_ROUTES= /usr/local/bin/render-rust-api "$candidate" + printf '\n' >"$candidate/routes" + nginx -t -q +fi +[ "$mode" != --check ] || exit 0 +if [ "$mode" = --reload ]; then + master=$(cat /var/run/nginx.pid) + workers() { + for pid in $(cat "/proc/$master/task/$master/children"); do + [ -r "/proc/$pid/cmdline" ] || continue + case "$(tr '\000' ' ' <"/proc/$pid/cmdline")" in + 'nginx: worker process'*) printf '%s\n' "$pid";; + esac + done + } + old=$(workers | tr "\n" " ") + [ -n "$old" ] || { echo 'No nginx workers found; refusing reload' >&2; exit 1; } + nginx -s reload + # Once signalled, retain the selected map even on a drain timeout. The + # controller must leave Rust running until a later successful drain. + keep=1 + limit=${RUST_API_DRAIN_SECONDS:-30} + case "$limit" in ''|*[!0-9]*) echo 'Invalid drain bound' >&2; exit 1;; esac + until_time=$(($(date +%s) + limit)) + while :; do + current=$(workers) + new=0 + for pid in $current; do + case " $old " in *" $pid "*) ;; *) new=1;; esac + done + remaining=0 + for pid in $old; do [ ! -d "/proc/$pid" ] || remaining=1; done + if [ "$new" = 1 ] && [ "$remaining" = 0 ]; then break; fi + if [ "$(date +%s)" -ge "$until_time" ]; then + echo 'Reload did not drain within the bound; leave polis-api running' >&2 + exit 1 + fi + sleep 0.1 + done +fi +keep=1 +# No older worker needs its files after startup or a successful drain. +for generation in "$state"/generation.*; do + [ "$generation" = "$candidate" ] || rm -rf "$generation" +done +echo "nginx route selection applied ($mode)" diff --git a/file-server/nginx/test-rust-reload.sh b/file-server/nginx/test-rust-reload.sh new file mode 100644 index 000000000..7db96caaa --- /dev/null +++ b/file-server/nginx/test-rust-reload.sh @@ -0,0 +1,182 @@ +#!/usr/bin/env bash +# Local Docker proof, callable by CI. All resources belong to a unique project. +set -euo pipefail +root=$(cd "$(dirname "$0")/../.." && pwd) +project="rustreload-$$-${RANDOM}" +work=$(mktemp -d) +compose=(docker compose -p "$project" -f "$work/compose.json") +cleanup() { + "${compose[@]}" logs --no-color nginx-proxy >&2 || true + "${compose[@]}" down -v --remove-orphans >/dev/null 2>&1 || true + docker image rm "$project:local" >/dev/null 2>&1 || true + rm -rf "$work" +} +trap cleanup EXIT +export RELOAD_TEST_ROOT="$root" RELOAD_TEST_WORK="$work" RELOAD_TEST_PROJECT="$project" +python3 - <<'PY' +import json,os,pathlib +root=os.environ['RELOAD_TEST_ROOT']; work=pathlib.Path(os.environ['RELOAD_TEST_WORK']) +def stub(port,body): + return {'image':'nginx:1.21.5-alpine','entrypoint':['sh','-c',f'printf \'server {{ listen {port}; location / {{ return 200 "{body}"; }} }}\' > /etc/nginx/conf.d/default.conf; exec nginx -g "daemon off;"']} +config={'services':{'server':stub(5000,'node'),'client-participation-alpha':stub(4321,'alpha'),'polis-api':stub(5100,'rust'),'nginx-proxy':{'image':os.environ['RELOAD_TEST_PROJECT']+':local','build':{'context':root+'/file-server','dockerfile':'nginx.Dockerfile'},'depends_on':['server','client-participation-alpha'],'ports':['127.0.0.1::80'],'volumes':['routing:/var/lib/polis-routing']}},'volumes':{'routing':{}}} + +# Delay after headers to prove draining protects a response that cannot fall back. +rust_code = """from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +import os,time +class Handler(BaseHTTPRequestHandler): + def do_GET(self): + if self.path=='/health' and os.environ.get('FAIL_HEALTH')=='1': + self.send_response(503); self.end_headers(); return + self.send_response(200); self.send_header('Content-Length','4'); self.end_headers() + if 'slow' in self.path: time.sleep(4) + self.wfile.write(b'rust') + def log_message(self,*args): pass +ThreadingHTTPServer(('0.0.0.0',5100),Handler).serve_forever() +""" +config['services']['polis-api']={'image':'python:3.12-alpine','entrypoint':['python','-u','-c',rust_code],'environment':{'FAIL_HEALTH':'${FAIL_HEALTH:-0}'}} +(work/'compose.json').write_text(json.dumps(config)) +PY +"${compose[@]}" pull polis-api +"${compose[@]}" build nginx-proxy +"${compose[@]}" up -d server client-participation-alpha nginx-proxy +python3 - <<'PY' +import concurrent.futures,http.client,json,os,pathlib,subprocess,threading,time +root=pathlib.Path(os.environ['RELOAD_TEST_ROOT']);work=pathlib.Path(os.environ['RELOAD_TEST_WORK']);project=os.environ['RELOAD_TEST_PROJECT'] +opts=['-p',project,'-f',str(work/'compose.json')];dc=['docker','compose',*opts] +def run(args,check=True,**kw):return subprocess.run(args,check=check,capture_output=True,text=True,**kw) +proxy=run(dc+['ps','-q','nginx-proxy']).stdout.strip() +port=int(run(dc+['port','nginx-proxy','80']).stdout.strip().rsplit(':',1)[1]) +def req(path='/api/v3/math/pca2',method='GET'): + c=http.client.HTTPConnection('127.0.0.1',port,timeout=8) + try: + c.request(method,path,body='{}' if method=='POST' else None);r=c.getresponse();return r.status,r.read().decode() + finally:c.close() +for _ in range(50): + try: + if req()==(200,'node'):break + except OSError:pass + time.sleep(.1) +else:raise AssertionError('initial Node readiness') +print('ok 1 all-off starts with Rust absent',flush=True) +stop=threading.Event();samples=[];lock=threading.Lock() +paths=[('participationInit','GET','/api/v3/participationInit'),('nextComment','GET','/api/v3/nextComment'),('votes','POST','/api/v3/votes'),('comments','POST','/api/v3/comments'),('pca2','GET','/api/v3/math/pca2')] +def probe(name,method,path): + while not stop.is_set(): + try:status,body=req(path,method);ok=status==200 and body in (['node','rust'] if name=='pca2' else ['node']) + except Exception:ok=False + with lock:samples.append((name,ok)) + stop.wait(.05) +threads=[threading.Thread(target=probe,args=p) for p in paths] +for t in threads:t.start() +def flip(routes): + r=run(['bash',str(root/'scripts/rust-api-switch.sh'),routes,*opts],False) + assert r.returncode==0,r.stdout+r.stderr + assert run(dc+['ps','-q','nginx-proxy']).stdout.strip()==proxy +try: + for cycle in range(2): + flip('pca2');assert req()==(200,'rust') + before=run(['docker','exec',proxy,'readlink','/var/lib/polis-routing/current']).stdout + bad=run(['bash',str(root/'scripts/rust-api-switch.sh'),'unknown-route',*opts],False) + assert bad.returncode!=0 and req()==(200,'rust') + assert run(['docker','exec',proxy,'readlink','/var/lib/polis-routing/current']).stdout==before + # A broken candidate config also preserves the last working generation. + bad=run(['docker','exec','-e','RUST_API_ROUTES=pca2','-e','RUST_API_RESOLVER=127.0.0.11 invalid_option',proxy,'/usr/local/bin/polis-rust-routes','--reload'],False) + assert bad.returncode!=0 and req()==(200,'rust') + assert run(['docker','exec',proxy,'readlink','/var/lib/polis-routing/current']).stdout==before + flip('');assert req()==(200,'node') + assert not run(dc+['ps','--status','running','-q','polis-api']).stdout.strip() + print('ok 2 two on/off cycles, Rust attribution, unchanged nginx ID, invalid selections preserved',flush=True) +finally: + stop.set() + for t in threads:t.join() +summary={name:{'n':sum(n==name for n,ok in samples),'failed':sum(n==name and not ok for n,ok in samples)} for name,_,_ in paths} +print(json.dumps(summary),flush=True) +assert all(v['n']>0 and v['failed']==0 for v in summary.values()) +print('ok 3 five concurrent streams, zero failures',flush=True) +# Restart tests deliberately interrupt the listener and are outside flip probes. +def refresh(): + global proxy,port + proxy=run(dc+['ps','-q','nginx-proxy']).stdout.strip() + port=int(run(dc+['port','nginx-proxy','80']).stdout.strip().rsplit(':',1)[1]) +def ready(body): + for _ in range(100): + try: + if req()==(200,body):return + except OSError:pass + time.sleep(.1) + raise AssertionError('startup readiness: '+body) +def persisted(): + return run(['docker','exec',proxy,'cat','/var/lib/polis-routing/current/routes']).stdout.strip() +def dependencies(): + return {name:run(dc+['ps','-q',name]).stdout.strip() for name in ['nginx-proxy','server','client-participation-alpha']} +flip('pca2') +assert persisted()=='pca2' +run(dc+['up','-d','--no-deps','--force-recreate','nginx-proxy']) +refresh();ready('node');assert persisted()=='' +print('ok 4 unset startup environment overrides persisted on selection',flush=True) +# A nonempty list also replaces (rather than merges with) the old selection. +overlay=work/'startup.json' +overlay.write_text(json.dumps({'services':{'nginx-proxy':{'environment':{'RUST_API_ROUTES':'pca2'}}}})) +run(dc+['-f',str(overlay),'up','-d','--no-deps','--force-recreate','nginx-proxy']) +refresh();ready('rust');assert persisted()=='pca2' +overlay.write_text(json.dumps({'services':{'nginx-proxy':{'environment':{'RUST_API_ROUTES':''}}}})) +run(dc+['-f',str(overlay),'up','-d','--no-deps','--force-recreate','nginx-proxy']) +refresh();ready('node');assert persisted()=='' +print('ok 5 explicit startup on then off obeys deployment env on initialized volume',flush=True) +# Hold the actual kernel lock; a second renderer must not delete/bypass it. +run(['docker','exec','-d',proxy,'sh','-c','exec 9>/var/lib/polis-routing/render.flock; flock 9; touch /tmp/render-held; exec sleep 300']) +for _ in range(100): + if run(['docker','exec',proxy,'test','-f','/tmp/render-held'],False).returncode==0:break + time.sleep(.05) +else:raise AssertionError('lock holder did not start') +before=run(['docker','exec',proxy,'readlink','/var/lib/polis-routing/current']).stdout +busy=run(['docker','exec','-e','RUST_API_ROUTES=pca2',proxy,'/usr/local/bin/polis-rust-routes','--reload'],False) +assert busy.returncode!=0 and 'Another route render is active' in busy.stderr +assert run(['docker','exec',proxy,'readlink','/var/lib/polis-routing/current']).stdout==before +assert req()==(200,'node') +print('ok 6 live render lock excludes a competing renderer without changing traffic',flush=True) +# Preserve the volume and both the old directory and new lock file across KILL. +run(['docker','exec',proxy,'mkdir','/var/lib/polis-routing/render.lock']) +run(dc+['kill','-s','SIGKILL','nginx-proxy']) +run(dc+['start','nginx-proxy']);refresh();ready('node') +assert persisted()=='' +assert run(['docker','exec',proxy,'test','-d','/var/lib/polis-routing/render.lock'],False).returncode==0 +flip('pca2');assert req()==(200,'rust') +print('ok 7 hard stop releases kernel lock; stale directory does not prevent startup or reload',flush=True) +# Wait until response headers arrive, then switch off. The old worker must +# finish the body before the controller stops Rust. +def delayed_response(signal): + c=http.client.HTTPConnection('127.0.0.1',port,timeout=20) + c.request('GET','/api/v3/math/pca2?slow=1');r=c.getresponse();signal.set() + try:return r.status,r.read().decode() + finally:c.close() +with concurrent.futures.ThreadPoolExecutor() as pool: + signal=threading.Event();pending=pool.submit(delayed_response,signal) + assert signal.wait(5) + flip('') + assert pending.result()==(200,'rust') +print('ok 8 down flip drains a Rust body already past its headers',flush=True) +flip('pca2') +with concurrent.futures.ThreadPoolExecutor() as pool: + signal=threading.Event();pending=pool.submit(delayed_response,signal) + assert signal.wait(5) + timed=run(['docker','exec','-e','RUST_API_ROUTES=','-e','RUST_API_DRAIN_SECONDS=0',proxy,'/usr/local/bin/polis-rust-routes','--reload'],False) + assert timed.returncode!=0 and 'within the bound' in timed.stderr + assert run(dc+['ps','--status','running','-q','polis-api']).stdout.strip() + assert not pending.done(), 'response must still be outstanding at immediate retry' + flip('') + assert pending.result()==(200,'rust') +assert not run(dc+['ps','--status','running','-q','polis-api']).stdout.strip() +print('ok 9 immediate retry after drain timeout waits for earlier shutting-down worker',flush=True) +# A real failed health response must leave Node serving and dependencies intact. +before=dependencies() +failed=run(['bash',str(root/'scripts/rust-api-switch.sh'),'pca2',*opts],False,env=dict(os.environ,FAIL_HEALTH='1')) +assert failed.returncode!=0 and 'Rust health failed; selection remains on Node' in failed.stderr +assert dependencies()==before +assert req()==(200,'node') and persisted()=='' +assert run(dc+['ps','--status','running','-q','polis-api']).stdout.strip() +flip('') +print('ok 10 failed Rust health leaves map on Node and recreates no dependency',flush=True) + +print('PASS: 10 reload groups',flush=True) +PY diff --git a/polis-cli/tests/differential/README.md b/polis-cli/tests/differential/README.md index 7bbd854f0..0df060978 100644 --- a/polis-cli/tests/differential/README.md +++ b/polis-cli/tests/differential/README.md @@ -5,7 +5,7 @@ fixture and local credential/files state, then run it again with every inventori staged Rust route enabled. This is independent of the byte replays: it neither starts those runners nor reads a recording archive. Byte replays remain the wire gate. -Build the CLI and four local images from the source being tested: +Build the CLI and five local images from the source being tested: ```sh (cd polis-cli && cargo build --locked -p polis --features fixture-ids) @@ -13,11 +13,13 @@ docker build --target prod --build-arg NODE_ENV=production -t cli-diff-node -f s docker build --build-context queue-rs=queue-rs -t cli-diff-postgres -f server/Dockerfile-db server docker build -t cli-diff-oidc oidc-simulator docker build --build-arg FEATURES=fixture-clock -t cli-diff-rust -f queue-rs/polis-api/Dockerfile queue-rs +docker build -t cli-diff-nginx:local -f file-server/nginx.Dockerfile file-server ``` Choose an unused project and three unused ports. The images are explicit and `up --pull never` prevents a test from silently changing them. The nginx image -is the same pinned tag used by the existing routing tests. +is built from the production Dockerfile, including its route helpers and +the include-generation symlink. A stock nginx image is insufficient. ```sh export COMPOSE_PROJECT_NAME=p027cli-diff-local @@ -88,8 +90,10 @@ not successful export/import, provider, analysis or backend coverage. Planned commands and local commands are likewise reported separately. Never turn a connectivity/parser/authentication failure into a successful live scenario. -The real nginx renderer receives `RUST_API_ROUTES` empty and then every -switch in `routes.json`. The route-template census rejects missing entries. +The real nginx reload helper receives `RUST_API_ROUTES` empty and then every +switch in `routes.json`, retaining the proxy container and its project-owned +routing volume. After old workers drain, the harness clears the access log +for each phase's independent counts. The route-template census rejects missing entries. Each entry requires an exact request count, a minimum number of sole Rust HTTP200 responses, and an exact count of scoped Node handoffs with a reason. These counts cover this generated fixture only. Unexercised routes explicitly diff --git a/polis-cli/tests/differential/compose.yml b/polis-cli/tests/differential/compose.yml index 8e9493a87..c6bfd154b 100644 --- a/polis-cli/tests/differential/compose.yml +++ b/polis-cli/tests/differential/compose.yml @@ -138,14 +138,12 @@ services: depends_on: postgres: {condition: service_healthy} proxy: - image: ${CLI_DIFF_NGINX_IMAGE:-nginx:1.21.5-alpine} - entrypoint: [sh, /renderer.sh, nginx, -g, 'daemon off;'] + image: ${CLI_DIFF_NGINX_IMAGE:-cli-diff-nginx:local} environment: API_SERVER_PORT: '5000' RUST_API_ROUTES: ${RUST_API_ROUTES:-} volumes: - - ../../file-server/nginx/docker-entrypoint.sh:/renderer.sh:ro - - ../../file-server/nginx/rust-api:/etc/nginx/rust-api-templates:ro + - routing:/var/lib/polis-routing - ../../polis-cli/tests/differential/nginx.conf.template:/etc/nginx/conf.d/default.conf.template:ro networks: [sealed] depends_on: [server, polis-api] @@ -160,3 +158,5 @@ services: depends_on: [proxy] networks: cli: {} +volumes: + routing: {} diff --git a/polis-cli/tests/differential/harness.py b/polis-cli/tests/differential/harness.py index 6759b207a..7533b093b 100644 --- a/polis-cli/tests/differential/harness.py +++ b/polis-cli/tests/differential/harness.py @@ -166,12 +166,16 @@ def up(self): return self.tokens def enter_phase(self,switch,*,fresh_backends): - """Re-render the proxy with the real renderer and reinstall the fixture. + """Reload the proxy with the real route helper and reinstall the fixture. Fresh backend processes clear process caches between phases.""" self.env['RUST_API_ROUTES']=switch if fresh_backends: self.dc('restart','-t','1','server','dynamodb');self.ready();self.publish_keys();self.dc('restart','-t','1','polis-api') - self.dc('up','-d','--no-deps','--force-recreate','--pull','never','proxy') + self.dc('exec','-T','-e','RUST_API_ROUTES='+switch, + 'proxy','/usr/local/bin/polis-rust-routes','--reload') + # The proxy survives phase changes. After old workers drain, clear + # only the access log so routing counts still describe one phase. + self.dc('exec','-T','proxy','sh','-c',': > '+NGINX_LOG) fixture=self.dc('exec','-T','server','node','/differential/seed.cjs',input=json.dumps(self.tokens),check=False) if fixture.returncode: print(fixture.stderr,file=sys.stderr) diff --git a/scripts/prepare-polis-cli-differential.sh b/scripts/prepare-polis-cli-differential.sh index 49f37b45d..5c3adda02 100644 --- a/scripts/prepare-polis-cli-differential.sh +++ b/scripts/prepare-polis-cli-differential.sh @@ -8,6 +8,7 @@ docker build --target prod --build-arg NODE_ENV=production -t "$CLI_DIFF_NODE_IM docker build --build-context queue-rs=queue-rs -t "$CLI_DIFF_POSTGRES_IMAGE" -f server/Dockerfile-db server docker build -t "$CLI_DIFF_OIDC_IMAGE" oidc-simulator docker build --build-arg FEATURES=fixture-clock -t "$CLI_DIFF_RUST_IMAGE" -f queue-rs/polis-api/Dockerfile queue-rs -for image in "${CLI_DIFF_NGINX_IMAGE:-nginx:1.21.5-alpine}" amazon/dynamodb-local:latest; do +docker build -t "${CLI_DIFF_NGINX_IMAGE:-cli-diff-nginx:local}" -f file-server/nginx.Dockerfile file-server +for image in amazon/dynamodb-local:latest; do docker image inspect "$image" >/dev/null 2>&1 || docker pull "$image" done diff --git a/scripts/rust-api-switch.sh b/scripts/rust-api-switch.sh new file mode 100644 index 000000000..3fd8ac50b --- /dev/null +++ b/scripts/rust-api-switch.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# Usage: bash scripts/rust-api-switch.sh ROUTES [docker compose global options...] +# Pass '' to move every route to Node, drain nginx, then stop only polis-api. +# Requires the reload-capable nginx image. Never recreates nginx or Node. +set -euo pipefail +[[ $# -ge 1 ]] || { echo "Usage: $0 ROUTES [compose options...]" >&2; exit 2; } +routes=$1 +shift +if [[ -n "${POLIS_COMPOSE_BIN:-}" ]]; then + compose=("$POLIS_COMPOSE_BIN" "$@") +else + compose=(docker compose "$@") +fi +proxy=$("${compose[@]}" ps -q nginx-proxy) +[[ -n "$proxy" ]] || { echo 'nginx-proxy is not running' >&2; exit 1; } +# Lock the entire lifecycle, not only each individual render/reload. A crashed +# caller leaves a visible lock and requires an operator to inspect before retry. +docker exec "$proxy" mkdir /var/lib/polis-routing/switch.lock +cleanup() { docker exec "$proxy" rmdir /var/lib/polis-routing/switch.lock >/dev/null; } +trap cleanup EXIT +trap 'exit 1' HUP INT TERM +apply() { + docker exec -e "RUST_API_ROUTES=$1" "$proxy" /usr/local/bin/polis-rust-routes "$2" +} +# Reject unknown routes before changing the current selection or any service. +apply "$routes" --check +# Old workers may have a Rust response in flight; do not stop Rust under them. +apply '' --reload +if [[ -z "${routes//[,$' \t\r\n']/}" ]]; then + "${compose[@]}" stop polis-api +else + RUST_API_ROUTES="$routes" "${compose[@]}" up -d --no-deps --no-build polis-api + # Probe from nginx's own network namespace. The diagnostic host is the same + # host:port its validated map uses, and the response must be HTTP success. + ready=0 + for ((attempt=0; attempt<30; attempt++)); do + if docker exec "$proxy" sh -c 'wget -q -T 2 -O /dev/null "http://${RUST_API_UPSTREAM:-polis-api:5100}/health"'; then + ready=1 + break + fi + sleep 1 + done + [[ "$ready" = 1 ]] || { echo 'Rust health failed; selection remains on Node' >&2; exit 1; } + apply "$routes" --reload +fi +[[ "$proxy" = "$("${compose[@]}" ps -q nginx-proxy)" ]] || { echo 'nginx identity changed unexpectedly' >&2; exit 1; } +echo 'Route switch complete; nginx container retained' From 745762d730331f7c2792065af7f1216dec442924 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Tue, 20 Oct 2026 18:16:44 -0700 Subject: [PATCH 11/30] votes: a typed contract for POST /api/v3/votes with 140 recorded cases (#3239) * votes: a typed contract for POST /api/v3/votes with 140 recorded cases The contract in polis-contracts names the request, every response Node produces on this pin and the vote convention it speaks through; the characterization harness records and replays 140 cases of the real route against unchanged Node with zero differences. Three opt-in probes stay red on purpose: they document the deferred bookkeeping writes failing after a durable vote, which a separate change fixes. No served behaviour changes. Co-Authored-By: Claude Fable 5.1 * votes: drop two unused bindings in the recorder Co-Authored-By: Claude Fable 5.1 --------- Co-authored-by: Claude Fable 5.1 --- queue-rs/polis-contracts/src/lib.rs | 1 + queue-rs/polis-contracts/src/post_votes.rs | 630 ++++++++++++++++++ server/characterization/barrier.cjs | 4 +- server/characterization/cli.cjs | 6 +- server/characterization/entry.cjs | 5 + server/characterization/observe.cjs | 5 +- server/characterization/votes/COVERAGE.md | 69 ++ server/characterization/votes/README.md | 106 +++ .../votes/additional-cases.json | 410 ++++++++++++ server/characterization/votes/additional.cjs | 136 ++++ server/characterization/votes/compose.yml | 4 + .../votes/contract-cases.json | 434 ++++++++++++ server/characterization/votes/control.cjs | 115 ++++ server/characterization/votes/diagnose.cjs | 16 + server/characterization/votes/idle-tls.cjs | 36 + .../characterization/votes/idle-tls.test.cjs | 58 ++ .../characterization/votes/install-tokens.cjs | 11 + .../votes/provider-tokens.cjs | 22 + server/characterization/votes/run.cjs | 166 +++++ 19 files changed, 2230 insertions(+), 4 deletions(-) create mode 100644 queue-rs/polis-contracts/src/post_votes.rs create mode 100644 server/characterization/votes/COVERAGE.md create mode 100644 server/characterization/votes/README.md create mode 100644 server/characterization/votes/additional-cases.json create mode 100644 server/characterization/votes/additional.cjs create mode 100644 server/characterization/votes/compose.yml create mode 100644 server/characterization/votes/contract-cases.json create mode 100644 server/characterization/votes/control.cjs create mode 100644 server/characterization/votes/diagnose.cjs create mode 100644 server/characterization/votes/idle-tls.cjs create mode 100644 server/characterization/votes/idle-tls.test.cjs create mode 100644 server/characterization/votes/install-tokens.cjs create mode 100644 server/characterization/votes/provider-tokens.cjs create mode 100644 server/characterization/votes/run.cjs diff --git a/queue-rs/polis-contracts/src/lib.rs b/queue-rs/polis-contracts/src/lib.rs index ae1082282..dfb101430 100644 --- a/queue-rs/polis-contracts/src/lib.rs +++ b/queue-rs/polis-contracts/src/lib.rs @@ -34,6 +34,7 @@ pub mod ops_page; pub mod ops_whoami; pub mod other_conversations_page; pub mod participation_read; +pub mod post_votes; pub mod recent_activity; pub mod recent_started; pub mod reports_read; diff --git a/queue-rs/polis-contracts/src/post_votes.rs b/queue-rs/polis-contracts/src/post_votes.rs new file mode 100644 index 000000000..56be99133 --- /dev/null +++ b/queue-rs/polis-contracts/src/post_votes.rs @@ -0,0 +1,630 @@ +//! POST /api/v3/votes as served by Node. This is a contract, not a writer. +//! +//! Auth and conversation resolution precede field parsing. A malformed vote can +//! create a participant without returning its token. Vote history + latest state +//! commit in one statement; star and next-comment work happen afterward. An HTTP +//! error is therefore not evidence that nothing was saved. Never replay it merely +//! because a proxy got an error. See the recording profile for durable witnesses. +//! +//! Source pin: 050dd04e7e6d9154e259a8addaa1e2229a768489. Middleware order: +//! server/app.ts:1272–1288. `parse_fields` covers only the fields registered after +//! membership; CID/XID validation, cookies and JWT identity resolution are outside +//! it (server/src/utils/parameter.ts:336; server/app.ts:1279–1280). +//! The decoder models Node JSON and production finalhandler bodies, including +//! the 50 MiB parser limit (server/app.ts:342) and HTTPS policy +//! (server/src/utils/domain.ts:59). Gateway-generated responses and development +//! finalhandler stack traces are outside this contract. It is not write admission. +use crate::votes::{StorageConvention, VoteChoice, WIRE_AGREE, WIRE_DISAGREE, WIRE_PASS}; +use crate::wire::JsNumber; +use serde::{Deserialize, Serialize}; +use serde_json::{value::RawValue, Value}; + +pub const PATH: &str = "/api/v3/votes"; +pub const CONTRACT: &str = "post-votes/1"; + +/// Raw body fields deliberately retain invalid types for characterization. +/// Null and absence both mean missing to Node's parameter middleware. Unknown +/// fields (including weight and caller-supplied pid) are not route inputs. +#[derive(Debug, Clone, Default, Deserialize, Serialize)] +pub struct Request { + pub conversation_id: Option, + pub xid: Option, + pub tid: Option, + pub vote: Option, + pub starred: Option, + pub high_priority: Option, + pub lang: Option, +} + +#[derive(Debug, Clone, PartialEq)] +pub struct ParsedFields { + /// Node accepts integer prefixes and does not bound tid to PostgreSQL int4. + /// An overflowing decimal string can parse to infinity and fail at the DB. + pub tid: f64, + pub vote: VoteChoice, + pub starred: Option, + pub high_priority: bool, + pub lang: Option, +} +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct InvalidField(pub &'static str); +fn ecma_space(c: char) -> bool { + matches!(c, '\u{0009}'..='\u{000d}' | '\u{0020}' | '\u{00a0}' | '\u{1680}' | '\u{2000}'..='\u{200a}' | '\u{2028}' | '\u{2029}' | '\u{202f}' | '\u{205f}' | '\u{3000}' | '\u{feff}') +} +/// Node's getInt: numeric integers or parseInt(text, 10), not strict decimal. +pub fn integer(value: &Value) -> Option { + match value { + Value::Number(n) => n.as_f64().filter(|n| n.is_finite() && n.fract() == 0.0), + Value::String(s) => { + let s = s.trim_start_matches(ecma_space); + let sign = usize::from(s.starts_with(['+', '-'])); + let digits = s + .as_bytes() + .iter() + .skip(sign) + .take_while(|b| b.is_ascii_digit()) + .count(); + if digits == 0 { + None + } else { + s[..sign + digits].parse().ok() + } + } + _ => None, + } +} +pub fn boolean(value: &Value) -> Option { + match value { + Value::Bool(v) => Some(*v), + Value::Number(n) => n.as_f64().map(|n| n != 0.0), + Value::String(s) => match s.to_lowercase().as_str() { + "t" | "true" | "on" | "1" => Some(true), + "f" | "false" | "off" | "0" => Some(false), + _ => None, + }, + _ => None, + } +} +/// Node checks UTF-16 length before trimming ASCII spaces; empty is accepted. +pub fn string(value: &Value, max: usize) -> Option { + value + .as_str() + .filter(|s| s.encode_utf16().count() <= max) + .map(|s| s.trim_matches(' ').to_owned()) +} +impl Request { + /// Only route-local fields, after auth/membership. Not an auth simulator. + pub fn parse_fields(&self) -> Result { + let tid = self + .tid + .as_ref() + .and_then(integer) + .ok_or(InvalidField("tid"))?; + let raw = self + .vote + .as_ref() + .and_then(integer) + .ok_or(InvalidField("vote"))?; + let vote = if raw == f64::from(WIRE_AGREE) { + VoteChoice::Agree + } else if raw == f64::from(WIRE_DISAGREE) { + VoteChoice::Disagree + } else if raw == f64::from(WIRE_PASS) { + VoteChoice::Pass + } else { + return Err(InvalidField("vote")); + }; + let optional_bool = |v: &Option, name| match v.as_ref().filter(|v| !v.is_null()) { + None => Ok(None), + Some(v) => boolean(v).map(Some).ok_or(InvalidField(name)), + }; + let starred = optional_bool(&self.starred, "starred")?; + let high_priority = optional_bool(&self.high_priority, "high_priority")?.unwrap_or(false); + let lang = match self.lang.as_ref().filter(|v| !v.is_null()) { + None => None, + Some(v) => Some(string(v, 10).ok_or(InvalidField("lang"))?), + }; + Ok(ParsedFields { + tid, + vote, + starred, + high_priority, + lang, + }) + } +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Auth { + pub token: String, + pub token_type: String, + pub expires_in: u64, +} +impl Auth { + /// server/src/auth/ensure-participant.ts:667–671. + fn validate(&self) -> Result<(), String> { + if self.token_type != "Bearer" || self.expires_in != 31_536_000 { + return Err("invalid issued auth metadata".into()); + } + Ok(()) + } +} +/// Retain exact bytes/order of nextComment, whose translation rows and optional +/// fields come from Node. Ordinary selection adds counts/randomN at +/// server/src/nextComment.ts:100–110, :170; topical selection constructs only +/// zid/tid/txt at :353–357. Both add translations at :420, :464–508 (300 ms timer at :501). +#[derive(Debug, Deserialize, Serialize)] +#[serde(transparent)] +pub struct NextComment(pub Box); +#[derive(Debug, Deserialize)] +#[serde(untagged)] +pub enum NextCommentFields { + Ordinary(OrdinaryNextComment), + Topical(TopicalNextComment), +} +#[derive(Debug, Deserialize)] +pub struct OrdinaryNextComment { + pub tid: i32, + pub txt: String, + pub remaining: u64, + pub total: u64, + #[serde(rename = "randomN")] + pub random_n: JsNumber, + pub translations: Vec, +} +#[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct TopicalNextComment { + pub zid: i32, + pub tid: i32, + pub txt: String, + pub translations: Vec, +} +impl NextComment { + pub fn fields(&self) -> serde_json::Result { + serde_json::from_str(self.0.get()) + } +} +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Success { + #[serde(rename = "nextComment", skip_serializing_if = "Option::is_none")] + pub next_comment: Option, + #[serde(rename = "currentPid")] + pub current_pid: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option, +} +/// The source initializes a fresh result with no shouldMod, so modOptions is +/// unreachable here. Auth injection also occurs on handler failJson responses. +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Failure { + pub error: String, + pub message: String, + pub status: u16, + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option, +} +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct AuthFailure { + pub error: String, + pub details: String, +} +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct AccountFailure { + pub error: String, + pub message: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub retry_after: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub details: Option, +} +#[derive(Debug)] +pub enum Response { + Success(Success), + Failure(Failure), + AuthFailure(AuthFailure), + AccountFailure(AccountFailure), + /// Express production finalhandler; middleware errors are not failJson. + Text { + status: u16, + body: Vec, + }, +} +impl Response { + pub fn decode(status: u16, body: &[u8]) -> Result { + if status == 200 { + let result: Success = serde_json::from_slice(body).map_err(|e| e.to_string())?; + reject_null_optionals(body, &["nextComment", "auth"])?; + if let Some(next) = &result.next_comment { + next.fields().map_err(|e| e.to_string())?; + } + if let Some(auth) = &result.auth { + auth.validate()?; + } + return Ok(Self::Success(result)); + } + if body == b"Bad Request\n" && status == 400 + || body == b"Internal Server Error\n" && status == 500 + || body == b"Payload Too Large\n" && status == 413 + || body == b"Unsupported Media Type\n" && status == 415 + || body == b"Please use HTTPS when submitting data." && status == 400 + { + return Ok(Self::Text { + status, + body: body.to_vec(), + }); + } + if status == 401 { + if let Ok(value) = serde_json::from_slice::(body) { + if value.error == "Invalid authentication token" + || value.error == "Invalid token format" + && value.details == "Token does not match any supported JWT type" + { + return Ok(Self::AuthFailure(value)); + } + } + } + if let Ok(value) = serde_json::from_slice::(body) { + reject_null_optionals(body, &["details", "retry_after"])?; + if ACCOUNT_ERRORS.iter().any(|(s, code, message)| { + *s == status && *code == value.error && *message == value.message + }) && (status == 429 && value.retry_after == Some(1) + || status != 429 && value.retry_after.is_none()) + && (value.details.is_none() + || matches!( + value.error.as_str(), + "user_creation_failed" | "authentication_error" + )) + { + return Ok(Self::AccountFailure(value)); + } + } + let result: Failure = serde_json::from_slice(body).map_err(|e| e.to_string())?; + reject_null_optionals(body, &["auth"])?; + if result.status != status + || result.message != result.error + || !ERRORS + .iter() + .any(|(s, c, _)| *s == status && *c == result.error) + { + return Err("unrecognized POST votes error".into()); + } + if let Some(auth) = &result.auth { + // Membership and parameter errors precede attachAuthToken: + // server/app.ts:1277–1287; auth/ensure-participant.ts:683–698; + // utils/parameter.ts:137. Only handler errors can carry it. + if !matches!( + result.error.as_str(), + "polis_err_conversation_is_closed" + | "polis_err_vote_duplicate" + | "polis_err_vote" + | "polis_err_finishing_response" + ) { + return Err("auth is unavailable before the token injector".into()); + } + auth.validate()?; + } + Ok(Self::Failure(result)) + } + pub fn bytes(&self) -> serde_json::Result> { + match self { + Self::Success(v) => serde_json::to_vec(v), + Self::Failure(v) => serde_json::to_vec(v), + Self::AuthFailure(v) => serde_json::to_vec(v), + Self::AccountFailure(v) => serde_json::to_vec(v), + Self::Text { body, .. } => Ok(body.clone()), + } + } +} +fn reject_null_optionals(body: &[u8], fields: &[&str]) -> Result<(), String> { + let value: Value = serde_json::from_slice(body).map_err(|e| e.to_string())?; + if fields + .iter() + .any(|field| value.get(field).is_some_and(Value::is_null)) + { + return Err("Node omits absent optional response fields".into()); + } + Ok(()) +} +/// Third column identifies the producer and explicit SQL-fault coverage. +/// Accepted failJson producers: server/src/utils/parameter.ts:137, +/// auth/ensure-participant.ts:683–698, routes/votes.ts:283–302 and +/// server-helpers.ts:236. Unreachable catches are listed separately. +pub const ERRORS: &[(u16, &str, &str)] = &[ + (400, "polis_err_misc", "parameter assigner exception"), + ( + 401, + "polis_err_treevite_auth_required", + "membership refusal", + ), + (403, "polis_err_xid_required", "new identity refusal"), + (403, "polis_err_xid_not_allowed", "allow-list refusal"), + (403, "polis_err_conversation_is_closed", "handler refusal"), + ( + 406, + "polis_err_vote_duplicate", + "SQLSTATE 23505; no history unique key on published schema", + ), + ( + 500, + "polis_err_vote", + "insert, star or next-comment failure; may have committed", + ), + ( + 500, + "polis_err_finishing_response", + "finishOne serialization failure after mutation", + ), +]; +/// Excluded from decoding: fresh result has no zid (routes/votes.ts:253), so +/// addConversationId resolves immediately (server-helpers.ts:197); its rejection +/// catch at :232 cannot run. The other two labels are legacy handler catches +/// (routes/votes.ts:291–302), never thrown by doVotesPost at this pin. +pub const UNREACHABLE_ERRORS: &[(u16, &str, &str)] = &[ + ( + 500, + "polis_err_finishing_responseA", + "unreachable addConversationId rejection", + ), + ( + 403, + "polis_err_post_votes_social_needed", + "unreachable legacy handler catch", + ), + ( + 500, + "polis_err_vote_anonymous_user_creation", + "unreachable legacy handler catch", + ), +]; +/// server/src/auth/jwt-middleware.ts:104–160. Only the two 500 branches may +/// include details, and only in DEV_MODE. decode accepts both configuration +/// modes; it does not assert which mode produced a particular response. +pub const ACCOUNT_ERRORS: &[(u16, &str, &str)] = &[ + ( + 429, + "too_many_requests", + "Authentication system is experiencing high load. Please try again in a moment.", + ), + ( + 400, + "invalid_user_data", + "User account is missing required information (email).", + ), + ( + 429, + "authentication_conflict", + "Authentication system encountered a temporary conflict. Please try again.", + ), + ( + 500, + "user_creation_failed", + "Failed to create or map user account", + ), + ( + 500, + "authentication_error", + "An unexpected authentication error occurred", + ), +]; +/// The INSERT rule replaces vote and modified, even for a repeated vote or equal +/// timestamp. It does not select MAX(created) and does not replace latest weight. +/// History always appends. high_priority exists only on history at this pin. +pub fn stored_vote(choice: VoteChoice) -> i32 { + StorageConvention::CURRENT.encode(choice) +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + #[test] + fn node_integer_and_boolean_coercions() { + for (value, expected) in [ + (json!(" +12tail"), Some(12.0)), + (json!("0x10"), Some(0.0)), + (json!("1.9"), Some(1.0)), + (json!("1e3"), Some(1.0)), + (json!("\u{feff}3"), Some(3.0)), + (json!(1.5), None), + (json!(true), None), + (json!(""), None), + ] { + assert_eq!(integer(&value), expected); + } + for (value, expected) in [ + (json!(2), Some(true)), + (json!("OFF"), Some(false)), + (json!(" true "), None), + (json!([]), None), + ] { + assert_eq!(boolean(&value), expected); + } + } + #[test] + fn string_length_precedes_ascii_space_trimming() { + assert_eq!(string(&json!(" x "), 5), Some("x".into())); + assert_eq!(string(&json!(" x "), 4), None); + assert_eq!(string(&json!(""), 10), Some("".into())); + assert_eq!(string(&json!("😀"), 1), None); + assert_eq!(string(&json!("\t"), 1), Some("\t".into())); + } + #[test] + fn optional_null_defaults_and_vote_meaning() { + let r: Request = serde_json::from_value( + json!({"tid":"0tail","vote":WIRE_AGREE,"starred":null,"high_priority":null}), + ) + .unwrap(); + let v = r.parse_fields().unwrap(); + assert_eq!(v.vote, VoteChoice::Agree); + assert_eq!(v.starred, None); + assert!(!v.high_priority); + assert_eq!( + stored_vote(v.vote), + StorageConvention::CURRENT.encode(VoteChoice::Agree) + ); + } + #[test] + fn middleware_field_order_is_preserved() { + let r: Request = + serde_json::from_value(json!({"tid":false,"vote":99,"starred":"bad"})).unwrap(); + assert_eq!(r.parse_fields(), Err(InvalidField("tid"))); + } + #[test] + fn topical_and_translated_selection_preserve_bytes() { + for body in [ + r#"{"nextComment":{"zid":1,"tid":7,"txt":"Generated topical","translations":[]},"currentPid":2}"#, + r#"{"nextComment":{"zid":1,"tid":7,"txt":"Generated topical","translations":[{"zid":1,"tid":7,"txt":"Texte","lang":"fr"}]},"currentPid":2}"#, + ] { + let decoded = Response::decode(200, body.as_bytes()).unwrap(); + assert_eq!(decoded.bytes().unwrap(), body.as_bytes()); + let Response::Success(success) = decoded else { + panic!("success") + }; + assert!(matches!( + success.next_comment.unwrap().fields().unwrap(), + NextCommentFields::Topical(_) + )); + } + for body in [ + r#"{"nextComment":{"tid":7,"txt":"Incomplete ordinary"},"currentPid":2}"#, + r#"{"nextComment":null,"currentPid":2}"#, + r#"{"nextComment":{"zid":1,"tid":7,"txt":"Partial counts","remaining":3,"translations":[]},"currentPid":2}"#, + ] { + assert!(Response::decode(200, body.as_bytes()).is_err()); + } + } + #[test] + fn ordinary_translations_require_an_array_and_preserve_bytes() { + for body in [ + r#"{"nextComment":{"tid":7,"txt":"Generated ordinary","remaining":3,"total":4,"randomN":0.5,"translations":[]},"currentPid":2}"#, + r#"{"nextComment":{"tid":7,"txt":"Generated ordinary","remaining":3,"total":4,"randomN":0.5,"translations":[{"zid":1,"tid":7,"txt":"Texte","lang":"fr"}]},"currentPid":2}"#, + ] { + let decoded = Response::decode(200, body.as_bytes()).unwrap(); + assert_eq!(decoded.bytes().unwrap(), body.as_bytes()); + let Response::Success(success) = decoded else { + panic!("success") + }; + assert!(matches!( + success.next_comment.unwrap().fields().unwrap(), + NextCommentFields::Ordinary(_) + )); + } + for body in [ + r#"{"nextComment":{"tid":7,"txt":"Missing translations","remaining":3,"total":4,"randomN":0.5},"currentPid":2}"#, + r#"{"nextComment":{"tid":7,"txt":"Null translations","remaining":3,"total":4,"randomN":0.5,"translations":null},"currentPid":2}"#, + ] { + assert!(Response::decode(200, body.as_bytes()).is_err()); + } + } + #[test] + fn middleware_position_controls_auth_delivery() { + let auth = json!({"token":"generated-token","token_type":"Bearer","expires_in":31_536_000}); + for &(status, code, _) in ERRORS { + let mut body = json!({"error":code,"message":code,"status":status}); + assert!( + Response::decode(status, &serde_json::to_vec(&body).unwrap()).is_ok(), + "{code}" + ); + body["auth"] = auth.clone(); + let handler = matches!( + code, + "polis_err_conversation_is_closed" + | "polis_err_vote_duplicate" + | "polis_err_vote" + | "polis_err_finishing_response" + ); + assert_eq!( + Response::decode(status, &serde_json::to_vec(&body).unwrap()).is_ok(), + handler, + "{code}" + ); + } + for &(status, code, _) in UNREACHABLE_ERRORS { + let body = json!({"error":code,"message":code,"status":status}); + assert!(Response::decode(status, &serde_json::to_vec(&body).unwrap()).is_err()); + } + for (field, value) in [("token_type", json!("bearer")), ("expires_in", json!(1))] { + let mut body = json!({"currentPid":2,"auth":auth}); + body["auth"][field] = value; + assert!(Response::decode(200, &serde_json::to_vec(&body).unwrap()).is_err()); + } + } + #[test] + fn account_envelopes_follow_their_producers() { + for &(status, error, message) in ACCOUNT_ERRORS { + let mut body = json!({"error":error,"message":message}); + if status == 429 { + body["retry_after"] = json!(1); + } + assert!(Response::decode(status, &serde_json::to_vec(&body).unwrap()).is_ok()); + body["details"] = json!("generated account failure"); + assert_eq!( + Response::decode(status, &serde_json::to_vec(&body).unwrap()).is_ok(), + status == 500 + ); + body.as_object_mut().unwrap().remove("details"); + body["retry_after"] = json!(2); + assert!(Response::decode(status, &serde_json::to_vec(&body).unwrap()).is_err()); + } + } + #[test] + fn pre_handler_transport_and_auth_envelopes() { + for (status, body) in [ + (400, "Bad Request\n"), + (500, "Internal Server Error\n"), + (413, "Payload Too Large\n"), + (415, "Unsupported Media Type\n"), + (400, "Please use HTTPS when submitting data."), + ( + 401, + r#"{"error":"Invalid authentication token","details":"jwt expired"}"#, + ), + ( + 401, + r#"{"error":"Invalid token format","details":"Token does not match any supported JWT type"}"#, + ), + ] { + let response = Response::decode(status, body.as_bytes()).unwrap(); + assert_eq!(response.bytes().unwrap(), body.as_bytes()); + assert!(Response::decode(404, body.as_bytes()).is_err()); + } + // Optional hybrid auth never emits the required-auth missing-token body. + assert!(Response::decode(401, br#"{"error":"No authentication token found"}"#).is_err()); + } + #[test] + fn recorded_response_bytes_round_trip() { + round_trip( + include_str!("../../../server/characterization/votes/contract-cases.json"), + 72, + ); + } + #[test] + fn additional_recorded_response_bytes_round_trip() { + round_trip( + include_str!("../../../server/characterization/votes/additional-cases.json"), + 68, + ); + } + fn round_trip(fixture: &str, count: usize) { + let rows: Value = serde_json::from_str(fixture).unwrap(); + assert_eq!(rows.as_array().unwrap().len(), count); + for row in rows.as_array().unwrap() { + let body = row["body"].as_str().unwrap(); + let response = + Response::decode(row["status"].as_u64().unwrap() as u16, body.as_bytes()) + .unwrap_or_else(|e| panic!("{}: {e}", row["case"])); + assert_eq!( + response.bytes().unwrap(), + body.as_bytes(), + "{}", + row["case"] + ); + } + } +} diff --git a/server/characterization/barrier.cjs b/server/characterization/barrier.cjs index ee4c86216..856f18cc0 100644 --- a/server/characterization/barrier.cjs +++ b/server/characterization/barrier.cjs @@ -27,7 +27,7 @@ function exemption(kind, stack, callback) { // they cannot perform request writes. runtime.test.cjs exercises actual resources. // Request ownership propagates through promises even though promises themselves are // not pending I/O. Track timers, filesystem work and explicit DB/provider operations. -function createBarrier(unownedActive = () => false) { +function createBarrier(unownedActive = () => false, settledResource = () => false) { const context = new AsyncLocalStorage(), pending = new Map(), closed = new Set(), @@ -73,7 +73,7 @@ function createBarrier(unownedActive = () => false) { function state(owner) { return { pending: [...pending.values()] - .filter((x) => x.owner === owner) + .filter((x) => x.owner === owner && !settledResource(x.kind, x.resource)) .map(({ owner, kind, origin, callback }) => ({ owner, kind, diff --git a/server/characterization/cli.cjs b/server/characterization/cli.cjs index b523f3b7a..e425d0f57 100644 --- a/server/characterization/cli.cjs +++ b/server/characterization/cli.cjs @@ -359,6 +359,9 @@ async function observeCase(c, tokens, tables, normalizer) { ? JSON.parse(Buffer.from(tokens[c.auth].split(".")[1], "base64url")).sub : undefined, xid: c.request.body?.xid, + // Additional vote identities declare the expected subject independently of + // the response; signature, participant and conversation checks still apply. + ...c.credentialBinding, }; const wire = response.wire; wire.response.headers = require("./headers.cjs").headers( @@ -456,6 +459,7 @@ async function observeCase(c, tokens, tables, normalizer) { return { ...c, version: 1, + ...(!stable ? { unsettledWork: obsAfter.work } : {}), ...(c.caseId.startsWith("comments-read/") ? { commentsContext: obsAfter.commentsContext } : {}), @@ -1053,7 +1057,7 @@ async function close() { // sender, snapshot and schema reader rather than reimplementing request // semantics. Requiring the module must not run the recorder, and a consumer // needs a way to release the pg pool and the DynamoDB client it opens on import. -module.exports = { send, snapshot, schema, close }; +module.exports = { send, snapshot, schema, close, runCase }; if (require.main === module) { main() diff --git a/server/characterization/entry.cjs b/server/characterization/entry.cjs index 7b8b04e14..d50474f85 100644 --- a/server/characterization/entry.cjs +++ b/server/characterization/entry.cjs @@ -12,6 +12,10 @@ const pair = crypto.generateKeyPairSync("rsa", { }); process.env.JWT_PRIVATE_KEY = pair.privateKey; process.env.JWT_PUBLIC_KEY = pair.publicKey; +// Explicit, local recording profile; never loaded by the application entrypoint. +const votesProfile = process.env.P027_VOTES_PROFILE === "1" + ? require("./votes/control.cjs").install(state, pair) + : null; function files(dir = process.cwd()) { const result = {}; function visit(p) { @@ -90,6 +94,7 @@ async function main() { .createServer(async (req, res) => { res.setHeader("content-type", "application/json"); try { + if (votesProfile && await votesProfile(req, res)) return; if (req.url.startsWith("/begin?")) { const seed = new URL(req.url, "http://localhost").searchParams.get( "seed" diff --git a/server/characterization/observe.cjs b/server/characterization/observe.cjs index cc25d6e56..f0f33b232 100644 --- a/server/characterization/observe.cjs +++ b/server/characterization/observe.cjs @@ -31,7 +31,10 @@ const state = (global.__p027 = { // Bluebird's shared callback queue otherwise drops AsyncLocalStorage ownership. require("bluebird").config({ asyncHooks: true }); const barrier = (state.barrier = require("./barrier.cjs").createBarrier( - () => state.currentCase !== null + () => state.currentCase !== null, + process.env.P027_VOTES_PROFILE === "1" + ? require("./votes/idle-tls.cjs").install() + : undefined )); const { AsyncResource } = require("node:async_hooks"); const pgPool = require("pg").Pool, diff --git a/server/characterization/votes/COVERAGE.md b/server/characterization/votes/COVERAGE.md new file mode 100644 index 000000000..6e5f7ba0f --- /dev/null +++ b/server/characterization/votes/COVERAGE.md @@ -0,0 +1,69 @@ +# POST votes contract coverage + +Source pin: `050dd04e7e6d9154e259a8addaa1e2229a768489`. This is a compatibility +catalog and a bounded recording profile, not authority to serve a Rust writer. +The production Node handlers, authentication code, pools and schema are unchanged. +Every valid vote is submitted over HTTP using `semanticToWire`; stored values +are inspected through `storageToSemantic`. Storage agree remains owned by the +convention module. No new vote insert helper or allowlist exception is introduced. + +## Response producers + +| Branch | Source | Evidence and contract | +| --- | --- | --- | +| Ordinary success | `server/src/routes/votes.ts:250–284`; `server/src/nextComment.ts:100–110,170` | Original bodies plus additional identities; `NextCommentFields::Ordinary` retains counts/randomN and raw bytes and requires a translations array (never absent or null); `ordinary_translations_require_an_array_and_preserve_bytes` covers both rejections and empty/nonempty arrays. See `server/src/nextComment.ts:420,464–508`. | +| Topical success | `server/src/nextComment.ts:353–357,420,464–508` | `topical-next-comment`; `topical_and_translated_selection_preserve_bytes`. Requires zid/tid/txt/translations, without ordinary counts/randomN. | +| Topical fallback | `server/src/nextComment.ts:325–350,366–370,413–417` | Empty agenda and exhausted pool cases; ordinary response shape. Selection failures also fall back; codec covers that same shape. | +| Translations | `server/src/nextComment.ts:464–508` | Stored nonempty translation case and explicit SQL-read failure; raw translation rows retained. A provider timeout is not recorded: the profile disables translation API calls and sealed egress forbids the real provider. The 300 ms response budget (`server/src/nextComment.ts:501`) can return the same empty/available rows; the topical/translated codec test covers those bodies, not provider timing. | +| No next statement | `server/src/routes/votes.ts:253–259` | `no-next-comment`; omit nextComment, never null. No modOptions: fresh result has no shouldMod. | +| Issued auth | `server/src/auth/ensure-participant.ts:667–671`; `server/src/auth/attach-auth-token.ts:45–64` | Fresh success plus fresh vote/star/next errors. Fixed Bearer and 31536000. `middleware_position_controls_auth_delivery` rejects different metadata. | +| Membership refusals | `server/src/auth/ensure-participant.ts:683–698`; `server/app.ts:1277–1287` | XID required/denied and Treevite 403/401 have no auth: injector is later. Codec rejects auth on every pre-injector failJson. | +| Parameter errors | `server/src/utils/parameter.ts:137,180–270,336` | Original invalid fields yield finalhandler 400; assigner exception 400 polis_err_misc is codec-only because normal JSON fields do not make the assigner throw. No auth on either. | +| Parser size | `server/app.ts:342` | `parser-body-too-large`: 413 and exact `Payload Too Large\n`. `pre_handler_transport_and_auth_envelopes`. | +| Parser media type | `server/app.ts:342` installs Connect JSON parsing | `parser-unsupported-charset` and `parser-unsupported-content-encoding`: real charset and Content-Encoding branches each return 415 and exact `Unsupported Media Type\n`, with no vote or participant added. `pre_handler_transport_and_auth_envelopes` and captured-byte roundtrips. | +| HTTPS policy | `server/src/utils/domain.ts:37–62` | 400 and exact `Please use HTTPS when submitting data.`; codec-only because this profile runs DEV_MODE and forwards HTTPS. No production-policy run is claimed. | +| Hybrid authentication | `server/src/auth/hybrid-jwt.ts:80–83,96–240` | Local expired/signature/issuer/audience variants and original invalid format. Optional missing Bearer continues; required-auth missing-token envelope is rejected by codec. | +| OIDC account errors | `server/src/auth/jwt-middleware.ts:104–160` | Mapping SQL failures record general 500 and both 429 branches through the real middleware, using explicit fault messages/codes. `account_envelopes_follow_their_producers` covers all five labels, exact messages and retry_after=1 only on 429. Details permitted only for user_creation_failed/authentication_error, in development mode. Missing-email is recorded with a provider-signed fixture token lacking email. Only the outer extraction catch is codec-only: plain JWT JSON cannot provoke an outer extraction exception. | +| Vote/star/next failure | `server/src/routes/votes.ts:88–94,244–250,288–307` | Original failures plus fresh-token and saved-star/failed-next cases. 500 polis_err_vote; 406 polis_err_vote_duplicate is SQLSTATE injection, not an ordinary revote. | +| Serialization failure | `server/src/server-helpers.ts:216–237` | Codec-only polis_err_finishing_response 500: normal Postgres/JSON rows cannot supply a cyclic value or throwing serializer without replacing response construction. | +| Unreachable catches | `server/src/routes/votes.ts:253,291–302`; `server/src/server-helpers.ts:197,232` | Fresh result has no zid; addConversationId resolves immediately. finishing_responseA and both legacy catches are cataloged in UNREACHABLE_ERRORS and rejected by codec. | + +## Identities and side effects + +The original six sequences are pid0, participant, locally issued standard, +signed XID, owner and admin. Each contains new/changed/repeated, moderated-out, +missing-comment and closed outcomes. Standard is not OIDC first contact; the +original foreign token is anonymous only. uid2 is the configured administrator. + +| Named gap | Additional evidence / remaining boundary | Source | +| --- | --- | --- | +| Distinct moderator and six outcomes | Site-sharing uid100004 with a database-allocated pid, different from owner/admin, all six outcomes. This route has no moderator bypass. | `server/src/utils/common.ts:89–99`; `server/src/routes/votes.ts:215–307` | +| First reply not retained, retry | Two anonymous successes deliberately discard the first credential before retry. This proves identity recreation, not TCP disconnection or unknown commit. | `server/src/auth/ensure-participant.ts:488–516,620–640` | +| Parser-refusal retry | First malformed star creates membership without delivered auth; retry without token creates another identity. | `server/app.ts:1277–1287` | +| Fresh handler-error token | Fresh anonymous insert, star and next failures; failures after injector carry auth. | `server/src/auth/attach-auth-token.ts:45–64` | +| Missing/revoked membership, valid token | Signed pid70 with no membership; separately mint a token for a database-allocated member, delete its row, then submit that still-valid token. Existing nonnegative token pid is trusted without lookup. | `server/src/auth/ensure-participant.ts:257–258` | +| Foreign standard | Retains uid, discards foreign pid, resolves membership and mints current-conversation token. | `server/src/auth/ensure-participant.ts:156–161,442–450` | +| Foreign XID, same/different owner | Both resolve the XID under the target owner; foreign uid/pid are discarded. | `server/src/auth/ensure-participant.ts:144–156`; `server/src/xids.ts:102` getXidRecord | +| Request XID overrides XID token | Conditional on xid_participant: explicit different XID resolves independently and mints a bound token. | `server/src/auth/ensure-participant.ts:452–459` | +| Blank/space/tab XID | Signed token XID restored after trim; anonymous whitespace has no XID. | `server/src/auth/ensure-participant.ts:424–431` | +| Existing signed XID removed from allowlist | 403 without auth, before membership lookup. | `server/src/auth/ensure-participant.ts:179–204,465` | +| Bare existing XID | Existing target-owner record and membership reused. | `server/src/auth/ensure-participant.ts:488–498` | +| Treevite existing-member lookup | No-pid standard, foreign standard and foreign XID; original case already carried pid and did not prove lookup. | `server/src/auth/ensure-participant.ts:542–549` | +| Treevite pid0 | Existing pid0 is accepted. | `server/src/auth/ensure-participant.ts:519,552` | +| Treevite new XID/standard/OIDC | All three nonmembers refused; newly created identities may remain without membership. | `server/src/auth/ensure-participant.ts:527–556` | +| Treevite owner without participation | Owner's first join in an empty conversation is allowed. | `server/src/auth/ensure-participant.ts:534–560` | +| Fresh privileged join | Owner above and fresh admin join; admin does not gain a Treevite bypass. | `server/src/auth/ensure-participant.ts:534–556,567–577` | +| Ordinary OIDC first account | Simulator-issued ordinary user maps account and joins, distinct from the locally signed standard token. | `server/src/auth/hybrid-jwt.ts:177–199`; `server/src/auth/create-user.ts:53–123` | +| Local expired/invalid/issuer/audience | Each of anonymous, standard and XID; actual hybrid response recorded. | `server/src/auth/jwt-utils.ts:225–244`; `server/src/auth/hybrid-jwt.ts:237–240` | +| OIDC expiry/invalid claims/JWKS rotation, expiry, failure | Provider-signed expired, wrong issuer/audience, bad signature and unpublished-key cases are recorded. Tokens use the isolated simulator’s own signing implementation, with no key copied to artifacts. The unpublished key triggers a real JWKS lookup and validation refusal. Key rotation, cache expiry and network timeout remain unrecorded: the provider has one fixed key, and the profile does not alter the validator cache clock or block provider traffic. The codec covers the resulting 401 envelope; this is not cache/availability qualification. | `server/src/auth/jwt-middleware.ts:36–61`; `server/src/auth/hybrid-jwt.ts:177–199,237–240` | +| Ignored pid/weight | Caller fields do not change pid or stored history weight. | `server/app.ts:1272–1288`; `server/src/routes/votes.ts:219–232` | +| Backdated replacement and existing weight | Future latest.modified is replaced by the new vote timestamp; nonzero latest weight remains 7. No vote value is directly changed by setup. | `server/postgres/migrations/000006_update_votes_rule.sql:8–13` | +| Star then next failure | One committed star and vote despite 500. | `server/src/routes/votes.ts:244–250` | +| Deferred operation failures | Opt-in P027_VOTES_DEFERRED_FAILURE fault cases exercise each of the three promises; failures are retained as failing oracles, never rewritten as successes. Normal corpus does not inject them. No contract response can promise that deferred work succeeded. | `server/src/routes/votes.ts:237–242`; `server/src/server-helpers.ts:425–451` | +| Actual response disconnect / unknown commit | Not recorded: runCase requires a completed response and compares drained effects. No codec can classify an absent response; there is no retry permission in this contract. | `server/src/routes/votes.ts:229–250` | + +The contract tests validate response shapes only for the source-only branches; +they do not simulate identity resolution or prove those branches executed. +The JWKS fetch remains a synchronous external dependency before voting. Reading +this contract adds no pool, lock, migration or slow work to participation. These +recordings do not waive participation load guards or prove resource isolation. diff --git a/server/characterization/votes/README.md b/server/characterization/votes/README.md new file mode 100644 index 000000000..ea83c8a5e --- /dev/null +++ b/server/characterization/votes/README.md @@ -0,0 +1,106 @@ +# POST votes characterization + +This profile records the existing Node route. It does not implement a writer, +change a route, or authorize migration. Votes use `semanticToWire` and the real +HTTP handler; there are no fixture INSERTs into vote tables. + +The profile reuses `runCase`, ordered wire records, verified JWT substitution, +database snapshots, effect drain, and the exact comparator. `control.cjs` runs +only with `P027_VOTES_PROFILE=1` in the isolated characterization entrypoint. +SQL failures are labeled controls, not natural application failures. Real auth, +membership, vote-convention and handler chains run throughout. + +The 72-case matrix covers anonymous first contact; pid zero, nonzero, standard, +XID, owner and admin identities; foreign, expired and invalid tokens; Treevite +membership and refusal; XID policy; vote changes and repeats; moderated-out and +missing comments; closed conversations; star and priority coercions; malformed +fields; no next comment; and explicit vote/star/next-selection SQL failures. +The six identity sequences use distinct existing comment keys. Each new-vote +case asserts a first latest-row insertion; later cases assert history appends +and current latest state. A fresh seed and server restart precede each run. + +`contract-cases.json` holds all 72 captured response bodies, with passing +recording oracles. Its Rust test decodes and re-encodes every body byte for byte. +Credential VALUES use verified symbols; surrounding whitespace, field order +and bytes remain intact. A fresh 72-case replay also matched ordered headers, +bodies, database and external effects with the existing comparator. +These are the declared matrix's coverage, not all possible HTTP/parser/provider +failures. The static error catalog distinguishes source-traced and unreachable +branches from live observations. The SQLSTATE duplicate case is injected; the +published history schema does not naturally enforce that uniqueness. + +The profile alone classifies an HTTPS Agent's idle TLSSocket timer as settled. +`idle-tls.cjs` retains the timer association and checks the socket is in the +Agent's free pool, absent from its active pool, and its request/response complete. +A reused active socket is pending again. Non-TLS sockets, unrelated timers, +SQL and provider operations do not qualify. Drain deadlines are unchanged. +The runtime test uses a real local TLS issuer, tests both strict and classified +barriers, and checks active reuse, an ordinary timer and explicit SQL work. +Both earlier cold-owner diagnostic controls remain in the delivery evidence. +A cold OIDC vote still performs the existing outbound JWKS request; this change +does not alter authentication or network behavior. + +Within the generated-data compose profile, run: + +```sh +docker compose -f server/characterization/compose.yml -f server/characterization/votes/compose.yml exec -T driver node --test characterization/votes/idle-tls.test.cjs +docker compose -f server/characterization/compose.yml -f server/characterization/votes/compose.yml exec -T driver node characterization/cli.cjs seed +docker compose -f server/characterization/compose.yml -f server/characterization/votes/compose.yml restart server +# Wait for the characterization ready endpoint before each run. +# Install provider-signed fixture tokens without writing them to disk: +docker compose -f server/characterization/compose.yml -f server/characterization/votes/compose.yml exec -T oidc-simulator node < server/characterization/votes/provider-tokens.cjs | docker compose -f server/characterization/compose.yml -f server/characterization/votes/compose.yml exec -T driver node characterization/votes/install-tokens.cjs +docker compose -f server/characterization/compose.yml -f server/characterization/votes/compose.yml exec -T driver node characterization/votes/run.cjs /artifacts/votes-record +# Seed and restart again, then replay: +docker compose -f server/characterization/compose.yml -f server/characterization/votes/compose.yml exec -T driver node characterization/votes/run.cjs /artifacts/votes-replay /artifacts/votes-record +``` + +Use a unique compose project and ports and the harness's internal network. +Source provenance comes from `P027_SOURCE_COMMIT`. No general-corpus admission +rule is widened for this separate profile. + +Latest-state behavior comes from `000006_update_votes_rule.sql`: every INSERT +appends history, then upserts vote/modified for `(zid,pid,tid)` without comparing +created times or updating the existing latest weight. high_priority exists on +history only. Star writes and next-comment selection follow that commit. +Both injected post-commit failures save a vote before HTTP 500; retry after the +next-comment failure appends again. No next comment means the field is omitted. +A failed response must not be treated as a safe retry signal. Mixed-writer load +qualification is still a separate prerequisite; no load result is claimed here. + +The original 72 bodies remain unchanged in `contract-cases.json`. Additional +cases are appended by `additional.cjs`; their captured bodies live separately +in `additional-cases.json`. See [COVERAGE.md](COVERAGE.md) for source references, +identity distinctions, unrecorded branches and codec-only evidence. + +The checked-in compose topology sends HTTP directly to Node (`P027_BASE_URL` +in `../compose.yml`); it has no deployment gateway. A direct run is not gateway +qualification. A separately supplied gateway must be identified in its evidence; +its presence cannot be inferred from a successful replay. + +Byte equality uses `../normalize.cjs` policy version 3 and `../wire.cjs`, through +`../compare.cjs`: JWT values are signature/binding verified then substituted; +typed capabilities and bound URLs are substituted lexically; original affected +Content-Length and ETag are checked before deriving replacement headers. Body +chunks are concatenated. Chunk boundaries, timing, date, connection, keep-alive +and provider metadata are excluded from equality. Ordered remaining headers, +body bytes and database effects are compared. Clocks and randomN remain exact. +This is not an unmodified TCP transcript. + +Additional identity bindings are declared from request credentials before the +response is decoded, including signed XID fallback and standard-user subjects. +They do not disable signature, issuer, audience, expiry, participant-row or +conversation verification. SQL-fault cases name the injected operation; they +exercise real middleware and route behavior after that dependency fails. + +Before each fresh run, restart the owned in-memory DynamoDB service as well as +seeding Postgres and restarting Node, then install the provider tokens again. +The additional fixture creates its two DynamoDB tables only after the original +72 cases. This keeps their initial topology and effects unchanged. + +To retain a failing deferred-write reproduction, set +`P027_VOTES_DEFERRED_FAILURE` on the driver to exactly one of +`deferred-conversation`, `deferred-participant`, or `deferred-count`. This selects +a single fault case; it retains the ordinary passing-oracle assertion and exits +nonzero if Node emits an unhandled rejection. Run each against a fresh seed and +server process, in a separate output directory. Never count these as green +recordings or discard their captured response/effects. diff --git a/server/characterization/votes/additional-cases.json b/server/characterization/votes/additional-cases.json new file mode 100644 index 000000000..6de2064fc --- /dev/null +++ b/server/characterization/votes/additional-cases.json @@ -0,0 +1,410 @@ +[ + { + "case": "moderator-new", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 3\",\"tid\":6,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":5.945560598745942,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":7}", + "recording_oracle_pass": true + }, + { + "case": "moderator-changed", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.7287952080368996,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":7}", + "recording_oracle_pass": true + }, + { + "case": "moderator-repeated", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":7.731962572783232,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":7}", + "recording_oracle_pass": true + }, + { + "case": "moderator-moderated-out", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 1\",\"tid\":4,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.175868894904852,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":7}", + "recording_oracle_pass": true + }, + { + "case": "moderator-missing-comment", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":6.416025808081031,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":7}", + "recording_oracle_pass": true + }, + { + "case": "moderator-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "lost-first-reply", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.4451679736375809,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":9,\"auth\":{\"token\":\"$jwt:fecc3bb8a54d811e99090147cb2fa2fd192642524f48de982191b05f51ad4789\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "lost-first-reply-retry-without-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 1\",\"tid\":4,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.791366457939148,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":10,\"auth\":{\"token\":\"$jwt:f036bae09edcc8e13f18e694a54cf1b4af3b877cdbc828a463009ef0b0e6f6da\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "fresh-parser-refusal", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "parser-refusal-retry-without-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 1\",\"tid\":4,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.6598544400185347,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":12,\"auth\":{\"token\":\"$jwt:96a355de6c25f982866d831ffa64c5333c90915537fb985ae442bf96981078d2\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "fresh-handler-error-auth", + "status": 500, + "body": "{\"error\":\"polis_err_vote\",\"message\":\"polis_err_vote\",\"status\":500,\"auth\":{\"token\":\"$jwt:8de4cf5b42fda6295003ed528cdaa952281bc660ff3ca6f2e582f12cb5093030\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "fresh-star-error-auth", + "status": 500, + "body": "{\"error\":\"polis_err_vote\",\"message\":\"polis_err_vote\",\"status\":500,\"auth\":{\"token\":\"$jwt:703323536124d38ea69b1dde6a7c6f1d9edcd7f8bccc9a0770e764f0c49d67d1\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "fresh-next-error-auth", + "status": 500, + "body": "{\"error\":\"polis_err_vote\",\"message\":\"polis_err_vote\",\"status\":500,\"auth\":{\"token\":\"$jwt:b3cf2db614be9978d03c930c28d9fd9d430457b5b4e0a6bd6c6fc0ce56c51c38\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "missing-membership-valid-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 3\",\"tid\":6,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":4.439899494871497,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":70}", + "recording_oracle_pass": true + }, + { + "case": "revoked-membership-valid-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement B\",\"tid\":1,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.4345246385782957,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":8}", + "recording_oracle_pass": true + }, + { + "case": "foreign-standard-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.5737164095044136,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2,\"auth\":{\"token\":\"$jwt:64b4ab092c122392a47a94012e839470f3a0a34260accd3aa9846b6550a5f509\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "foreign-xid-same-owner", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.671350329183042,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2,\"auth\":{\"token\":\"$jwt:ba44042502d5f77fffff3332e52baa5b985690b45ca322ac54905652d1853f0c\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "foreign-xid-different-owner", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.3820808436721563,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2,\"auth\":{\"token\":\"$jwt:ba44042502d5f77fffff3332e52baa5b985690b45ca322ac54905652d1853f0c\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "xid-request-overrides-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 3\",\"tid\":6,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":4.472501611337066,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":16,\"auth\":{\"token\":\"$jwt:f16aaf7c423cc141c53e2a815edf63a220389d56839aebecd7ed30e1caa27661\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "xid-blank-preserves-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.24504826683551073,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-whitespace-preserves-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated moderator statement\",\"tid\":9,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.989465515129268,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-tab-preserves-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.532578356564045,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "anonymous-blank-xid", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":6.15921669639647,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":17,\"auth\":{\"token\":\"$jwt:57d6cb05328aebca978458433e2c3cb2ca4a72b628dc3d91eb9a5fe3b3616372\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "signed-xid-removed-from-list", + "status": 403, + "body": "{\"error\":\"polis_err_xid_not_allowed\",\"message\":\"polis_err_xid_not_allowed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "bare-xid-existing-member", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated moderator statement\",\"tid\":9,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.5501168305054307,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2,\"auth\":{\"token\":\"$jwt:ba44042502d5f77fffff3332e52baa5b985690b45ca322ac54905652d1853f0c\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "treevite-lookup-without-pid", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated moderator statement\",\"tid\":9,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.666884991340339,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "treevite-foreign-standard-member", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated moderator statement\",\"tid\":9,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.106368969194591,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2,\"auth\":{\"token\":\"$jwt:64b4ab092c122392a47a94012e839470f3a0a34260accd3aa9846b6550a5f509\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "treevite-foreign-xid-member", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated moderator statement\",\"tid\":9,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.7218953128904104,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2,\"auth\":{\"token\":\"$jwt:ba44042502d5f77fffff3332e52baa5b985690b45ca322ac54905652d1853f0c\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "treevite-pid-zero", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated moderator statement\",\"tid\":9,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":5.095566085539758,\"remaining\":6,\"total\":9,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "treevite-new-xid", + "status": 401, + "body": "{\"error\":\"polis_err_treevite_auth_required\",\"message\":\"polis_err_treevite_auth_required\",\"status\":401}", + "recording_oracle_pass": true + }, + { + "case": "treevite-new-standard", + "status": 401, + "body": "{\"error\":\"polis_err_treevite_auth_required\",\"message\":\"polis_err_treevite_auth_required\",\"status\":401}", + "recording_oracle_pass": true + }, + { + "case": "treevite-new-oidc", + "status": 401, + "body": "{\"error\":\"polis_err_treevite_auth_required\",\"message\":\"polis_err_treevite_auth_required\",\"status\":401}", + "recording_oracle_pass": true + }, + { + "case": "oidc-first-contact", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 1\",\"tid\":4,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.7162996530532837,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":18}", + "recording_oracle_pass": true + }, + { + "case": "oidc-account-failure", + "status": 500, + "body": "{\"error\":\"user_creation_failed\",\"message\":\"Failed to create or map user account\",\"details\":\"generated recording SQL failure\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-account-conflict", + "status": 429, + "body": "{\"error\":\"authentication_conflict\",\"message\":\"Authentication system encountered a temporary conflict. Please try again.\",\"retry_after\":1}", + "recording_oracle_pass": true + }, + { + "case": "oidc-account-load", + "status": 429, + "body": "{\"error\":\"too_many_requests\",\"message\":\"Authentication system is experiencing high load. Please try again in a moment.\",\"retry_after\":1}", + "recording_oracle_pass": true + }, + { + "case": "anonymous-expired", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}", + "recording_oracle_pass": true + }, + { + "case": "anonymous-signature", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}", + "recording_oracle_pass": true + }, + { + "case": "anonymous-issuer", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt issuer invalid. expected: https://pol.is/\"}", + "recording_oracle_pass": true + }, + { + "case": "anonymous-audience", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt audience invalid. expected: participants\"}", + "recording_oracle_pass": true + }, + { + "case": "standard-expired", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}", + "recording_oracle_pass": true + }, + { + "case": "standard-signature", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}", + "recording_oracle_pass": true + }, + { + "case": "standard-issuer", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt issuer invalid. expected: https://pol.is/\"}", + "recording_oracle_pass": true + }, + { + "case": "standard-audience", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt audience invalid. expected: participants\"}", + "recording_oracle_pass": true + }, + { + "case": "xid-expired", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}", + "recording_oracle_pass": true + }, + { + "case": "xid-signature", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}", + "recording_oracle_pass": true + }, + { + "case": "xid-issuer", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt issuer invalid. expected: https://pol.is/\"}", + "recording_oracle_pass": true + }, + { + "case": "xid-audience", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt audience invalid. expected: participants\"}", + "recording_oracle_pass": true + }, + { + "case": "star-saved-before-next-failure", + "status": 500, + "body": "{\"error\":\"polis_err_vote\",\"message\":\"polis_err_vote\",\"status\":500}", + "recording_oracle_pass": true + }, + { + "case": "ignored-caller-pid-weight", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.0532677806913853,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "backdated-latest-replacement", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.512346007861197,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "retained-latest-weight", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.586590542457998,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "translated-next-comment", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 2\",\"tid\":5,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.937946015968919,\"remaining\":8,\"total\":9,\"translations\":[{\"zid\":1,\"tid\":5,\"src\":0,\"txt\":\"Texte traduit\",\"lang\":\"fr\",\"created\":\"1700000000000\",\"modified\":\"1700000000000\"}]},\"currentPid\":19,\"auth\":{\"token\":\"$jwt:f85c3e5e37023919a359ec0376b016899675c6520a8130bae303aa33b1c19fbd\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "translation-read-fallback", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 2\",\"tid\":5,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.118407469242811,\"remaining\":8,\"total\":9,\"translations\":[]},\"currentPid\":20,\"auth\":{\"token\":\"$jwt:555048a0624e394ee50b2e2b7ab921990cddb00ce58acfa7370880615563c330\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "topical-next-comment", + "status": 200, + "body": "{\"nextComment\":{\"zid\":1,\"tid\":1,\"txt\":\"Generated statement B\",\"translations\":[]},\"currentPid\":7}", + "recording_oracle_pass": true + }, + { + "case": "topical-empty-agenda-fallback", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated moderator statement\",\"tid\":9,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.8279955610632896,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "topical-exhausted-fallback", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.7232847986742854,\"remaining\":4,\"total\":9,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "treevite-owner-without-membership", + "status": 200, + "body": "{\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "fresh-admin-join", + "status": 200, + "body": "{\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "oidc-missing-email", + "status": 400, + "body": "{\"error\":\"invalid_user_data\",\"message\":\"User account is missing required information (email).\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-expired", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-issuer", + "status": 401, + "body": "{\"error\":\"Invalid token format\",\"details\":\"Token does not match any supported JWT type\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-audience", + "status": 401, + "body": "{\"error\":\"Invalid token format\",\"details\":\"Token does not match any supported JWT type\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-signature", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-unknown-key", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"Unable to find a signing key that matches 'generated-unpublished-key'\"}", + "recording_oracle_pass": true + }, + { + "case": "parser-body-too-large", + "status": 413, + "body": "Payload Too Large\n", + "recording_oracle_pass": true + }, + { + "case": "parser-unsupported-charset", + "status": 415, + "body": "Unsupported Media Type\n", + "recording_oracle_pass": true + }, + { + "case": "parser-unsupported-content-encoding", + "status": 415, + "body": "Unsupported Media Type\n", + "recording_oracle_pass": true + } +] diff --git a/server/characterization/votes/additional.cjs b/server/characterization/votes/additional.cjs new file mode 100644 index 000000000..eb5544a96 --- /dev/null +++ b/server/characterization/votes/additional.cjs @@ -0,0 +1,136 @@ +"use strict"; +// Additional cases run after the original corpus so its inputs and ordering stay +// unchanged. All response evidence comes from the real HTTP recorder. +const assert = require('node:assert/strict'); +let moderatorPid; +exports.cases = (add, convention) => { + for (const outcome of ['new','changed','repeated','moderated-out','missing-comment','closed']) { + add('moderator-'+outcome,'site-moderator',{ + tid:outcome==='moderated-out'?2:outcome==='missing-comment'?999:9, + ...(['changed','repeated'].includes(outcome)?{vote:convention.semanticToWire('disagree')}:{}) + },outcome==='closed'?403:200,outcome==='closed'?'closed':null); + } + add('lost-first-reply','unauthenticated'); + add('lost-first-reply-retry-without-token','unauthenticated'); + add('fresh-parser-refusal','unauthenticated',{starred:'yes'},400); + add('parser-refusal-retry-without-token','unauthenticated'); + add('fresh-handler-error-auth','unauthenticated',{},500,null,'vote'); + add('fresh-star-error-auth','unauthenticated',{starred:true},500,null,'star'); + add('fresh-next-error-auth','unauthenticated',{},500,null,'next'); + add('missing-membership-valid-token','missing-member'); + add('revoked-membership-valid-token','revoked-member',{},200,'revoked-member'); + add('foreign-standard-token','foreign-standard'); + add('foreign-xid-same-owner','foreign-xid'); + add('foreign-xid-different-owner','foreign-xid-other-owner'); + add('xid-request-overrides-token','xid',{xid:'generated-override'}); + add('xid-blank-preserves-token','xid',{xid:''}); + add('xid-whitespace-preserves-token','xid',{xid:' '}); + add('xid-tab-preserves-token','xid',{xid:'\t'}); + add('anonymous-blank-xid','unauthenticated',{xid:' '}); + add('signed-xid-removed-from-list','xid',{},403,'removed-whitelist'); + add('bare-xid-existing-member','unauthenticated',{xid:'generated-member'}); + add('treevite-lookup-without-pid','standard-no-pid',{},200,'treevite'); + add('treevite-foreign-standard-member','foreign-standard',{},200,'treevite'); + add('treevite-foreign-xid-member','foreign-xid',{},200,'treevite'); + add('treevite-pid-zero','pid0',{},200,'treevite'); + add('treevite-new-xid','unauthenticated',{xid:'generated-treevite-new'},401,'treevite'); + add('treevite-new-standard','standard-nonmember',{},401,'treevite'); + add('treevite-new-oidc','comments-owner-1',{},401,'treevite'); + add('oidc-first-contact','comments-owner-2'); + add('oidc-account-failure','comments-owner-2',{},500,null,'account'); + add('oidc-account-conflict','comments-owner-2',{},429,null,'account-conflict'); + add('oidc-account-load','comments-owner-2',{},429,null,'account-load'); + for(const kind of ['anonymous','standard','xid']) for(const fault of ['expired','signature','issuer','audience']) + add(kind+'-'+fault,kind+'-'+fault,{},401); + add('star-saved-before-next-failure','participant',{starred:true},500,null,'next'); + add('ignored-caller-pid-weight','participant',{pid:80,weight:123,weight_x_32767:123}); + add('backdated-latest-replacement','participant',{},200,'backdated'); + add('retained-latest-weight','participant',{},200,'latest-weight'); + add('translated-next-comment','unauthenticated',{lang:'fr'},200,'translations'); + add('translation-read-fallback','unauthenticated',{lang:'fr'},200,null,'translation-read'); + add('topical-next-comment','site-moderator',{},200,'topical'); + add('topical-empty-agenda-fallback','participant',{},200,'topical-empty'); + add('topical-exhausted-fallback','participant',{},200,'topical-exhausted'); + // Deliberately red on this source pin: each returns HTTP 200 and commits one + // vote, then deferred bookkeeping writes emit an unhandledRejection. The + // vote-path work fixes these writes; run.cjs:128's oracle assertion stays intact. + if(process.env.P027_VOTES_DEFERRED_FAILURE) { + add('deferred-conversation-failure','participant',{},200,null,'deferred-conversation'); + add('deferred-participant-failure','participant',{},200,null,'deferred-participant'); + add('deferred-count-failure','participant',{},200,null,'deferred-count'); + } + add('treevite-owner-without-membership','owner',{conversation_id:'2generatedempty'},200,'treevite-cold-owner'); + add('fresh-admin-join','admin',{conversation_id:'2generatedempty'},200,'cold-admin'); + add('oidc-missing-email','oidc-missing-email',{},400); + for(const kind of ['expired','issuer','audience','signature','unknown-key']) add('oidc-'+kind,'oidc-'+kind,{},401); + // Real parser rejection; the input exceeds the server's 50 MiB limit. + add('parser-body-too-large','participant',{padding:' '.repeat(50*1024*1024)},413); + add('parser-unsupported-charset','participant',{},415,null,null,{'content-type':'application/json; charset=iso-8859-1'}); + add('parser-unsupported-content-encoding','participant',{},415,null,null,{'content-encoding':'unsupported'}); +}; +exports.initialize = async (pool) => { + await pool.query("INSERT INTO users(uid,hname,site_id) VALUES(100004,'Generated moderator','p027-owner'),(100005,'Generated nonmember','generated-site'),(100006,'Generated removed member','generated-site')"); + const moderator=await pool.query('INSERT INTO participants(zid,uid,created) VALUES(1,100004,1700000000000) RETURNING pid'); + moderatorPid=moderator.rows[0].pid; + const removed=await pool.query('INSERT INTO participants(zid,uid,created) VALUES(1,100006,1700000000000) RETURNING pid'); + await pool.query("INSERT INTO comments(zid,pid,uid,txt,lang,created,modified,mod) VALUES(1,0,1,'Generated moderator statement','en',1700000000000,1700000000000,0)"); + await pool.query("INSERT INTO conversations(zid,owner,topic,is_active) VALUES(3,100004,'Generated other owner',true),(4,1,'Generated no members',true)"); + await pool.query("INSERT INTO zinvites(zid,zinvite) VALUES(3,'2generatedotherowner'),(4,'2generatedempty')"); + return {moderatorPid,removedPid:removed.rows[0].pid}; +}; +exports.setup = async (kind, pool, get) => { + await get('/votes-mode?topical='+(kind?.startsWith('topical')?'1':'0')); + if (kind==='removed-whitelist') { + await pool.query('UPDATE conversations SET use_xid_whitelist=true WHERE zid=1'); + await pool.query("DELETE FROM xid_whitelist WHERE owner=1 AND xid='generated-member'"); + } + if(kind==='revoked-member') { + await pool.query('DELETE FROM participants WHERE zid=1 AND uid=100006'); + } + if(kind==='treevite-cold-owner'||kind==='cold-admin') await pool.query('UPDATE conversations SET treevite_enabled=$1 WHERE zid=4',[kind==='treevite-cold-owner']); + if (kind==='backdated') await pool.query('UPDATE votes_latest_unique SET modified=1700000001000 WHERE zid=1 AND pid=2 AND tid=0'); + if (kind==='latest-weight') await pool.query('UPDATE votes_latest_unique SET weight_x_32767=7 WHERE zid=1 AND pid=2 AND tid=0'); + if (kind==='translations') await pool.query("INSERT INTO comment_translations(zid,tid,txt,lang,src,created,modified) SELECT zid,tid,'Texte traduit','fr',0,1700000000000,1700000000000 FROM comments WHERE zid=1"); + if (kind?.startsWith('topical')) { + const {DynamoDBClient,CreateTableCommand,PutItemCommand}=require('@aws-sdk/client-dynamodb'); + const client=new DynamoDBClient({endpoint:process.env.DYNAMODB_ENDPOINT,region:'us-east-1',credentials:{accessKeyId:'generatedlocal',secretAccessKey:'generatedlocal'}}); + try { + for(const table of ['Delphi_CommentClustersLLMTopicNames','Delphi_CommentHierarchicalClusterAssignments']) { + try { await client.send(new CreateTableCommand({TableName:table,...require('../dynamo-schema.json').tables[table]})); } + catch(e) { if(e.name!=='ResourceInUseException') throw e; } + } + await client.send(new PutItemCommand({TableName:'Delphi_CommentClustersLLMTopicNames',Item:{conversation_id:{S:'1'},topic_key:{S:'generated-topic'},layer_id:{N:'0'},cluster_id:{N:'1'}}})); + await client.send(new PutItemCommand({TableName:'Delphi_CommentHierarchicalClusterAssignments',Item:{conversation_id:{S:'1'},comment_id:{N:kind==='topical-exhausted'?'0':'1'},layer0_cluster_id:{N:'1'}}})); + // The existing moderator has an unvoted statement in this topic. + const pid=kind==='topical' ? moderatorPid : 2; + await pool.query('INSERT INTO topic_agenda_selections(zid,pid,archetypal_selections,delphi_job_id) VALUES(1,$1,$2,$3) ON CONFLICT(zid,pid) DO UPDATE SET archetypal_selections=EXCLUDED.archetypal_selections',[pid,JSON.stringify(kind==='topical-empty'?[]:[{topic_key:'generated-topic'}]),'generated-job']); + } finally { client.destroy(); } + } +}; +exports.check = (spec,r,after) => { + if(spec.status===415) { + assert.equal(r.response.body,'Unsupported Media Type\n'); + assert.equal(r.voteProof.historyAdded,0); + assert.equal(r.effects.participantCreated,0); + } + if(spec.name.startsWith('moderator-')&&spec.status===200) { + assert.equal(r.response.body.currentPid,moderatorPid); + assert.ok(after['pg:participants'].some(p=>p.zid===1&&p.pid===moderatorPid&&p.uid===100004)); + } + if(spec.name==='topical-next-comment') { + assert.equal(r.response.body.nextComment.tid,1); + assert.equal(r.response.body.nextComment.zid,1); + for(const key of ['remaining','total','randomN']) assert.equal(Object.hasOwn(r.response.body.nextComment,key),false); + } + if(spec.name.startsWith('topical-')&&spec.name.endsWith('fallback')) assert.equal(typeof r.response.body.nextComment.remaining,'number'); + if(spec.name==='translated-next-comment') assert.ok(r.response.body.nextComment.translations.length>0); + if(spec.name.startsWith('fresh-')&&spec.name.endsWith('-auth')) assert.ok(r.response.body.auth); + if(spec.name==='fresh-parser-refusal') assert.equal(r.effects.participantCreated,1); + if(spec.name==='star-saved-before-next-failure') assert.equal(r.effects.db['pg:stars'].added.length,1); + if(spec.name==='retained-latest-weight') assert.equal(after['pg:votes_latest_unique'].find(v=>v.zid===1&&v.pid===2&&v.tid===0).weight_x_32767,7); + if(spec.name==='ignored-caller-pid-weight') { + assert.equal(r.voteProof.historyAdded,1); + assert.equal(r.effects.db['pg:votes'].added[0].pid,2); + assert.equal(r.effects.db['pg:votes'].added[0].weight_x_32767,0); + } +}; diff --git a/server/characterization/votes/compose.yml b/server/characterization/votes/compose.yml new file mode 100644 index 000000000..579b77718 --- /dev/null +++ b/server/characterization/votes/compose.yml @@ -0,0 +1,4 @@ +services: + server: + environment: + P027_VOTES_PROFILE: "1" diff --git a/server/characterization/votes/contract-cases.json b/server/characterization/votes/contract-cases.json new file mode 100644 index 000000000..e3b13deae --- /dev/null +++ b/server/characterization/votes/contract-cases.json @@ -0,0 +1,434 @@ +[ + { + "case": "anonymous-first", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.112874258076772,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":3,\"auth\":{\"token\":\"$jwt:8123d1d96d13e926fe16bf4ef6afe8467107ba5185af5c1e2b46edb0a8de399f\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "pid0-new", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":5.828463755082339,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-changed", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":6.609784686937928,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-repeated", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 1\",\"tid\":4,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.1951061030849814,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-moderated-out", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":6.337324131978676,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-missing-comment", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 2\",\"tid\":5,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.2020552253816277,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "participant-new", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement A\",\"tid\":0,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.2029235998634249,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-changed", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement A\",\"tid\":0,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.8732665081042796,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-repeated", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.777415480464697,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-moderated-out", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 2\",\"tid\":5,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.920147249242291,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-missing-comment", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":6.63758784905076,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "standard-new", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 3\",\"tid\":6,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.312350075226277,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-changed", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 3\",\"tid\":6,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.2251244159415364,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-repeated", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":4.388390659354627,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-moderated-out", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":5.560576517600566,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-missing-comment", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 3\",\"tid\":6,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.592354732565582,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "xid-new", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":3.2549573422875255,\"remaining\":5,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-changed", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement B\",\"tid\":1,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.2880198820494115,\"remaining\":5,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-repeated", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.8468313382472843,\"remaining\":5,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-moderated-out", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":4.726128152105957,\"remaining\":5,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-missing-comment", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement A\",\"tid\":0,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.04368971916846931,\"remaining\":5,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "owner-new", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":5.174153212923557,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-changed", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 5\",\"tid\":8,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":5.395857783034444,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-repeated", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement A\",\"tid\":0,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.36438696971163154,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-moderated-out", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement A\",\"tid\":0,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.8500022878870368,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-missing-comment", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 3\",\"tid\":6,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":4.626847336068749,\"remaining\":6,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "admin-new", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement B\",\"tid\":1,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.261453143786639,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-changed", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 2\",\"tid\":5,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":4.376307199243456,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-repeated", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":6.5522221371065825,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-moderated-out", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement B\",\"tid\":1,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.6764576942659914,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-missing-comment", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":6.49618799961172,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "foreign-conversation-token", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":5.220504785655066,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":4,\"auth\":{\"token\":\"$jwt:780c26a4be383fee80afa1ca6eadd798e71d00c626f0c7956c3d174a102dcf46\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "expired-token", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}", + "recording_oracle_pass": true + }, + { + "case": "invalid-token-format", + "status": 401, + "body": "{\"error\":\"Invalid token format\",\"details\":\"Token does not match any supported JWT type\"}", + "recording_oracle_pass": true + }, + { + "case": "invalid-signature", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}", + "recording_oracle_pass": true + }, + { + "case": "treevite-member", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement B\",\"tid\":1,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.6366801131516695,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "treevite-owner", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated statement B\",\"tid\":1,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.28910759603604674,\"remaining\":5,\"total\":8,\"translations\":[]},\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "treevite-new-anonymous", + "status": 401, + "body": "{\"error\":\"polis_err_treevite_auth_required\",\"message\":\"polis_err_treevite_auth_required\",\"status\":401}", + "recording_oracle_pass": true + }, + { + "case": "xid-required", + "status": 403, + "body": "{\"error\":\"polis_err_xid_required\",\"message\":\"polis_err_xid_required\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "xid-first-contact", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":5.403491917531937,\"remaining\":7,\"total\":8,\"translations\":[]},\"currentPid\":5,\"auth\":{\"token\":\"$jwt:bb839ee98d40a2b6c5f177cc4b4b0655990543abd21ca7d530927f42440756ca\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "xid-allowed", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.717525489628315,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-denied", + "status": 403, + "body": "{\"error\":\"polis_err_xid_not_allowed\",\"message\":\"polis_err_xid_not_allowed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "star-true", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.694807194173336,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "star-false", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.733730649575591,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "star-repeat", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.4739013807848096,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "star-null", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 4\",\"tid\":7,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":2.829334800131619,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "star-numeric", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.462148081511259,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "star-string", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.8437822936102748,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "star-invalid", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "priority-invalid", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "prefix-integers", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.569366866722703,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "fractional-tid", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "missing-tid", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "missing-vote", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "invalid-vote", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "invalid-conversation", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "missing-conversation", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "invalid-xid", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "invalid-lang", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "lang-empty", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":1.9316071514040232,\"remaining\":4,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "no-next-comment", + "status": 200, + "body": "{\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "vote-failure", + "status": 500, + "body": "{\"error\":\"polis_err_vote\",\"message\":\"polis_err_vote\",\"status\":500}", + "recording_oracle_pass": true + }, + { + "case": "duplicate-sqlstate", + "status": 406, + "body": "{\"error\":\"polis_err_vote_duplicate\",\"message\":\"polis_err_vote_duplicate\",\"status\":406}", + "recording_oracle_pass": true + }, + { + "case": "star-failure-after-commit", + "status": 500, + "body": "{\"error\":\"polis_err_vote\",\"message\":\"polis_err_vote\",\"status\":500}", + "recording_oracle_pass": true + }, + { + "case": "next-failure-after-commit", + "status": 500, + "body": "{\"error\":\"polis_err_vote\",\"message\":\"polis_err_vote\",\"status\":500}", + "recording_oracle_pass": true + }, + { + "case": "retry-after-next-failure", + "status": 200, + "body": "{\"nextComment\":{\"txt\":\"Generated identity statement 0\",\"tid\":3,\"created\":\"1700000000000\",\"quote_src_url\":null,\"is_seed\":false,\"is_meta\":false,\"lang\":\"en\",\"pid\":0,\"original_id\":null,\"randomN\":0.9368339048232883,\"remaining\":3,\"total\":8,\"translations\":[]},\"currentPid\":2}", + "recording_oracle_pass": true + } +] diff --git a/server/characterization/votes/control.cjs b/server/characterization/votes/control.cjs new file mode 100644 index 000000000..40436fce7 --- /dev/null +++ b/server/characterization/votes/control.cjs @@ -0,0 +1,115 @@ +"use strict"; +// Harness-only SQL failure injection. The real route, auth, convention module +// and database statements remain unchanged. Each fault is explicit in evidence. +exports.install = (state, pair) => { + const { Client } = require("pg"); + const query = Client.prototype.query; + let fault = null, fired = 0, providerTokens = {}; + Client.prototype.query = function (...args) { + const sql = typeof args[0] === "string" ? args[0] : args[0]?.text || ""; + const matches = { + next: /get_visible_comments/i, + star: /insert into stars/i, + vote: /insert into votes \(/i, + duplicate: /insert into votes \(/i, + account: /SELECT uid FROM oidc_user_mappings WHERE oidc_sub/i, + "account-conflict": /SELECT uid FROM oidc_user_mappings WHERE oidc_sub/i, + "account-load": /SELECT uid FROM oidc_user_mappings WHERE oidc_sub/i, + "translation-read": /select \* from comment_translations/i, + "deferred-conversation": /update conversations set modified/i, + "deferred-participant": /update participants set last_interaction/i, + "deferred-count": /update participants set vote_count/i, + }; + if (fault && matches[fault].test(sql)) { + const kind = fault; + fault = null; + fired++; + const error = Object.assign(new Error(kind === "account-load" ? "generated high concurrency" : "generated recording SQL failure"), { + code: ["duplicate", "account-conflict"].includes(kind) ? "23505" : "XX000", + }); + const callback = args.at(-1); + if (typeof callback === "function") { + queueMicrotask(() => callback(error)); + return; + } + return Promise.reject(error); + } + return query.apply(this, args); + }; + return async (req, res) => { + const url = new URL(req.url, "http://localhost"); + if (url.pathname === "/votes-provider-tokens" && req.method === "POST") { + const chunks = []; + for await (const chunk of req) chunks.push(chunk); + providerTokens = JSON.parse(Buffer.concat(chunks).toString()); + if (!Object.keys(providerTokens).every(key => key.startsWith("oidc-"))) + throw Error("unexpected provider fixture name"); + res.end("{}"); + return true; + } + if (url.pathname === "/votes-mode") { + process.env.TOPICAL_COMMENT_RATIO = url.searchParams.get("topical") === "1" ? "1" : "0"; + res.end("{}"); + return true; + } + if (url.pathname === "/votes-fault") { + const kind = url.searchParams.get("kind"); + if (!["next", "star", "vote", "duplicate", "account", "account-conflict", "account-load", "translation-read", "deferred-conversation", "deferred-participant", "deferred-count", "none"].includes(kind)) + throw Error("unknown vote recording fault"); + fault = kind === "none" ? null : kind; + fired = 0; + res.end("{}"); + return true; + } + if (url.pathname === "/votes-fault-state") { + res.end(JSON.stringify({ armed: fault, fired })); + return true; + } + if (url.pathname !== "/votes-tokens") return false; + const anon = require("../../src/auth/anonymous-jwt.ts").issueAnonymousJWT; + const xid = require("../../src/auth/xid-jwt.ts").issueXidJWT; + const standard = require("../../src/auth/standard-user-jwt.ts").issueStandardUserJWT; + const token = anon("2p027generated", 3, 2); + const claims = JSON.parse(Buffer.from(token.split(".")[1], "base64url")); + claims.iat -= 31536001; + claims.exp -= 31536001; + const signed = (original, changes) => require("jsonwebtoken").sign({ + ...JSON.parse(Buffer.from(original.split(".")[1], "base64url")), + ...changes, + }, pair.privateKey, { algorithm: "RS256" }); + const localTokens = { + anonymous: token, + standard: standard("generated-standard", "2p027generated", 3, 2), + xid: xid("generated-member", "2p027generated", 3, 2), + }; + const invalid = Object.fromEntries(Object.entries(localTokens).flatMap(([kind, value]) => [ + [kind + "-expired", signed(value, { exp: 1 })], + [kind + "-issuer", signed(value, { iss: "https://invalid.example/" })], + [kind + "-audience", signed(value, { aud: "generated-other" })], + [kind + "-signature", value.slice(0, value.lastIndexOf(".") + 1) + "generated"], + ])); + res.end(JSON.stringify({ + ...providerTokens, + ...invalid, + "site-moderator": standard("generated-moderator", "2p027generated", 100004, Number(url.searchParams.get("moderatorPid") || 80)), + "revoked-member": anon("2p027generated", 100006, Number(url.searchParams.get("removedPid") || 70)), + "standard-no-pid": signed(localTokens.standard, { pid: undefined }), + "foreign-standard": standard("generated-standard", "2p027foreign", 3, 2), + "foreign-xid": xid("generated-member", "2p027foreign", 3, 2), + "foreign-xid-other-owner": xid("generated-member", "2generatedotherowner", 100004, 0), + "standard-nonmember": standard("generated-nonmember", "2p027generated", 100005, -1), + "missing-member": anon("2p027generated", 100006, 70), + "missing-member-zero": anon("2generatedempty", 100006, 0), + pid0: anon("2p027generated", 1, 0), + participant: token, + standard: standard("generated-standard", "2p027generated", 3, 2), + xid: xid("generated-member", "2p027generated", 3, 2), + foreign: anon("2p027foreign", 3, 2), + expired: require("jsonwebtoken").sign(claims, pair.privateKey, { algorithm: "RS256" }), + bad: "generated-invalid-token", + signature: token.slice(0, token.lastIndexOf(".") + 1) + "generated", + publicKey: pair.publicKey, + })); + return true; + }; +}; diff --git a/server/characterization/votes/diagnose.cjs b/server/characterization/votes/diagnose.cjs new file mode 100644 index 000000000..56191c573 --- /dev/null +++ b/server/characterization/votes/diagnose.cjs @@ -0,0 +1,16 @@ +'use strict'; +require('ts-node/register/transpile-only'); +const fs=require('node:fs'); +const recorder=require('../cli.cjs'); +const {Normalizer}=require('../normalize.cjs'); +const {semanticToWire}=require('../../src/votes/convention.ts'); +async function get(p){return (await fetch(process.env.P027_CONTROL_URL+p)).json();} +async function main(){ + const tokens={...await get('/tokens'),...await get('/votes-tokens')}; + const tables=[...new Set((await recorder.schema()).map(r=>r.table_name))]; + const r=await recorder.runCase({caseId:'post-votes/owner-cold-diagnostic',case:'owner-cold-diagnostic',auth:'owner',seed:'abcdef123456',request:{method:'POST',path:'/api/v3/votes',query:{},headers:{'content-type':'application/json','x-forwarded-proto':'https',authorization:'$auth:owner'},body:{conversation_id:'2p027generated',tid:0,vote:semanticToWire('agree')}}},tokens,tables,new Normalizer()); + fs.writeFileSync('/artifacts/votes-owner-diagnostic.json',JSON.stringify(r,null,2)+'\n'); + console.log(JSON.stringify({status:r.response.status,oracle:r.oracle,work:r.unsettledWork})); + if(!r.oracle.pass)process.exitCode=1; +} +main().catch(e=>{console.error(e);process.exitCode=1;}).finally(recorder.close); diff --git a/server/characterization/votes/idle-tls.cjs b/server/characterization/votes/idle-tls.cjs new file mode 100644 index 000000000..02952da64 --- /dev/null +++ b/server/characterization/votes/idle-tls.cjs @@ -0,0 +1,36 @@ +"use strict"; +// Recording-profile accounting only. An Agent's idle TLS socket cannot mutate +// the request. Keep its timer tracked so reuse immediately makes it pending. +const https = require("node:https"); +const { TLSSocket } = require("node:tls"); +function install() { + const timers = new WeakMap(); + const original = https.Agent.prototype.keepSocketAlive; + https.Agent.prototype.keepSocketAlive = function (socket) { + const kept = original.call(this, socket); + if (kept && socket instanceof TLSSocket) { + for (const symbol of Object.getOwnPropertySymbols(socket)) { + const timer = socket[symbol]; + if ( + symbol.description === "timeout" && + timer && typeof timer._onTimeout === "function" + ) timers.set(timer, { socket, agent: this }); + } + } + return kept; + }; + const settled = (kind, resource) => { + if (kind !== "Timeout" || !resource) return false; + const found = timers.get(resource); + if (!found) return false; + const { socket, agent } = found; + const free = Object.values(agent.freeSockets).some(xs => xs.includes(socket)); + const active = Object.values(agent.sockets).some(xs => xs.includes(socket)); + const request = socket._httpMessage; + return free && !active && !socket.destroyed && + (!request || (request.finished && request.res?.complete === true)); + }; + settled.restore = () => { https.Agent.prototype.keepSocketAlive = original; }; + return settled; +} +module.exports = { install }; diff --git a/server/characterization/votes/idle-tls.test.cjs b/server/characterization/votes/idle-tls.test.cjs new file mode 100644 index 000000000..a30473b9f --- /dev/null +++ b/server/characterization/votes/idle-tls.test.cjs @@ -0,0 +1,58 @@ +"use strict"; +const test = require("node:test"); +const assert = require("node:assert/strict"); +const https = require("node:https"); +const { createBarrier } = require("../barrier.cjs"); +const { install } = require("./idle-tls.cjs"); +const tick = () => new Promise(resolve => setImmediate(resolve)); + +test("only an idle completed TLS Agent timer settles; reuse remains pending", async () => { + const classify = install(); + const barrier = createBarrier(() => false, classify); + const strict = createBarrier(); + const agent = new https.Agent({ keepAlive: true, timeout: 4000 }); + let timer; + try { + await strict.run("strict", () => barrier.run("owner", () => + new Promise((resolve, reject) => { + https.get("https://oidc-simulator:3000/.well-known/jwks.json", { agent }, res => { + res.resume(); + res.on("end", resolve); + }).on("error", reject); + }) + )); + await tick(); + assert.ok(strict.state("strict").pending.some(x => x.kind === "Timeout")); + assert.deepEqual(barrier.state("owner").pending, []); + const socket = Object.values(agent.freeSockets).flat()[0]; + assert.ok(socket); + // Reuse the actual idle socket; while its next response is paused, its + // request timeout must be pending even though keepSocketAlive saw it before. + await barrier.run("second", () => new Promise((resolve, reject) => { + https.get("https://oidc-simulator:3000/.well-known/jwks.json", { agent }, res => { + try { + assert.equal(res.socket, socket); + assert.ok([...barrier.state("owner").pending, ...barrier.state("second").pending] + .some(x => x.kind === "Timeout")); + res.resume(); + res.on("end", resolve); + } catch (e) { res.resume(); reject(e); } + }).on("error", reject); + })); + await tick(); + assert.deepEqual(barrier.state("second").pending, []); + barrier.run("ordinary", () => { timer = setTimeout(() => {}, 4000); }); + assert.equal(barrier.state("ordinary").pending.length, 1); + const finish = barrier.run("sql", () => barrier.start("postgres")); + assert.equal(barrier.state("sql").pending.length, 1); + finish(); + assert.equal(barrier.finish("owner"), "request-effects-drained"); + assert.equal(barrier.finish("second"), "request-effects-drained"); + } finally { + clearTimeout(timer); + agent.destroy(); + barrier.close(); + strict.close(); + classify.restore(); + } +}); diff --git a/server/characterization/votes/install-tokens.cjs b/server/characterization/votes/install-tokens.cjs new file mode 100644 index 000000000..4286b0424 --- /dev/null +++ b/server/characterization/votes/install-tokens.cjs @@ -0,0 +1,11 @@ +"use strict"; +// Pipe simulator test tokens directly to the owned observer; never persist them. +(async () => { + const chunks = []; + for await (const chunk of process.stdin) chunks.push(chunk); + const response = await fetch(process.env.P027_CONTROL_URL + "/votes-provider-tokens", { + method: "POST", body: Buffer.concat(chunks), + }); + if (!response.ok) throw Error("provider fixture installation failed"); + console.log("provider fixtures installed"); +})().catch(error => { console.error(error); process.exitCode = 1; }); diff --git a/server/characterization/votes/provider-tokens.cjs b/server/characterization/votes/provider-tokens.cjs new file mode 100644 index 000000000..e35851e42 --- /dev/null +++ b/server/characterization/votes/provider-tokens.cjs @@ -0,0 +1,22 @@ +"use strict"; +// Run on stdin in the isolated simulator container. Use its own test signing +// implementation without copying a key into the source, artifacts or logs. +const { createJsonWebToken } = require("@simulacrum/auth0-simulator/dist/auth/jwt.js"); +const claims = { + iss: "https://oidc-simulator:3000/", aud: "users", + sub: "generated-oidc-vote-fixture", email: "generated-oidc@example.invalid", + iat: 1699999999, exp: 1700086400, +}; +const valid = createJsonWebToken(claims); +const missingEmail = { ...claims, sub: "generated-oidc-no-email" }; +delete missingEmail.email; +process.stdout.write(JSON.stringify({ + "oidc-missing-email": createJsonWebToken(missingEmail), + "oidc-expired": createJsonWebToken({ ...claims, exp: 1 }), + "oidc-issuer": createJsonWebToken({ ...claims, iss: "https://invalid.example/" }), + "oidc-audience": createJsonWebToken({ ...claims, aud: "generated-other" }), + "oidc-signature": valid.slice(0, valid.lastIndexOf(".") + 1) + "generated", + "oidc-unknown-key": createJsonWebToken(claims, undefined, { + algorithm: "RS256", keyid: "generated-unpublished-key", + }), +})); diff --git a/server/characterization/votes/run.cjs b/server/characterization/votes/run.cjs new file mode 100644 index 000000000..9f37675b2 --- /dev/null +++ b/server/characterization/votes/run.cjs @@ -0,0 +1,166 @@ +"use strict"; +// Uses the characterization recorder's real transport, snapshots, effect drain, +// JWT verification, exact byte comparator and egress admission. The votes +// profile separately classifies completed idle TLS sockets at the drain barrier. +require('ts-node/register/transpile-only'); +const fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict'); +const {Pool}=require('pg'); +const recorder=require('../cli.cjs'); +const {Normalizer}=require('../normalize.cjs'); +const {hash}=require('../core.cjs'); +const {records,put,pin}=require('../recording.cjs'); +const {firstDifference}=require('../compare.cjs'); +const convention=require('../../src/votes/convention.ts'); +const {MOD_BAN}=require('../routing/fixture.cjs'); +const control=process.env.P027_CONTROL_URL; +const pool=new Pool({connectionString:process.env.DATABASE_URL}); +const out=process.argv[2]; +async function get(p){const r=await fetch(control+p,{signal:AbortSignal.timeout(10000)});assert.equal(r.status,200);return r.json();} +const cases=[]; +function add(name,auth='participant',body={},status=200,setup=null,fault=null,headers={}){ + cases.push({name,auth,body,status,setup,fault,headers}); +} +add('anonymous-first','unauthenticated'); +for(const [index,actor] of ['pid0','participant','standard','xid','owner','admin'].entries()) { + const tid=3+index; + add(actor+'-new',actor,{tid}); + add(actor+'-changed',actor,{tid,vote:convention.semanticToWire('disagree')}); + add(actor+'-repeated',actor,{tid,vote:convention.semanticToWire('disagree')}); + add(actor+'-moderated-out',actor,{tid:2}); + add(actor+'-missing-comment',actor,{tid:999}); + add(actor+'-closed',actor,{},403,'closed'); +} +add('foreign-conversation-token','foreign'); +add('expired-token','expired',{},401); +add('invalid-token-format','bad',{},401); +add('invalid-signature','signature',{},401); +add('treevite-member','participant',{},200,'treevite'); +add('treevite-owner','owner',{},200,'treevite'); +add('treevite-new-anonymous','unauthenticated',{},401,'treevite'); +add('xid-required','unauthenticated',{},403,'required'); +add('xid-first-contact','unauthenticated',{xid:'generated-new-member'}); +add('xid-allowed','xid',{},200,'whitelist'); +add('xid-denied','unauthenticated',{xid:'generated-denied'},403,'whitelist'); +add('star-true','participant',{starred:true}); +add('star-false','participant',{starred:false}); +add('star-repeat','participant',{starred:false}); +add('star-null','participant',{starred:null}); +add('star-numeric','participant',{starred:2,high_priority:'ON'}); +add('star-string','participant',{starred:'off',high_priority:true}); +add('star-invalid','participant',{starred:'yes'},400); +add('priority-invalid','participant',{high_priority:'yes'},400); +add('prefix-integers','participant',{tid:'0suffix',vote:String(convention.semanticToWire('pass'))+'suffix'}); +add('fractional-tid','participant',{tid:1.5},400); +add('missing-tid','unauthenticated',{tid:null},400); +add('missing-vote','participant',{vote:null},400); +add('invalid-vote','participant',{vote:2},400); +add('invalid-conversation','participant',{conversation_id:'2generatedmissing'},400); +add('missing-conversation','participant',{conversation_id:null},400); +add('invalid-xid','participant',{xid:3},400); +add('invalid-lang','participant',{lang:'abcdefghijkl'},400); +add('lang-empty','participant',{lang:''}); +add('no-next-comment','participant',{tid:1},200,'no-next'); +add('vote-failure','participant',{},500,null,'vote'); +add('duplicate-sqlstate','participant',{},406,null,'duplicate'); +add('star-failure-after-commit','participant',{starred:true},500,null,'star'); +add('next-failure-after-commit','participant',{},500,null,'next'); +add('retry-after-next-failure','participant'); +const additional = require('./additional.cjs'); +additional.cases(add, convention); +if(process.env.P027_VOTES_DEFERRED_FAILURE) { + const selected=cases.filter(c=>c.fault===process.env.P027_VOTES_DEFERRED_FAILURE); + assert.equal(selected.length,1,'select exactly one deferred failure'); + cases.splice(0,cases.length,...selected); +} +async function setup(kind){ + await pool.query('UPDATE comments SET mod=$1 WHERE zid=1 AND tid<>2',[kind==='no-next'?MOD_BAN:0]); + await pool.query('UPDATE conversations SET is_active=$1, treevite_enabled=$2, xid_required=$3, use_xid_whitelist=$4 WHERE zid=1',[kind!=='closed',kind==='treevite',kind==='required',kind==='whitelist']); +} +async function main(){ + assert.equal(new URL(process.env.DATABASE_URL).pathname,'/p027'); + assert.ok(out && out.startsWith('/artifacts/votes-')); + fs.mkdirSync(out,{recursive:true}); + const tokens={...await get('/tokens'),...await get('/votes-tokens')}; + await pool.query("INSERT INTO comments(zid,pid,uid,txt,lang,created,modified,mod) VALUES (1,0,1,'Generated moderated statement','en',1700000000000,1700000000000,$1)",[MOD_BAN]); + await pool.query("INSERT INTO xids(owner,uid,xid,zid,pid) VALUES(1,3,'generated-member',1,2)"); + await pool.query("INSERT INTO xid_whitelist(owner,xid) VALUES(1,'generated-member')"); + await pool.query("INSERT INTO conversations(zid,owner,topic,is_active) VALUES(2,1,'Generated foreign conversation',true)"); + await pool.query("INSERT INTO zinvites(zid,zinvite) VALUES(2,'2p027foreign')"); + for(let i=0;i<6;i++) await pool.query("INSERT INTO comments(zid,pid,uid,txt,lang,created,modified,mod) VALUES (1,0,1,$1,'en',1700000000000,1700000000000,0)",['Generated identity statement '+i]); + const tables=[...new Set((await recorder.schema()).map(r=>r.table_name))]; + const initial=await recorder.snapshot(tables); + const ready=await get('/ready'); + const route=ready.routes.find(r=>r.path==='/api/v3/votes' && r.method==='POST'); + assert.ok(route); + const normalizer=new Normalizer(); + const actual=[]; + for(const spec of cases){ + if(actual.length===72) { + const ids=await additional.initialize(pool); + Object.assign(tokens,await get('/votes-tokens?'+new URLSearchParams(ids))); + } + await setup(spec.setup); + if(actual.length>=72) await additional.setup(spec.setup,pool,get); + await get('/votes-fault?kind='+(spec.fault||'none')); + if(spec.auth!=='unauthenticated') assert.ok(tokens[spec.auth],spec.auth+' credential fixture'); + const c={caseId:'post-votes/'+spec.name,case:spec.name,auth:spec.auth, + seed:hash(spec.name).slice(0,12),routeId:undefined, + request:{method:'POST',path:'/api/v3/votes',query:{},headers:{'content-type':'application/json','x-forwarded-proto':'https',...(spec.auth==='unauthenticated'?{}:{authorization:'$auth:'+spec.auth}),...spec.headers}, + body:{conversation_id:'2p027generated',tid:0,vote:convention.semanticToWire('agree'),...spec.body}}}; + if(actual.length>=72 && tokens[spec.auth]?.includes('.')) { + const claims=JSON.parse(Buffer.from(tokens[spec.auth].split('.')[1],'base64url')); + c.credentialBinding={zid:spec.body.conversation_id==='2generatedempty'?4:1,oidcSub:claims.oidc_sub||claims.sub, + xid:typeof spec.body.xid==='string'&&spec.body.xid.trim()?spec.body.xid:claims.xid}; + } + const r=await recorder.runCase(c,tokens,tables,normalizer); + const fault=await get('/votes-fault-state'); + const after=await recorder.snapshot(tables); + const inserted=r.effects.db['pg:votes']?.added||[]; + r.voteProof={historyAdded:inserted.length,storedMeanings:inserted.map(v=>convention.storageToSemantic(v.vote)),latest:after['pg:votes_latest_unique'],stars:after['pg:stars'],fault}; + const dest=path.join(out,String(actual.length).padStart(3,'0')+'-'+spec.name); + fs.mkdirSync(dest,{recursive:true}); + put(dest,'comparison.json',r); + const projected=records(r); + for(const [name,value] of Object.entries(projected))put(dest,name+'.json',value); + actual.push(r); + put(out,'partial.json',{completed:actual.length,total:cases.length}); + assert.equal(r.response.status,spec.status,spec.name+' status'); + assert.equal(r.oracle.pass,true,JSON.stringify(r.oracle)); + assert.equal(fault.fired,spec.fault?1:0,spec.name+' fault witness'); + const commits=spec.status===200 || spec.fault==='star' || spec.fault==='next'; + assert.equal(inserted.length,commits?1:0,spec.name+' durable history count'); + if(commits){ + const row=inserted[0]; + const parsed=Number.parseInt(String(c.request.body.vote),10); + assert.equal(convention.storageToSemantic(row.vote),convention.wireToSemantic(parsed)); + const latest=after['pg:votes_latest_unique'].filter(v=>v.zid===row.zid&&v.pid===row.pid&&v.tid===row.tid); + if(spec.name.endsWith('-new')) { + const replaced=r.effects.db['pg:votes_latest_unique']?.removed||[]; + assert.equal(replaced.filter(v=>v.zid===row.zid&&v.pid===row.pid&&v.tid===row.tid).length,0,spec.name+' first insert'); + } + if(spec.name==='no-next-comment')assert.equal(Object.hasOwn(r.response.body,'nextComment'),false); + assert.equal(latest.length,1);assert.equal(latest[0].vote,row.vote); + assert.equal(latest[0].modified,row.created); + if(typeof r.response.body==='object' && r.response.body.currentPid!==undefined)assert.equal(r.response.body.currentPid,row.pid); + } + if(actual.length>72) additional.check(spec,r,after); + console.log(JSON.stringify({case:spec.name,status:r.response.status,votes:inserted.length,oracle:r.oracle.pass})); + } + const corpus={format:'post-votes-recordings/1',source_commit:process.env.P027_SOURCE_COMMIT, + cases:actual.map(r=>({case:r.case,status:r.response.status,historyAdded:r.voteProof.historyAdded})), + convention:{wire_agree:convention.WIRE_AGREE,storage_agree:convention.currentStorageConvention().agreeValue}, + serialization:ready.serialization,initial,final:await recorder.snapshot(tables)}; + put(out,'corpus.json',corpus); + put(out,'cases.json',actual); + if(process.argv[3]){ + const before=JSON.parse(fs.readFileSync(path.join(process.argv[3],'cases.json'))); + assert.equal(before.length,actual.length); + const differences=actual.flatMap((r,i)=>{const d=firstDifference(before[i],r);return d?[{case:r.case,difference:d}]:[];}); + put(out,'replay.json',{cases:actual.length,differences});assert.deepEqual(differences,[]); + } + const files=[]; + function visit(dir){for(const e of fs.readdirSync(dir,{withFileTypes:true})){const f=path.join(dir,e.name);if(e.isDirectory())visit(f);else files.push(pin(out,path.relative(out,f)));}} + visit(out);put(out,'index.json',{format:corpus.format,source_commit:corpus.source_commit,files}); + console.log(JSON.stringify({cases:actual.length,failed:0,replay:!!process.argv[3]})); +} +main().catch(e=>{console.error(e);process.exitCode=1;}).finally(async()=>{await pool.end();await recorder.close();}); From 6899f31b66998d50c495786fd6fe4eb25285e519 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Tue, 20 Oct 2026 20:10:40 -0700 Subject: [PATCH 12/30] characterization: the recorder and routing replay tolerate a vote path that no longer stores vote_count (#3241) The vote-path recorder derives a participant's count from the votes table when settling and in its recorded participants query; the routing replay's substitute pg gains a notification passthrough and extracts updateVoteCount only when the server still declares it. Harness only; goldens unchanged. Co-authored-by: Claude Fable 5.1 --- .../integration/vote-path-recordings.test.ts | 13 ++++--------- server/characterization/routing/http.cjs | 12 ++++++------ server/characterization/routing/runtime.cjs | 1 + 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/server/__tests__/integration/vote-path-recordings.test.ts b/server/__tests__/integration/vote-path-recordings.test.ts index 335367ecc..71861b74b 100644 --- a/server/__tests__/integration/vote-path-recordings.test.ts +++ b/server/__tests__/integration/vote-path-recordings.test.ts @@ -538,20 +538,15 @@ async function zidOf(conversationId: string): Promise { return rows[0].zid; } -/** - * Wait for the handlers' deferred updates (POST /votes and POST /comments run - * updateVoteCount and the modified/last-interaction updates on a 100 ms timer) - * before reading. Polls instead of sleeping: done when every participant's - * vote_count equals its stored rows and the conversation's participant and - * modified state has not changed across three polls. A path that never - * updates vote_count is accepted once its state has been still for 2 s. +/** Wait for notification state to settle before recording. Numeric counts + * are read from durable vote history; the retired cached count is not a signal. */ async function settle(zid: number): Promise { const state = async () => JSON.stringify( ( await pool.query( - `SELECT p.pid, p.vote_count, p.last_interaction, c.modified, + `SELECT p.pid, (SELECT count(*)::int FROM votes v WHERE v.zid=p.zid AND v.pid=p.pid) AS vote_count, p.last_interaction, c.modified, (SELECT count(*) FROM votes v WHERE v.zid = p.zid AND v.pid = p.pid) AS stored FROM participants p JOIN conversations c ON c.zid = p.zid WHERE p.zid = $1 ORDER BY p.pid`, @@ -911,7 +906,7 @@ describe("vote paths serve exactly the bytes edge served", () => { await recordStored("V/after-participant-votes", V.zid); await recordQuery( "V/db/participants", - "SELECT pid, vote_count, mod FROM participants WHERE zid = $1 ORDER BY pid", + "SELECT pid, (SELECT count(*)::int FROM votes v WHERE v.zid=p.zid AND v.pid=p.pid) AS vote_count, mod FROM participants p WHERE zid = $1 ORDER BY pid", [V.zid] ); diff --git a/server/characterization/routing/http.cjs b/server/characterization/routing/http.cjs index 408fda489..d95c97da4 100644 --- a/server/characterization/routing/http.cjs +++ b/server/characterization/routing/http.cjs @@ -2,25 +2,25 @@ // parameter parsing are fixed fixture inputs; this is not an auth middleware test. const fs=require('node:fs'),path=require('node:path'),ts=require('typescript'); const express=require('express'),request=require('supertest'); -function functions(file,names,bindings,mutation) { +function functions(file,names,bindings,mutation,optional=[]) { let source=fs.readFileSync(path.resolve(__dirname,'../../src',file),'utf8'); if(mutation?.file===file) { if(!source.includes(mutation.from))throw Error(`mutation anchor missing: ${mutation.name}`); source=source.replace(mutation.from,mutation.to); } const ast=ts.createSourceFile(file,source,ts.ScriptTarget.Latest,true); - const found=ast.statements.filter(n=>ts.isFunctionDeclaration(n)&&names.includes(n.name?.text)); - if(found.length!==names.length)throw Error(`missing route/helper declaration in ${file}`); + const found=ast.statements.filter(n=>ts.isFunctionDeclaration(n)&&[...names,...optional].includes(n.name?.text)); + if(names.some(name=>!found.some(n=>n.name.text===name)))throw Error(`missing route/helper declaration in ${file}`); const js=ts.transpileModule(found.map(n=>n.getText(ast)).join('\n'),{compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.CommonJS}}).outputText; - return new Function(...Object.keys(bindings),`${js}\nreturn {${names.join(',')}};`)(...Object.values(bindings)); + return new Function(...Object.keys(bindings),`${js}\nreturn {${found.map(n=>n.name.text).join(',')}};`)(...Object.values(bindings)); } exports.request=async(rt,f)=>{ rt.fixture=f; if(!rt.app) { const logger=Object.fromEntries(['error','warn','info','debug'].map(k=>[k,()=>{}])); const common={_:require('underscore'),pg:rt.pg,logger,failJson:(res,status,label)=>res.status(status).json({error:label}),getZinvite:rt.load('utils/zinvite.ts').getZinvite}; - const helpers=functions('server-helpers.ts',['finishOne','addConversationId','safeTimestampToMillis','updateConversationModifiedTime','updateLastInteractionTimeForConversation','updateVoteCount','addNoMoreCommentsRecord','addStar'],common,rt.mutation); - const binding={...common,...helpers,...rt.load('votes/convention.ts'),getNextComment:rt.next.getNextComment,isDuplicateKey:e=>e.code==='23505',setTimeout:fn=>rt.timers.push(fn)}; + const helpers=functions('server-helpers.ts',['finishOne','addConversationId','safeTimestampToMillis','updateConversationModifiedTime','updateLastInteractionTimeForConversation','addNoMoreCommentsRecord','addStar'],common,rt.mutation,['updateVoteCount']); + const binding={...common,updateVoteCount:()=>{},...helpers,...rt.load('votes/convention.ts'),getNextComment:rt.next.getNextComment,isDuplicateKey:e=>e.code==='23505',setTimeout:fn=>rt.timers.push(fn)}; const get=functions('routes/comments.ts',['handle_GET_nextComment'],binding,rt.mutation).handle_GET_nextComment; const post=functions('routes/votes.ts',['doVotesPost','votesPost','handle_POST_votes'],binding,rt.mutation).handle_POST_votes; const app=express();app.use(express.json()); diff --git a/server/characterization/routing/runtime.cjs b/server/characterization/routing/runtime.cjs index 22a5614ec..5c78f7cff 100644 --- a/server/characterization/routing/runtime.cjs +++ b/server/characterization/routing/runtime.cjs @@ -43,6 +43,7 @@ exports.runtime = function runtime(client, fixture, mutate = null) { queryP_metered: async(_name,sql,params)=>(await trackedQuery(sql,params)).rows, query(sql, params, cb) { trackedQuery(sql,params).then(x=>cb(null,x),e=>cb(e)); }, queryP: async(sql,params)=>(await trackedQuery(sql,params)).rows, + queryP_notification: async(sql,params)=>(await trackedQuery(sql,params)).rows, queryP_readOnly: async(sql,params)=>(await trackedQuery(sql,params)).rows, }; const config = {mathEnv:'python',cacheMathResults:true,shouldUseTranslationAPI:fixture.translate!==false, From b7a360b9a6a02fdc831596e1028518a35e4f6232 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Tue, 20 Oct 2026 21:21:39 -0700 Subject: [PATCH 13/30] votes: the vote path inserts and returns; vote_count and modified are derived at read (#3240) Node's deferred bookkeeping after every vote (a participant recount, the conversation's modified time, the notification state) ran on the two participation write pools and, behind a held row lock, starved votes, comments and nextComment until they timed out. The vote and comment paths no longer write vote_count or modified; readers derive both from committed history. Notification state moves to its own bounded pool and fails soft. A participation-under-load integration test holds the realistic lock (NO KEY UPDATE on the conversation and participant rows) and asserts every request answers within 5 s. No schema change. Co-authored-by: Claude Fable 5.1 --- queue-rs/polis-api/src/recent_activity.rs | 16 +- .../integration/derived-activity.test.ts | 165 ++++ .../integration/mixed-writer-load.test.ts | 914 ++++++++++++++++++ .../integration/participation-pools.test.ts | 26 +- .../xid-list-moderators-only.test.ts | 2 +- .../__tests__/setup/mixed-writer-observer.cjs | 35 + .../__tests__/setup/mixed-writer-process.cjs | 33 + .../unit/commentToxicityCheckOff.test.ts | 3 +- .../__tests__/unit/commentTranslation.test.ts | 3 +- .../unit/commentUniqueViolation.test.ts | 2 +- .../unit/conversationsRoutes.test.ts | 8 +- .../__tests__/unit/seedAutomaticPass.test.ts | 2 +- .../routing/expected-differences.json | 372 +++++-- server/src/db/activity.ts | 16 + server/src/db/participation-scope.ts | 5 +- server/src/db/pg-query.ts | 35 +- server/src/participant.ts | 2 +- server/src/routes/comments.ts | 26 +- server/src/routes/conversations.ts | 19 +- server/src/routes/notify.ts | 37 +- server/src/routes/participation.ts | 5 +- server/src/routes/votes.ts | 10 +- server/src/routes/xids.ts | 7 +- server/src/server-helpers.ts | 18 +- 24 files changed, 1609 insertions(+), 152 deletions(-) create mode 100644 server/__tests__/integration/derived-activity.test.ts create mode 100644 server/__tests__/integration/mixed-writer-load.test.ts create mode 100644 server/__tests__/setup/mixed-writer-observer.cjs create mode 100644 server/__tests__/setup/mixed-writer-process.cjs create mode 100644 server/src/db/activity.ts diff --git a/queue-rs/polis-api/src/recent_activity.rs b/queue-rs/polis-api/src/recent_activity.rs index 031c484a8..7ff2fb396 100644 --- a/queue-rs/polis-api/src/recent_activity.rs +++ b/queue-rs/polis-api/src/recent_activity.rs @@ -104,7 +104,9 @@ pub fn read( since: i64, ) -> anyhow::Result> { let rows = c.query( - "SELECT 1 FROM conversations WHERE modified >= $1 LIMIT 1", + "SELECT 1 FROM conversations c WHERE c.modified >= $1 + OR (c.modified IS NOT NULL AND EXISTS (SELECT 1 FROM votes v WHERE v.zid=c.zid AND v.created >= $1)) + OR (c.modified IS NOT NULL AND EXISTS (SELECT 1 FROM comments m WHERE m.zid=c.zid AND (m.created >= $1 OR m.modified >= $1))) LIMIT 1", &[&since], )?; Ok(rows.is_empty().then_some([])) @@ -120,7 +122,7 @@ mod tests { let setup_schema = schema.clone(); tokio::task::spawn_blocking(move||{ let mut c=postgres::Client::connect(&setup_url,postgres::NoTls).unwrap(); - c.batch_execute(&format!("CREATE SCHEMA {setup_schema}; CREATE TABLE {setup_schema}.conversations(modified bigint); INSERT INTO {setup_schema}.conversations VALUES(2000),(NULL);")).unwrap(); + c.batch_execute(&format!("CREATE SCHEMA {setup_schema}; CREATE TABLE {setup_schema}.conversations(zid int, modified bigint); CREATE TABLE {setup_schema}.votes(zid int, created bigint); CREATE TABLE {setup_schema}.comments(zid int, created bigint, modified bigint); INSERT INTO {setup_schema}.conversations VALUES(1,2000),(2,NULL),(3,1),(4,1); INSERT INTO {setup_schema}.votes VALUES(2,9000),(3,3000); INSERT INTO {setup_schema}.comments VALUES(4,4000,5000);")).unwrap(); }).await.unwrap(); let make_pool = || { let mut c: postgres::Config = url.parse().unwrap(); @@ -132,7 +134,7 @@ mod tests { }; let pool = make_pool(); let participation = make_pool(); - for zid in [2001, 9007199254740000] { + for zid in [5001, 9007199254740000] { assert!( pool.with(move |c| read(c, zid)) .await @@ -141,7 +143,9 @@ mod tests { .is_empty() ); } - assert!(pool.with(|c| read(c, 2000)).await.unwrap().is_none()); + for since in [2000, 3000, 4000, 5000] { + assert!(pool.with(move |c| read(c, since)).await.unwrap().is_none()); + } let (ready_tx, ready_rx) = tokio::sync::oneshot::channel(); let (release_tx, release_rx) = std::sync::mpsc::channel(); let lock_url = url.clone(); @@ -160,13 +164,13 @@ mod tests { }); ready_rx.await.unwrap(); let stalled = pool.clone(); - let task = tokio::spawn(async move { stalled.with(|c| read(c, 2001)).await }); + let task = tokio::spawn(async move { stalled.with(|c| read(c, 5001)).await }); assert!(participation.ping().await); assert!(task.await.unwrap().is_err()); release_tx.send(()).unwrap(); locked.await.unwrap(); assert!( - pool.with(|c| read(c, 2001)) + pool.with(|c| read(c, 5001)) .await .unwrap() .unwrap() diff --git a/server/__tests__/integration/derived-activity.test.ts b/server/__tests__/integration/derived-activity.test.ts new file mode 100644 index 000000000..0ba6230a3 --- /dev/null +++ b/server/__tests__/integration/derived-activity.test.ts @@ -0,0 +1,165 @@ +import { beforeAll, expect, test } from "@jest/globals"; +import { Pool } from "pg"; +import { + setupAuthAndConvo, + getJwtAuthenticatedAgent, +} from "../setup/api-test-helpers"; +import { pool } from "../setup/db-test-helpers"; +import pg, { NOTIFICATION_PENDING_MAX } from "../../src/db/pg-query"; +import { onParticipationPools } from "../../src/db/participation-scope"; +import { + conversationModifiedSql, + participantVoteCountSql, +} from "../../src/db/activity"; +import { semanticToWire } from "../../src/votes/convention"; + +let agent: any, conversationId: string, zid: number, pid: number, tid: number; +beforeAll(async () => { + const fixture = await setupAuthAndConvo({ + createConvo: true, + commentCount: 2, + }); + conversationId = fixture.conversationId; + tid = fixture.commentIds[0]; + agent = (await getJwtAuthenticatedAgent(fixture.testUser)).agent; + zid = ( + await pool.query("SELECT zid FROM zinvites WHERE zinvite=$1", [ + conversationId, + ]) + ).rows[0].zid; + pid = ( + await pool.query("SELECT pid FROM participants WHERE zid=$1 ORDER BY pid", [ + zid, + ]) + ).rows[0].pid; +}); + +test("participant reads count history including revotes without maintaining the cached count", async () => { + const start = Number( + ( + await pool.query("SELECT count(*) FROM votes WHERE zid=$1 AND pid=$2", [ + zid, + pid, + ]) + ).rows[0].count + ); + await pool.query( + "UPDATE participants SET vote_count=97 WHERE zid=$1 AND pid=$2", + [zid, pid] + ); + for (const semantic of ["agree", "disagree", "pass"] as const) { + const response = await agent.post("/api/v3/votes").send({ + conversation_id: conversationId, + tid, + vote: semanticToWire(semantic), + }); + expect(response.status).toBe(200); + } + const response = await agent + .get("/api/v3/participants") + .query({ conversation_id: conversationId }); + expect(response.status).toBe(200); + const stored = ( + await pool.query("SELECT * FROM participants WHERE zid=$1 AND pid=$2", [ + zid, + pid, + ]) + ).rows[0]; + expect(stored.vote_count).toBe(97); + // The same object field order/types, with only the obsolete cache replaced. + // Notification timestamps can advance independently; pin their observed bytes. + stored.last_interaction = response.body.last_interaction; + stored.nsli = response.body.nsli; + stored.vote_count = start + 3; + expect(response.text).toBe(JSON.stringify(stored)); + const absent = ( + await pool.query( + `SELECT ${participantVoteCountSql( + "p" + )} AS vote_count FROM (VALUES ($1::int, 2147483647, NULL::int)) p(zid,pid,vote_count)`, + [zid] + ) + ).rows[0]; + expect(absent.vote_count).toBeNull(); +}); + +test("activity includes votes, comment edits and the retained metadata clock with bigint output", async () => { + const read = async () => + ( + await pool.query( + `SELECT ${conversationModifiedSql( + "c" + )} AS modified FROM conversations c WHERE zid=$1`, + [zid] + ) + ).rows[0].modified; + const voteTime = ( + await pool.query("SELECT max(created) AS t FROM votes WHERE zid=$1", [zid]) + ).rows[0].t; + await pool.query("UPDATE conversations SET modified=1 WHERE zid=$1", [zid]); + await pool.query("UPDATE comments SET created=1,modified=2 WHERE zid=$1", [ + zid, + ]); + expect(await read()).toBe(voteTime); + const edited = Number(voteTime) + 100; + await pool.query("UPDATE comments SET modified=$2 WHERE zid=$1 AND tid=$3", [ + zid, + edited, + tid, + ]); + expect(await read()).toBe(String(edited)); + await pool.query("UPDATE conversations SET modified=$2 WHERE zid=$1", [ + zid, + edited + 100, + ]); + expect(await read()).toBe(String(edited + 100)); + await pool.query("UPDATE conversations SET modified=NULL WHERE zid=$1", [ + zid, + ]); + expect(await read()).toBeNull(); +}); + +test("notification admission is bounded and cannot occupy participation connections", async () => { + const work = Array.from({ length: NOTIFICATION_PENDING_MAX + 1 }, () => + pg.queryP_notification("SELECT pg_sleep(2)") + ); + const settled = Promise.allSettled(work); + const started = performance.now(); + const answer: any = await new Promise((resolve, reject) => + onParticipationPools(null, null, () => { + pg.queryP("SELECT 42::int AS n").then(resolve, reject); + }) + ); + expect(answer[0].n).toBe(42); + expect(performance.now() - started).toBeLessThan(5000); + const results = await settled; + expect(results.every((r) => r.status === "rejected")).toBe(true); + expect( + results.some( + (r) => + r.status === "rejected" && + r.reason.message === "notification_queue_full" + ) + ).toBe(true); + expect(performance.now() - started).toBeLessThan(5000); + expect((await pg.queryP_notification("SELECT 43::int AS n"))[0].n).toBe(43); +}); + +test("an idle notification connection loss is handled and replaced", async () => { + const admin = new Pool({ + connectionString: process.env.DATABASE_URL, + max: 1, + }); + try { + const lost = ( + await pg.queryP_notification("SELECT pg_backend_pid() AS pid") + )[0].pid; + await admin.query("SELECT pg_terminate_backend($1)", [lost]); + await new Promise((resolve) => setTimeout(resolve, 300)); + expect( + (await pg.queryP_notification("SELECT pg_backend_pid() AS pid"))[0].pid + ).not.toBe(lost); + } finally { + await admin.end(); + } +}); diff --git a/server/__tests__/integration/mixed-writer-load.test.ts b/server/__tests__/integration/mixed-writer-load.test.ts new file mode 100644 index 000000000..c1a6ce477 --- /dev/null +++ b/server/__tests__/integration/mixed-writer-load.test.ts @@ -0,0 +1,914 @@ +/** + * Two independent writers share the migrated database. By default the second + * writer is another Node process. MIXED_WRITER_BASE_URL replaces only its HTTP + * destination, so a future Rust handler uses these same requests and assertions. + * No request is retried or sent to a fallback after a possible mutation. + * + * Twelve participants, every request strictly below 5000 ms, and a 10000 ms + * client give-up boundary: the existing participation guard's unchanged bounds. + * A failure is a defect report, never an expected failure or a wider budget. + */ +import { fork, ChildProcess } from "child_process"; +import { randomUUID } from "crypto"; +import { Server } from "http"; +import { AddressInfo } from "net"; +import path from "path"; +import request from "supertest"; +import { Client, PoolClient } from "pg"; +import { getApp } from "../app-loader"; +import { setupAuthAndConvo } from "../setup/api-test-helpers"; +import { issueAnonymousJWT } from "../../src/auth/anonymous-jwt"; +import pg, { + MAIN_POOL_MAX, + PARTICIPATION_POOL_MAX, + PARTICIPATION_READ_POOL_MAX, + RESULT_SNAPSHOT_POOL_MAX, + REPORT_EXPORT_POOL_MAX, + AGENT_EXCHANGE_POOL_MAX, +} from "../../src/db/pg-query"; +import { + semanticToWire, + semanticToStorage, + storageToSemantic, + wireToSemantic, + Vote, + StorageConvention, + currentStorageConvention, +} from "../../src/votes/convention"; + +const BUDGET_MS = 5000, + GIVE_UP_MS = 10000, + PARTICIPANTS = 12; +const observer = require("../setup/mixed-writer-observer.cjs"); +let server: Server, + child: ChildProcess | undefined, + primary: string, + secondary: string; +let admin: Client, conversationId: string, zid: number, tids: number[]; +let convention: StorageConvention; +let participants: Participant[]; +type Participant = { pid: number; uid: number; token: string }; +type Outcome = { + op: string; + writer: string; + pid: number; + tid?: number; + text?: string; + ms: number; + status: number; + body: any; + error?: string; +}; +const output = (data: Record) => { + process.stdout.write(`MIXED_WRITER ${JSON.stringify(data)}\n`); +}; +const delay = () => new Promise((resolve) => setTimeout(resolve, 10)); +async function until( + check: () => Promise, + label: string, + ms = GIVE_UP_MS +) { + const deadline = performance.now() + ms; + while (!(await check())) { + if (performance.now() >= deadline) + throw new Error(`barrier not reached: ${label}`); + await delay(); + } +} +async function snapshot(label: string) { + const activity = ( + await admin.query(`SELECT pid,application_name,state,wait_event_type, + wait_event,pg_blocking_pids(pid) AS blockers,left(query,180) AS query + FROM pg_stat_activity WHERE datname=current_database() AND pid<>pg_backend_pid()`) + ).rows; + const locks = ( + await admin.query(`SELECT pid,locktype,mode,granted,relation::regclass::text, + classid,objid FROM pg_locks WHERE pid IN + (SELECT pid FROM pg_stat_activity WHERE datname=current_database())`) + ).rows; + let secondPools: unknown = + "external writer; inspect application_name and database waits"; + if (child) { + secondPools = await new Promise((resolve, reject) => { + const id = randomUUID(); + const timer = setTimeout( + () => reject(new Error("second writer snapshot timeout")), + GIVE_UP_MS + ); + const receive = (message: any) => { + if (message.id !== id) return; + clearTimeout(timer); + child!.off("message", receive); + resolve(message); + }; + child!.on("message", receive); + child!.send({ op: "snapshot", id }); + }); + } + const primaryPools = observer.snapshot(); + output({ label, activity, locks, primaryPools, secondPools }); + for (const diagnostics of [primaryPools, secondPools]) { + if (typeof diagnostics !== "object") continue; + for (const pool of (diagnostics as any).pools) { + if (pool.role === "participation") + expect(pool.max).toBe(PARTICIPATION_POOL_MAX); + if (pool.role === "participation-read") + expect(pool.max).toBe(PARTICIPATION_READ_POOL_MAX); + } + } + return activity; +} +async function call( + url: string, + p: Participant | undefined, + op: string, + payload: any +): Promise { + const start = performance.now(); + try { + let sent = + op === "nextComment" || + op === "participationInit" || + op === "votes/me" || + op === "votesRead" + ? request(url) + .get(`/api/v3/${op === "votesRead" ? "votes" : op}`) + .query(payload) + : request(url).post(`/api/v3/${op}`).send(payload); + if (p) sent = sent.set("Authorization", `Bearer ${p.token}`); + const res = await sent + .timeout({ response: GIVE_UP_MS, deadline: GIVE_UP_MS }) + .ok(() => true); + return { + op, + writer: url === primary ? "primary" : "secondary", + pid: p?.pid ?? -1, + tid: payload.tid, + text: payload.txt, + ms: performance.now() - start, + status: res.status, + body: res.body, + }; + } catch (error) { + return { + op, + writer: url === primary ? "primary" : "secondary", + pid: p?.pid ?? -1, + tid: payload.tid, + text: payload.txt, + ms: performance.now() - start, + status: 0, + body: null, + error: String(error), + }; + } +} +const vote = ( + url: string, + p: Participant | undefined, + tid: number, + intent: Vote, + extra = {} +) => + call(url, p, "votes", { + conversation_id: conversationId, + tid, + vote: semanticToWire(intent), + ...extra, + }); +function prompt(outcomes: Outcome[]) { + // Do not put auth tokens or entire response objects in the evidence log. + output({ + outcomes: outcomes.map(({ body: _body, ...rest }) => rest), + p50_ms: percentile(outcomes, 0.5), + p95_ms: percentile(outcomes, 0.95), + max_ms: Math.max(...outcomes.map((x) => x.ms)), + }); + expect(outcomes.map((x) => x.status)).toEqual(outcomes.map(() => 200)); + expect(outcomes.every((x) => x.ms < BUDGET_MS)).toBe(true); +} +function percentile(values: Outcome[], p: number) { + return values.map((x) => x.ms).sort((a, b) => a - b)[ + Math.ceil(values.length * p) - 1 + ]; +} +async function history(p: Participant, tid: number) { + return ( + await admin.query( + "SELECT vote,created,weight_x_32767,high_priority FROM votes WHERE zid=$1 AND pid=$2 AND tid=$3", + [zid, p.pid, tid] + ) + ).rows; +} +async function latest(p: Participant, tid: number) { + const rows = ( + await admin.query( + "SELECT vote,modified,weight_x_32767 FROM votes_latest_unique WHERE zid=$1 AND pid=$2 AND tid=$3", + [zid, p.pid, tid] + ) + ).rows; + expect(rows).toHaveLength(1); + return rows[0]; +} +async function enrolled(url: string): Promise { + const first = await vote(url, undefined, tids[0], "pass"); + prompt([first]); + const token = first.body.auth?.token, + pid = first.body.currentPid; + expect(typeof token).toBe("string"); + expect(Number.isInteger(pid)).toBe(true); + const rows = ( + await admin.query("SELECT uid FROM participants WHERE zid=$1 AND pid=$2", [ + zid, + pid, + ]) + ).rows; + expect(rows).toHaveLength(1); + return { pid, uid: rows[0].uid, token }; +} +async function durable(outcomes: Outcome[], tid: number) { + for (const out of outcomes.filter((x) => x.op === "comments")) { + const p = participants.find((p) => p.pid === out.pid)!; + const rows = ( + await admin.query( + "SELECT pid,uid,tid FROM comments WHERE zid=$1 AND txt=$2", + [zid, out.text] + ) + ).rows; + expect(rows).toEqual([{ pid: p.pid, uid: p.uid, tid: out.body.tid }]); + } + for (const p of participants) { + expect(await history(p, tid)).toHaveLength(1); + expect(storageToSemantic((await latest(p, tid)).vote, { convention })).toBe( + "agree" + ); + const next = await call(primary, p, "nextComment", { + conversation_id: conversationId, + not_voted_by_pid: p.pid, + }); + expect(next.status).toBe(200); + if (Number.isInteger(next.body?.tid)) expect(next.body.tid).not.toBe(tid); + } +} +async function burst(tid: number, split: boolean, reverse = false) { + const tag = randomUUID(); + return Promise.all( + participants.flatMap((p, i) => { + const url = + split && i < PARTICIPANTS / 2 !== reverse ? secondary : primary; + return [ + vote(url, p, tid, "agree"), + call(primary, p, "comments", { + conversation_id: conversationId, + txt: `Generated mixed writer statement ${tag} ${i}`, + vote: semanticToWire("pass"), + }), + call(primary, p, "nextComment", { + conversation_id: conversationId, + not_voted_by_pid: p.pid, + }), + ]; + }) + ); +} +async function countersSettled() { + await until( + async () => + ( + await admin.query( + `SELECT count(*)::int AS n FROM participants p + WHERE zid=$1 AND EXISTS(SELECT 1 FROM votes v WHERE v.zid=p.zid AND v.pid=p.pid) AND last_interaction=0`, + [zid] + ) + ).rows[0].n === 0, + "notification interaction state settled", + 30000 + ); +} + +beforeAll(async () => { + admin = new Client({ + connectionString: process.env.DATABASE_URL, + application_name: "mixed-writer-observer", + }); + await admin.connect(); + // This release's conversion source is constant; it has no database convention + // table. Fail if a later schema adds one without updating this admission. + expect( + (await admin.query("SELECT to_regclass('public.vote_convention') AS name")) + .rows[0].name + ).toBeNull(); + convention = currentStorageConvention(); + const app = await getApp(); + server = app.listen(0, "127.0.0.1"); + await new Promise((resolve) => server.once("listening", resolve)); + primary = `http://127.0.0.1:${(server.address() as AddressInfo).port}`; + if (process.env.MIXED_WRITER_BASE_URL) { + const url = new URL(process.env.MIXED_WRITER_BASE_URL); + if (!["127.0.0.1", "localhost", "[::1]"].includes(url.hostname)) + throw new Error("second writer must be local"); + secondary = url.origin; + } else { + const database = new URL(process.env.DATABASE_URL!); + database.searchParams.set("application_name", "mixed-writer-secondary"); + child = fork( + path.resolve(__dirname, "../setup/mixed-writer-process.cjs"), + [], + { + env: { + ...process.env, + DATABASE_URL: database.toString(), + READ_ONLY_DATABASE_URL: database.toString(), + }, + stdio: ["ignore", "ignore", "pipe", "ipc"], + } + ); + child.stderr?.on("data", (data) => process.stderr.write(data)); + secondary = await new Promise((resolve, reject) => { + const timer = setTimeout( + () => reject(new Error("second writer startup timeout")), + 60000 + ); + child!.once("exit", (code) => { + clearTimeout(timer); + reject(new Error(`second writer exited ${code}`)); + }); + child!.on("message", (message: any) => { + if (message.ready) { + clearTimeout(timer); + resolve(`http://127.0.0.1:${message.port}`); + } + }); + }); + } + const setup = await setupAuthAndConvo({ commentCount: 16 }); + conversationId = setup.conversationId; + tids = setup.commentIds; + zid = ( + await admin.query("SELECT zid FROM zinvites WHERE zinvite=$1", [ + conversationId, + ]) + ).rows[0].zid; + // Include pid zero explicitly; the owner's seeded comments enrolled them. + const owner = ( + await admin.query( + "SELECT pid,uid FROM participants WHERE zid=$1 ORDER BY pid", + [zid] + ) + ).rows; + expect(owner[0].pid).toBe(0); + participants = []; + for (let i = 0; i < PARTICIPANTS; i++) + participants.push(await enrolled(i % 2 ? primary : secondary)); + const max = Number( + (await admin.query("SHOW max_connections")).rows[0].max_connections + ); + const reserved = Number( + (await admin.query("SHOW superuser_reserved_connections")).rows[0] + .superuser_reserved_connections + ); + const perNode = + 2 * MAIN_POOL_MAX + + PARTICIPATION_POOL_MAX + + PARTICIPATION_READ_POOL_MAX + + RESULT_SNAPSHOT_POOL_MAX + + REPORT_EXPORT_POOL_MAX + + AGENT_EXCHANGE_POOL_MAX + + 2; + expect(2 * perNode + 8).toBeLessThanOrEqual(max - reserved); + output({ + budget_ms: BUDGET_MS, + give_up_ms: GIVE_UP_MS, + participants: PARTICIPANTS, + per_node_pool_max: perNode, + postgres_max: max, + administrative_reserve: 8, + second_writer: child ? "independent Node process" : "external HTTP handler", + participation_write_max: PARTICIPATION_POOL_MAX, + participation_read_max: PARTICIPATION_READ_POOL_MAX, + }); +}, 120000); + +afterAll(async () => { + if (child && child.exitCode === null) { + const stopped = new Promise((resolve) => + child!.once("exit", () => resolve()) + ); + child.send({ op: "stop" }); + const timer = setTimeout(() => child!.kill("SIGTERM"), GIVE_UP_MS); + await stopped; + clearTimeout(timer); + } + await new Promise((resolve) => + server ? server.close(() => resolve()) : resolve() + ); + await admin?.end(); +}); + +test("Node control, split ownership, reversed ownership and Node down phase preserve every write", async () => { + for (const [index, name] of [ + "node-before", + "split", + "split-reversed", + "node-after", + ].entries()) { + const outcomes = await burst( + tids[index + 1], + index === 1 || index === 2, + index === 2 + ); + prompt(outcomes); + await durable(outcomes, tids[index + 1]); + await countersSettled(); + await snapshot(name); + } +}, 120000); + +test("same-key concurrent writers append both votes and retain exactly one latest row", async () => { + const tid = tids[5]; + const outcomes = await Promise.all( + participants.flatMap((p) => [ + vote(primary, p, tid, "agree"), + vote(secondary, p, tid, "disagree"), + ]) + ); + prompt(outcomes); + for (const p of participants) { + const rows = await history(p, tid); + expect(rows).toHaveLength(2); + expect( + rows.map((row) => storageToSemantic(row.vote, { convention })).sort() + ).toEqual(["agree", "disagree"]); + expect(["agree", "disagree"]).toContain( + storageToSemantic((await latest(p, tid)).vote, { convention }) + ); + } + await countersSettled(); +}); + +test("both serialized writer orders and repeat votes preserve history and the last insertion", async () => { + for (const [i, urls] of [ + [primary, secondary], + [secondary, primary], + ].entries()) { + const p = participants[i], + tid = tids[6 + i]; + prompt([await vote(urls[0], p, tid, "agree")]); + prompt([await vote(urls[1], p, tid, "disagree")]); + prompt([await vote(urls[1], p, tid, "disagree")]); + expect(await history(p, tid)).toHaveLength(3); + expect(storageToSemantic((await latest(p, tid)).vote, { convention })).toBe( + "disagree" + ); + const readback = await call(primary, p, "votes/me", { + conversation_id: conversationId, + }); + expect(readback.status).toBe(200); + const rows = Array.isArray(readback.body) + ? readback.body + : readback.body.votes; + // votes/me returns history without an ORDER BY, not the latest relation. + expect( + rows + .filter((row: any) => row.tid === tid) + .map((row: any) => wireToSemantic(row.vote)) + .sort() + ).toEqual(["agree", "disagree", "disagree"]); + const latestRead = await call(primary, p, "votesRead", { + conversation_id: conversationId, + pid: p.pid, + tid, + }); + expect(latestRead.status).toBe(200); + expect(latestRead.body).toHaveLength(1); + expect(wireToSemantic(latestRead.body[0].vote)).toBe("disagree"); + } +}); + +test("equal and decreasing timestamps follow insertion order and retain the original latest weight", async () => { + const p = participants[0], + tid = tids[8], + created = Date.now(); + for (const [index, intent] of ( + ["agree", "disagree", "pass"] as Vote[] + ).entries()) { + // The direct database witness still crosses the convention module. + await admin.query( + `INSERT INTO votes(zid,pid,tid,vote,created,weight_x_32767,high_priority) + VALUES($1,$2,$3,$4,$5,$6,$7)`, + [ + zid, + p.pid, + tid, + semanticToStorage(intent, { convention }), + created - (index === 2 ? 1 : 0), + index === 0 ? 20000 : 10000, + index === 0, + ] + ); + const row = await latest(p, tid); + expect(storageToSemantic(row.vote, { convention })).toBe(intent); + expect(Number(row.modified)).toBe(created - (index === 2 ? 1 : 0)); + expect(row.weight_x_32767).toBe(20000); + } + expect(await history(p, tid)).toHaveLength(3); +}); + +test("concurrent first votes through both writers allocate distinct participants without losing a vote", async () => { + const before = Number( + (await admin.query("SELECT count(*) FROM participants WHERE zid=$1", [zid])) + .rows[0].count + ); + const newParticipants = await Promise.all( + Array.from({ length: PARTICIPANTS }, (_, i) => + enrolled(i % 2 ? primary : secondary) + ) + ); + expect(new Set(newParticipants.map((p) => p.pid)).size).toBe(PARTICIPANTS); + expect(new Set(newParticipants.map((p) => p.uid)).size).toBe(PARTICIPANTS); + expect( + Number( + ( + await admin.query("SELECT count(*) FROM participants WHERE zid=$1", [ + zid, + ]) + ).rows[0].count + ) + ).toBe(before + PARTICIPANTS); + for (const p of newParticipants) + expect(await history(p, tids[0])).toHaveLength(1); +}); + +test("two first writes for one generated identity allocate one participant and store both votes", async () => { + // participationInit does not issue an anonymous identity before a first + // write. Make a generated user and use the real issuer for the join race. + const uid = ( + await admin.query( + "INSERT INTO users(hname,email) VALUES($1,$2) RETURNING uid", + ["Generated shared identity", `${randomUUID()}@example.invalid`] + ) + ).rows[0].uid; + const p = { uid, pid: -1, token: issueAnonymousJWT(conversationId, uid, -1) }; + const before = ( + await admin.query("SELECT * FROM participants WHERE zid=$1 AND uid=$2", [ + zid, + p.uid, + ]) + ).rows; + const outcomes = await Promise.all([ + vote(primary, p, tids[12], "agree"), + vote(secondary, p, tids[13], "disagree"), + ]); + prompt(outcomes); + const rows = ( + await admin.query("SELECT pid FROM participants WHERE zid=$1 AND uid=$2", [ + zid, + p.uid, + ]) + ).rows; + expect(rows).toHaveLength(1); + expect(outcomes.map((x) => x.body.currentPid)).toEqual([ + rows[0].pid, + rows[0].pid, + ]); + p.pid = rows[0].pid; + expect(await history(p, tids[12])).toHaveLength(1); + expect(await history(p, tids[13])).toHaveLength(1); + output({ + same_identity_memberships_before: before.length, + same_identity_memberships_after: rows.length, + }); +}); + +test("pid zero is an admitted durable participant at both writers", async () => { + const row = ( + await admin.query("SELECT uid FROM participants WHERE zid=$1 AND pid=0", [ + zid, + ]) + ).rows[0]; + const p = { + uid: row.uid, + pid: 0, + token: issueAnonymousJWT(conversationId, row.uid, 0), + }; + const comment = await call(primary, participants[0], "comments", { + conversation_id: conversationId, + txt: `Generated pid zero target ${randomUUID()}`, + vote: semanticToWire("pass"), + }); + prompt([comment]); + prompt([await vote(primary, p, comment.body.tid, "agree")]); + prompt([await vote(secondary, p, comment.body.tid, "disagree")]); + expect(await history(p, comment.body.tid)).toHaveLength(2); + expect( + storageToSemantic((await latest(p, comment.body.tid)).vote, { convention }) + ).toBe("disagree"); +}); + +test("a second allocator never loses a first vote across another writer's commit boundary", async () => { + const writer = new Client({ + connectionString: process.env.DATABASE_URL, + application_name: "mixed-writer-allocator", + }); + await writer.connect(); + let pending: Promise | undefined; + try { + const uid = ( + await admin.query( + "INSERT INTO users(hname,email) VALUES($1,$2) RETURNING uid", + ["Generated allocator participant", `${randomUUID()}@example.invalid`] + ) + ).rows[0].uid; + await writer.query("BEGIN"); + const inserted = ( + await writer.query( + "INSERT INTO participants(pid,zid,uid) VALUES(NULL,$1,$2) RETURNING pid", + [zid, uid] + ) + ).rows[0]; + const writerPid = (await writer.query("SELECT pg_backend_pid() AS pid")) + .rows[0].pid; + pending = vote(secondary, undefined, tids[15], "agree"); + await until( + async () => + ( + await admin.query( + `SELECT EXISTS(SELECT 1 FROM pg_stat_activity + WHERE datname=current_database() AND $1=ANY(pg_blocking_pids(pid))) AS waiting`, + [writerPid] + ) + ).rows[0].waiting, + "second allocator reaches the uncommitted first writer" + ); + await snapshot("allocator-before-first-commit"); + await writer.query("COMMIT"); + const outcome = await pending; + output({ + allocator_first_pid: inserted.pid, + allocator_second_status: outcome.status, + allocator_second_error: outcome.status === 200 ? null : outcome.body, + }); + prompt([outcome]); + expect(outcome.body.currentPid).not.toBe(inserted.pid); + const stored = ( + await admin.query( + "SELECT * FROM votes WHERE zid=$1 AND pid=$2 AND tid=$3", + [zid, outcome.body.currentPid, tids[15]] + ) + ).rows; + expect(stored).toHaveLength(1); + } finally { + await writer.query("ROLLBACK").catch(() => undefined); + await writer.end(); + if (pending) await pending; + } +}); + +test("omitted, true, false and repeated stars retain separate history and importance", async () => { + const p = participants[1], + tid = tids[14]; + prompt([await vote(primary, p, tid, "agree", { high_priority: true })]); + expect( + ( + await admin.query( + "SELECT * FROM stars WHERE zid=$1 AND pid=$2 AND tid=$3", + [zid, p.pid, tid] + ) + ).rows + ).toHaveLength(0); + for (const starred of [true, false, false]) + prompt([await vote(secondary, p, tid, "agree", { starred })]); + expect(await history(p, tid)).toHaveLength(4); + expect( + (await history(p, tid)).filter((row) => row.high_priority) + ).toHaveLength(1); + const stars = ( + await admin.query( + "SELECT starred FROM stars WHERE zid=$1 AND pid=$2 AND tid=$3", + [zid, p.pid, tid] + ) + ).rows; + expect(stars).toHaveLength(3); + expect(stars.filter((row) => Boolean(row.starred))).toHaveLength(1); +}); + +test("mixed writes stay prompt while every slow-work pool is occupied and result work awaits its model", async () => { + const clients: PoolClient[] = [], + long: Promise[] = []; + let answer!: () => void; + const model = new Promise((resolve) => { + answer = resolve; + }); + let waiting = 0; + try { + await Promise.all( + Array.from({ length: RESULT_SNAPSHOT_POOL_MAX }, async () => { + const client = await pg.connectResultSnapshot(); + try { + await client.query("SELECT 1"); + } finally { + client.release(); + } + waiting++; + long.push(model); + }) + ); + expect(waiting).toBe(RESULT_SNAPSHOT_POOL_MAX); + for (const [n, connect] of [ + [MAIN_POOL_MAX, () => pg.connect()], + [MAIN_POOL_MAX, () => pg.connectReadOnly()], + [AGENT_EXCHANGE_POOL_MAX, () => pg.connectAgentExchange()], + [RESULT_SNAPSHOT_POOL_MAX, () => pg.connectResultSnapshot()], + ] as [number, () => Promise][]) { + for (let i = 0; i < n; i++) clients.push(await connect()); + } + await admin.query("SELECT pg_advisory_lock($1,$2)", [72189, zid]); + for (let i = 0; i < REPORT_EXPORT_POOL_MAX; i++) + long.push( + pg.queryP_reportExport( + "SELECT pg_advisory_xact_lock_shared($1,$2) /* mixed writer export barrier */", + [72189, zid] + ) + ); + await until( + async () => + ( + await admin.query(`SELECT count(*)::int AS n FROM pg_stat_activity + WHERE datname=current_database() AND wait_event_type='Lock' AND query LIKE '%mixed writer export barrier%'`) + ).rows[0].n === REPORT_EXPORT_POOL_MAX, + "all export connections parked" + ); + const before = await snapshot("slow-work-parked"); + expect( + before.filter((row) => row.state?.startsWith("idle in transaction")) + ).toHaveLength(0); + const outcomes = await burst(tids[9], true); + expect(waiting).toBe(RESULT_SNAPSHOT_POOL_MAX); + prompt(outcomes); + const after = await snapshot("participation-complete-before-release"); + expect( + after.filter( + (row) => + row.query.includes("mixed writer export barrier") && + row.wait_event_type === "Lock" + ) + ).toHaveLength(REPORT_EXPORT_POOL_MAX); + await durable(outcomes, tids[9]); + } finally { + answer(); + clients.forEach((client) => client.release()); + await admin.query("SELECT pg_advisory_unlock_all()"); + await Promise.allSettled(long); + } +}, 120000); + +test("same-conversation maintenance row locks leave participation responsive", async () => { + const blocker = new Client({ + connectionString: process.env.DATABASE_URL, + application_name: "mixed-writer-slow-row", + }); + await blocker.connect(); + let outcomes: Outcome[] = [], + first: Outcome[] = []; + try { + await blocker.query("BEGIN"); + // Model the import batch's conversation participant_count update and the + // bulk participant statistics update with their non-key row lock mode. + // These are existing participants. A fresh join updates participant_count + // through pid_auto; this wave does not qualify fresh joins behind an import. + await blocker.query( + "SELECT zid FROM conversations WHERE zid=$1 FOR NO KEY UPDATE", + [zid] + ); + const heldParticipants = await blocker.query( + "SELECT pid FROM participants WHERE zid=$1 AND pid=ANY($2::int[]) FOR NO KEY UPDATE", + [zid, participants.map((p) => p.pid)] + ); + expect(heldParticipants.rows).toHaveLength(PARTICIPANTS); + // Verify the blocker directly: successful isolation removes the old + // participation-pool waiters, so their existence cannot be a prerequisite. + // A separate observer attempts the same row locks with NOWAIT below. + first = await Promise.all( + participants.map((p, i) => + vote(i % 2 ? primary : secondary, p, tids[10], "agree") + ) + ); + // Keep the first wave's failures too, but collect all three participation + // operations and lock ownership before asserting or releasing slow work. + await expect( + admin.query( + "SELECT zid FROM conversations WHERE zid=$1 FOR NO KEY UPDATE NOWAIT", + [zid] + ) + ).rejects.toMatchObject({ code: "55P03" }); + for (const participant of participants) { + await expect( + admin.query( + "SELECT pid FROM participants WHERE zid=$1 AND pid=$2 FOR NO KEY UPDATE NOWAIT", + [zid, participant.pid] + ) + ).rejects.toMatchObject({ code: "55P03" }); + } + await snapshot("same-row-held-before-participation"); + outcomes = await burst(tids[11], true); + await snapshot("same-row-held-after-participation"); + prompt(first); + prompt(outcomes); + await durable(outcomes, tids[11]); + } finally { + // Retain failures before releasing the lock; release cannot turn a timeout + // into a successful measured request. Inspect ambiguous commits separately. + output({ + same_row_outcomes_before_release: [...first, ...outcomes].map( + ({ body: _body, ...rest }) => rest + ), + }); + await blocker.query("ROLLBACK").catch(() => undefined); + await blocker.end(); + // The client giving up does not cancel Node's queued work. Keep this + // generated fixture and the process alive until every attempted mutation + // is independently visible; otherwise Jest's forceExit could manufacture + // apparent loss by killing requests during cleanup. + const texts = outcomes + .filter((outcome) => outcome.op === "comments") + .map((outcome) => outcome.text); + if (first.length === PARTICIPANTS && outcomes.length === PARTICIPANTS * 3) { + await until( + async () => { + const votes = ( + await admin.query( + `SELECT count(*)::int AS n FROM votes + WHERE zid=$1 AND tid=ANY($2::int[]) AND pid=ANY($3::int[])`, + [zid, [tids[10], tids[11]], participants.map((p) => p.pid)] + ) + ).rows[0].n; + const comments = ( + await admin.query( + "SELECT count(*)::int AS n FROM comments WHERE zid=$1 AND txt=ANY($2::text[])", + [zid, texts] + ) + ).rows[0].n; + return votes === PARTICIPANTS * 2 && comments === PARTICIPANTS; + }, + "queued mutations visible after releasing slow work", + 30000 + ); + const storedCounts = ( + await admin.query("SELECT vote_count FROM participants WHERE zid=$1", [ + zid, + ]) + ).rows; + expect(storedCounts.every((p) => p.vote_count === 0)).toBe(true); + for (const p of participants) { + for (const tid of [tids[10], tids[11]]) { + expect(await history(p, tid)).toHaveLength(1); + expect( + storageToSemantic((await latest(p, tid)).vote, { convention }) + ).toBe("agree"); + } + } + const comments = ( + await admin.query( + "SELECT pid,uid,tid,txt FROM comments WHERE zid=$1 AND txt=ANY($2::text[])", + [zid, texts] + ) + ).rows; + expect(new Set(comments.map((row) => row.tid)).size).toBe(PARTICIPANTS); + for (const out of outcomes.filter( + (outcome) => outcome.op === "comments" + )) { + const p = participants.find((p) => p.pid === out.pid)!; + const rows = comments.filter((row) => row.txt === out.text); + expect(rows).toHaveLength(1); + expect(rows[0].pid).toBe(p.pid); + expect(rows[0].uid).toBe(p.uid); + } + } + await until( + async () => { + const activity = + await admin.query(`SELECT count(*)::int AS n FROM pg_stat_activity + WHERE datname=current_database() AND cardinality(pg_blocking_pids(pid))>0 + AND (query LIKE 'update participants%' OR query LIKE 'update conversations%')`); + return activity.rows[0].n === 0; + }, + "blocked notification work released", + 30000 + ); + output({ + reconciliation_after_release: ( + await admin.query( + `SELECT pid,tid,count(*)::int AS rows + FROM votes WHERE zid=$1 AND tid=ANY($2::int[]) GROUP BY pid,tid ORDER BY pid,tid`, + [zid, [tids[10], tids[11]]] + ) + ).rows, + comments_after_release: ( + await admin.query( + "SELECT pid,uid,tid FROM comments WHERE zid=$1 AND txt=ANY($2::text[]) ORDER BY pid", + [zid, texts] + ) + ).rows, + }); + } +}, 120000); diff --git a/server/__tests__/integration/participation-pools.test.ts b/server/__tests__/integration/participation-pools.test.ts index 916b87c6c..272dc74b9 100644 --- a/server/__tests__/integration/participation-pools.test.ts +++ b/server/__tests__/integration/participation-pools.test.ts @@ -1,6 +1,6 @@ /** - * The participation path runs on pools nothing else uses, and nothing it does - * can reach another pool (src/db/pg-query.ts, src/db/participation-scope.ts). + * Foreground participation runs on pools nothing else uses. Its two kinds of + * best-effort notification write have their own bounded pool. * * - Structure: exactly the four participation routes (POST /votes, POST * /comments, GET /nextComment, GET /participationInit) enter the @@ -9,8 +9,8 @@ * - Construction: in that scope every query helper takes its connection from a * participation pool; outside it none does. * - Requests: every connection a participation request takes, from its first - * middleware to the bookkeeping it schedules, comes from a participation - * pool, for every kind of participant and route variant below; other work + * middleware through its response, comes from a participation pool, except + * the explicitly checked notification SQL. Other work * (report tallies, exports, the opinion map, a participant's vote list, * admin reads) never takes one. * @@ -44,6 +44,8 @@ const BOOKKEEPING_MS = 800; // Every pooled connection is taken through Pool.prototype.connect (pg-pool's // own query() calls it too). Record which pool each one came from. let taken: PoolRole[] | null = null; +let notificationQueries: string[] = []; +const realPoolQuery = Pool.prototype.query; const PoolPrototype = Pool.prototype as unknown as { connect: (...args: unknown[]) => unknown; }; @@ -54,6 +56,10 @@ const hadOwnConnect = Object.prototype.hasOwnProperty.call( const realConnect = PoolPrototype.connect; beforeAll(() => { + Pool.prototype.query = function(this: Pool, ...args: any[]) { + if (taken && poolRole(this) === "notification") notificationQueries.push(String(args[0])); + return realPoolQuery.apply(this, args); + } as typeof Pool.prototype.query; PoolPrototype.connect = function (this: Pool, ...args: unknown[]) { const role = poolRole(this); if (taken && role) taken.push(role); @@ -61,6 +67,7 @@ beforeAll(() => { }; }); afterAll(() => { + Pool.prototype.query = realPoolQuery; if (hadOwnConnect) PoolPrototype.connect = realConnect; else delete (PoolPrototype as { connect?: unknown }).connect; }); @@ -71,6 +78,7 @@ async function poolsTakenBy( settleMs = BOOKKEEPING_MS ): Promise<{ roles: PoolRole[]; result: any }> { taken = []; + notificationQueries = []; try { const result = await work(); await wait(settleMs); @@ -245,7 +253,7 @@ describe("requests", () => { const bearer = (token: string) => ({ Authorization: `Bearer ${token}` }); /** One participation request: it answered 200, and every connection it - * and its bookkeeping took came from a participation pool. */ + * took came from a participation pool, except bounded notification writes. */ async function participation(name: string, send: () => request.Test) { const { roles, result } = await poolsTakenBy(() => send()); process.stdout.write( @@ -259,8 +267,12 @@ describe("requests", () => { expect(roles.length).toBeGreaterThan(0); expect({ name, - other: roles.filter((role) => !isParticipation(role)), + other: roles.filter((role) => !isParticipation(role) && role !== "notification"), }).toEqual({ name, other: [] }); + for (const query of notificationQueries) { + expect(query).toMatch(/^(update participants set last_interaction = now_as_millis\(\), nsli = 0|insert into notification_tasks \(zid\))/); + } + expect(roles.filter(role => role === "notification")).toHaveLength(notificationQueries.length); return result.body; } @@ -282,7 +294,7 @@ describe("requests", () => { return roles; } - test("every participation request, of every kind of participant, takes only participation connections", async () => { + test("participation uses its pools; only notification state uses the notification pool", async () => { const init = (query: string, token?: string) => { const sent = request(app).get(`/api/v3/participationInit?${query}`); return token ? sent.set(bearer(token)) : sent; diff --git a/server/__tests__/integration/xid-list-moderators-only.test.ts b/server/__tests__/integration/xid-list-moderators-only.test.ts index f64c352a8..77a842ca3 100644 --- a/server/__tests__/integration/xid-list-moderators-only.test.ts +++ b/server/__tests__/integration/xid-list-moderators-only.test.ts @@ -78,7 +78,7 @@ describe("the participant XID list: owner and moderators only", () => { const inUseRows = async () => ( await pool.query( - `SELECT p.pid, x.xid, COALESCE(p.vote_count, 0) AS vote_count + `SELECT p.pid, x.xid, (SELECT count(*)::int FROM votes v WHERE v.zid=p.zid AND v.pid=p.pid) AS vote_count FROM xids x JOIN participants p ON p.uid = x.uid WHERE p.zid = $1 AND x.owner = $2 ORDER BY p.pid`, diff --git a/server/__tests__/setup/mixed-writer-observer.cjs b/server/__tests__/setup/mixed-writer-observer.cjs new file mode 100644 index 000000000..5a1e56dc4 --- /dev/null +++ b/server/__tests__/setup/mixed-writer-observer.cjs @@ -0,0 +1,35 @@ +/* Pool diagnostics only: preserve callbacks, queries, releases and limits. */ +const { Pool } = require("pg"); +const seen = new Set(); +const waits = []; +const original = Pool.prototype.connect; +Pool.prototype.connect = function (callback) { + seen.add(this); + const started = performance.now(); + const queued = this.waitingCount; + const record = () => waits.push({ ms: performance.now() - started, queued }); + if (callback) + return original.call(this, (error, client, release) => { + record(); + callback(error, client, release); + }); + return original.call(this).then((client) => { + record(); + return client; + }); +}; +exports.snapshot = () => { + const { poolRole } = require("../../src/db/pg-query"); + return { + pools: [...seen].map((pool) => ({ + role: poolRole(pool), + max: pool.options.max, + total: pool.totalCount, + idle: pool.idleCount, + waiting: pool.waitingCount, + backendPids: pool._clients.map((client) => client.processID), + })), + acquisitions: waits.splice(0), + }; +}; +exports.close = () => Promise.all([...seen].map((pool) => pool.end())); diff --git a/server/__tests__/setup/mixed-writer-process.cjs b/server/__tests__/setup/mixed-writer-process.cjs new file mode 100644 index 000000000..70a770cf6 --- /dev/null +++ b/server/__tests__/setup/mixed-writer-process.cjs @@ -0,0 +1,33 @@ +/* Test-only second Node process. The HTTP surface is the unchanged app. + * IPC is used only for readiness, pool observations and orderly shutdown. */ +require("ts-node/register/transpile-only"); +const observer = require("./mixed-writer-observer.cjs"); +const app = require("../../app").default; +const requests = []; +const server = app.listen(0, "127.0.0.1", () => { + process.send({ ready: true, port: server.address().port, pid: process.pid }); +}); +server.on("request", (req, res) => { + res.once("finish", () => + requests.push({ + method: req.method, + path: req.url.split("?")[0], + status: res.statusCode, + }) + ); +}); +process.on("message", async (message) => { + if (message.op === "snapshot") { + process.send({ + id: message.id, + ...observer.snapshot(), + requests: requests.splice(0), + }); + } + if (message.op === "stop") { + server.close(async () => { + await observer.close(); + process.exit(0); + }); + } +}); diff --git a/server/__tests__/unit/commentToxicityCheckOff.test.ts b/server/__tests__/unit/commentToxicityCheckOff.test.ts index 5fd5465bf..8357c51ff 100644 --- a/server/__tests__/unit/commentToxicityCheckOff.test.ts +++ b/server/__tests__/unit/commentToxicityCheckOff.test.ts @@ -26,7 +26,7 @@ jest.mock("../../src/config", () => ({ })); jest.mock("../../src/db/pg-query", () => ({ __esModule: true, - default: { queryP: mockQuery, queryP_readOnly: mockQuery }, + default: { queryP: mockQuery, queryP_readOnly: mockQuery, queryP_notification: jest.fn(async () => []) }, })); jest.mock("../../src/utils/logger", () => ({ __esModule: true, @@ -60,6 +60,7 @@ jest.mock("../../src/utils/common", () => ({ jest.mock("../../src/routes/votes", () => ({ votesPost: jest.fn() })); jest.mock("../../src/server-helpers", () => ({ safeTimestampToMillis: (n: number) => n, + updateLastInteractionTimeForConversation: jest.fn(async () => []), })); jest.mock("../../src/utils/zinvite", () => ({})); jest.mock("../../src/utils/metered", () => ({})); diff --git a/server/__tests__/unit/commentTranslation.test.ts b/server/__tests__/unit/commentTranslation.test.ts index e9ee90d36..1666936de 100644 --- a/server/__tests__/unit/commentTranslation.test.ts +++ b/server/__tests__/unit/commentTranslation.test.ts @@ -20,7 +20,7 @@ jest.mock("../../src/config", () => ({ })); jest.mock("../../src/db/pg-query", () => ({ __esModule: true, - default: { queryP: mockQuery }, + default: { queryP: mockQuery, queryP_notification: jest.fn().mockResolvedValue([]) }, })); jest.mock("../../src/utils/logger", () => ({ __esModule: true, @@ -49,6 +49,7 @@ jest.mock("../../src/utils/common", () => ({ jest.mock("../../src/routes/votes", () => ({ votesPost: mockVote })); jest.mock("../../src/server-helpers", () => ({ safeTimestampToMillis: (n: number) => n, + updateLastInteractionTimeForConversation: jest.fn().mockResolvedValue([]), })); jest.mock("../../src/utils/zinvite", () => ({})); jest.mock("../../src/utils/metered", () => ({})); diff --git a/server/__tests__/unit/commentUniqueViolation.test.ts b/server/__tests__/unit/commentUniqueViolation.test.ts index dd9c44457..b9976bac8 100644 --- a/server/__tests__/unit/commentUniqueViolation.test.ts +++ b/server/__tests__/unit/commentUniqueViolation.test.ts @@ -19,7 +19,7 @@ jest.mock("../../src/config", () => ({ })); jest.mock("../../src/db/pg-query", () => ({ __esModule: true, - default: { queryP: mockQuery, queryP_readOnly: mockQuery }, + default: { queryP: mockQuery, queryP_readOnly: mockQuery, queryP_notification: jest.fn(async () => []) }, })); jest.mock("../../src/utils/logger", () => ({ __esModule: true, diff --git a/server/__tests__/unit/conversationsRoutes.test.ts b/server/__tests__/unit/conversationsRoutes.test.ts index 5e643fb61..182db5780 100644 --- a/server/__tests__/unit/conversationsRoutes.test.ts +++ b/server/__tests__/unit/conversationsRoutes.test.ts @@ -7,7 +7,7 @@ jest.mock("../../src/db/pg-query", () => { return { __esModule: true, default: { - queryP_readOnly: jest.fn(), + queryP_reportExport: jest.fn(), }, }; }); @@ -64,14 +64,14 @@ describe("conversations routes - handle_GET_all_conversations", () => { 403, "polis_err_no_access_for_this_user" ); - expect(pg.queryP_readOnly).not.toHaveBeenCalled(); + expect(pg.queryP_reportExport).not.toHaveBeenCalled(); }); it("returns paginated conversations for admin users", async () => { (isPolisDev as jest.Mock).mockReturnValue(true); // First call: main SELECT query (page rows), Second call: COUNT query - (pg.queryP_readOnly as jest.Mock) + (pg.queryP_reportExport as jest.Mock) .mockResolvedValueOnce([ { zid: 1, @@ -120,6 +120,6 @@ describe("conversations routes - handle_GET_all_conversations", () => { }); // Validate that DB was called twice: count and page - expect(pg.queryP_readOnly).toHaveBeenCalledTimes(2); + expect(pg.queryP_reportExport).toHaveBeenCalledTimes(2); }); }); diff --git a/server/__tests__/unit/seedAutomaticPass.test.ts b/server/__tests__/unit/seedAutomaticPass.test.ts index ce6e39545..b1f37c867 100644 --- a/server/__tests__/unit/seedAutomaticPass.test.ts +++ b/server/__tests__/unit/seedAutomaticPass.test.ts @@ -23,7 +23,7 @@ jest.mock("auth0", () => ({ ManagementClient: jest.fn() })); jest.mock("../../src/config", () => ({ __esModule: true, default: {} })); jest.mock("../../src/db/pg-query", () => ({ __esModule: true, - default: { queryP: mockQuery, queryP_readOnly: mockQuery }, + default: { queryP: mockQuery, queryP_readOnly: mockQuery, queryP_notification: jest.fn(async () => []) }, })); jest.mock("../../src/utils/logger", () => ({ __esModule: true, diff --git a/server/characterization/routing/expected-differences.json b/server/characterization/routing/expected-differences.json index e7998a0ae..74357851b 100644 --- a/server/characterization/routing/expected-differences.json +++ b/server/characterization/routing/expected-differences.json @@ -14403,8 +14403,8 @@ { "case": "http/ordinary/owner/POST/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -14458,7 +14458,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"nextComment\": {\n \"txt\": \"Generated statement 5\",\n \"tid\": 5,\n \"created\": \"1700000000005\",\n \"quote_src_url\": null,\n \"is_seed\": false,\n \"is_meta\": false,\n \"lang\": \"en\",\n \"pid\": 0,\n \"original_id\": null,\n \"randomN\": 6.25,\n \"remaining\": 2,\n \"total\": 6,\n \"translations\": []\n },\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 7, + "postgresStatements": 8, "dynamoCalls": 0, "mathBytes": 0 } @@ -14470,9 +14470,7 @@ "SELECT * FROM conversations WHERE zid = ($1);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], "dynamo": [], @@ -14496,15 +14494,15 @@ "draws": [ 0.625 ], - "postgresStatements": 10, + "postgresStatements": 8, "dynamoCalls": 0 } }, { "case": "http/ordinary/owner/POST/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -14543,7 +14541,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 8, + "postgresStatements": 9, "dynamoCalls": 0, "mathBytes": 0 } @@ -14556,9 +14554,7 @@ "insert into event_ptpt_no_more_comments (zid, pid, votes_placed) values ($1, $2, (select count(*) from votes where zid = ($1) and pid = ($2)))", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], "dynamo": [], @@ -14566,15 +14562,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 11, + "postgresStatements": 9, "dynamoCalls": 0 } }, { "case": "http/ordinary/owner/POST/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -14628,7 +14624,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"nextComment\": {\n \"txt\": \"Generated statement 5\",\n \"tid\": 5,\n \"created\": \"1700000000005\",\n \"quote_src_url\": null,\n \"is_seed\": false,\n \"is_meta\": false,\n \"lang\": \"en\",\n \"pid\": 0,\n \"original_id\": null,\n \"randomN\": 6.25,\n \"remaining\": 2,\n \"total\": 6,\n \"translations\": []\n },\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 7, + "postgresStatements": 8, "dynamoCalls": 0, "mathBytes": 0 } @@ -14640,9 +14636,7 @@ "SELECT * FROM conversations WHERE zid = ($1);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], "dynamo": [], @@ -14666,7 +14660,7 @@ "draws": [ 0.625 ], - "postgresStatements": 10, + "postgresStatements": 8, "dynamoCalls": 0 } }, @@ -14975,8 +14969,8 @@ { "case": "http/ordinary/second/POST/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -15042,7 +15036,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"nextComment\": {\n \"txt\": \"Generated statement 4\",\n \"tid\": 4,\n \"created\": \"1700000000004\",\n \"quote_src_url\": null,\n \"is_seed\": true,\n \"is_meta\": false,\n \"lang\": \"en\",\n \"pid\": 0,\n \"original_id\": null,\n \"randomN\": 11.875,\n \"remaining\": 5,\n \"total\": 6,\n \"translations\": []\n },\n \"currentPid\": 7\n}", "beforeDeferred": { - "postgresStatements": 7, + "postgresStatements": 8, "dynamoCalls": 0, "mathBytes": 0 } @@ -15054,9 +15048,7 @@ "SELECT * FROM conversations WHERE zid = ($1);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], "dynamo": [], @@ -15092,15 +15084,15 @@ "draws": [ 0.625 ], - "postgresStatements": 10, + "postgresStatements": 8, "dynamoCalls": 0 } }, { "case": "http/ordinary/second/POST/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -15139,7 +15131,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 7\n}", "beforeDeferred": { - "postgresStatements": 8, + "postgresStatements": 9, "dynamoCalls": 0, "mathBytes": 0 } @@ -15152,9 +15144,7 @@ "insert into event_ptpt_no_more_comments (zid, pid, votes_placed) values ($1, $2, (select count(*) from votes where zid = ($1) and pid = ($2)))", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], "dynamo": [], @@ -15162,15 +15152,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 11, + "postgresStatements": 9, "dynamoCalls": 0 } }, { "case": "http/ordinary/second/POST/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -15236,7 +15226,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"nextComment\": {\n \"txt\": \"Generated statement 4\",\n \"tid\": 4,\n \"created\": \"1700000000004\",\n \"quote_src_url\": null,\n \"is_seed\": true,\n \"is_meta\": false,\n \"lang\": \"en\",\n \"pid\": 0,\n \"original_id\": null,\n \"randomN\": 11.875,\n \"remaining\": 5,\n \"total\": 6,\n \"translations\": []\n },\n \"currentPid\": 7\n}", "beforeDeferred": { - "postgresStatements": 7, + "postgresStatements": 8, "dynamoCalls": 0, "mathBytes": 0 } @@ -15248,9 +15238,7 @@ "SELECT * FROM conversations WHERE zid = ($1);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], "dynamo": [], @@ -15286,7 +15274,7 @@ "draws": [ 0.625 ], - "postgresStatements": 10, + "postgresStatements": 8, "dynamoCalls": 0 } }, @@ -15709,8 +15697,8 @@ { "case": "http/topical/owner/POST/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -15789,7 +15777,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"nextComment\": {\n \"txt\": \"Generated statement 5\",\n \"tid\": 5,\n \"created\": \"1700000000005\",\n \"quote_src_url\": null,\n \"is_seed\": false,\n \"is_meta\": false,\n \"lang\": \"en\",\n \"pid\": 0,\n \"original_id\": null,\n \"randomN\": 6.25,\n \"remaining\": 2,\n \"total\": 6,\n \"translations\": []\n },\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 11, + "postgresStatements": 12, "dynamoCalls": 2, "mathBytes": 0 } @@ -15805,9 +15793,7 @@ "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], "dynamo": [ @@ -15852,15 +15838,15 @@ 0.625, 0.625 ], - "postgresStatements": 14, + "postgresStatements": 12, "dynamoCalls": 2 } }, { "case": "http/topical/owner/POST/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -15930,7 +15916,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 16, + "postgresStatements": 17, "dynamoCalls": 2, "mathBytes": 0 } @@ -15950,9 +15936,7 @@ "insert into event_ptpt_no_more_comments (zid, pid, votes_placed) values ($1, $2, (select count(*) from votes where zid = ($1) and pid = ($2)))", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -15984,15 +15968,15 @@ "draws": [ 0.625 ], - "postgresStatements": 19, + "postgresStatements": 17, "dynamoCalls": 2 } }, { "case": "http/topical/owner/POST/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -16071,7 +16055,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"nextComment\": {\n \"txt\": \"Generated statement 5\",\n \"tid\": 5,\n \"created\": \"1700000000005\",\n \"quote_src_url\": null,\n \"is_seed\": false,\n \"is_meta\": false,\n \"lang\": \"en\",\n \"pid\": 0,\n \"original_id\": null,\n \"randomN\": 6.25,\n \"remaining\": 2,\n \"total\": 6,\n \"translations\": []\n },\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 11, + "postgresStatements": 12, "dynamoCalls": 2, "mathBytes": 0 } @@ -16087,9 +16071,7 @@ "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], "dynamo": [ @@ -16134,7 +16116,7 @@ 0.625, 0.625 ], - "postgresStatements": 14, + "postgresStatements": 12, "dynamoCalls": 2 } }, @@ -16261,8 +16243,8 @@ { "case": "http/topical/second/POST/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", "before": { "value": { "status": 200, @@ -16332,7 +16314,7 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 7\n}", "beforeDeferred": { - "postgresStatements": 16, + "postgresStatements": 17, "dynamoCalls": 2, "mathBytes": 0 } @@ -16352,9 +16334,7 @@ "insert into event_ptpt_no_more_comments (zid, pid, votes_placed) values ($1, $2, (select count(*) from votes where zid = ($1) and pid = ($2)))", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", - "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -16386,7 +16366,279 @@ "draws": [ 0.625 ], - "postgresStatements": 19, + "postgresStatements": 17, + "dynamoCalls": 2 + } + }, + { + "case": "http/topical/second/POST/seeds", + "status": "ruled", + "reason": "Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "before": { + "value": { + "status": 200, + "contentType": "application/json; charset=utf-8", + "text": "{\n \"nextComment\": {\n \"zid\": 1,\n \"tid\": 2,\n \"txt\": \"Generated statement 2\",\n \"translations\": []\n },\n \"currentPid\": 7\n}", + "beforeDeferred": { + "postgresStatements": 6, + "dynamoCalls": 2, + "mathBytes": 0 + } + }, + "sql": [ + "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", + "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (1=1)) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from conversations where zid = ($1);", + "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", + "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", + "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)" + ], + "dynamo": [ + { + "TableName": "Delphi_CommentClustersLLMTopicNames", + "KeyConditionExpression": "conversation_id = :cid AND topic_key = :tk", + "ExpressionAttributeValues": { + ":cid": "1", + ":tk": "job#0#1" + } + }, + { + "TableName": "Delphi_CommentHierarchicalClusterAssignments", + "KeyConditionExpression": "conversation_id = :cid", + "ExpressionAttributeValues": { + ":cid": "1" + } + } + ], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "topical", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 2, + "weight": 1 + }, + { + "tid": 4, + "weight": 1 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 9, + "dynamoCalls": 2 + }, + "after": { + "value": { + "status": 200, + "contentType": "application/json; charset=utf-8", + "text": "{\n \"nextComment\": {\n \"zid\": 1,\n \"tid\": 2,\n \"txt\": \"Generated statement 2\",\n \"translations\": []\n },\n \"currentPid\": 7\n}", + "beforeDeferred": { + "postgresStatements": 7, + "dynamoCalls": 2, + "mathBytes": 0 + } + }, + "sql": [ + "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", + "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (1=1)) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from conversations where zid = ($1);", + "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);" + ], + "dynamo": [ + { + "TableName": "Delphi_CommentClustersLLMTopicNames", + "KeyConditionExpression": "conversation_id = :cid AND topic_key = :tk", + "ExpressionAttributeValues": { + ":cid": "1", + ":tk": "job#0#1" + } + }, + { + "TableName": "Delphi_CommentHierarchicalClusterAssignments", + "KeyConditionExpression": "conversation_id = :cid", + "ExpressionAttributeValues": { + ":cid": "1" + } + } + ], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "topical", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 2, + "weight": 1 + }, + { + "tid": 4, + "weight": 1 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 7, + "dynamoCalls": 2 + } + }, + { + "case": "http/topical/second/POST/large-math", + "status": "ruled", + "reason": "Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", + "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "before": { + "value": { + "status": 200, + "contentType": "application/json; charset=utf-8", + "text": "{\n \"nextComment\": {\n \"zid\": 1,\n \"tid\": 2,\n \"txt\": \"Generated statement 2\",\n \"translations\": []\n },\n \"currentPid\": 7\n}", + "beforeDeferred": { + "postgresStatements": 6, + "dynamoCalls": 2, + "mathBytes": 0 + } + }, + "sql": [ + "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", + "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (1=1)) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from conversations where zid = ($1);", + "update conversations set modified = ($2) where zid = ($1) and modified < ($2);", + "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", + "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)" + ], + "dynamo": [ + { + "TableName": "Delphi_CommentClustersLLMTopicNames", + "KeyConditionExpression": "conversation_id = :cid AND topic_key = :tk", + "ExpressionAttributeValues": { + ":cid": "1", + ":tk": "job#0#1" + } + }, + { + "TableName": "Delphi_CommentHierarchicalClusterAssignments", + "KeyConditionExpression": "conversation_id = :cid", + "ExpressionAttributeValues": { + ":cid": "1" + } + } + ], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "topical", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 2, + "weight": 1 + }, + { + "tid": 4, + "weight": 1 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 9, + "dynamoCalls": 2 + }, + "after": { + "value": { + "status": 200, + "contentType": "application/json; charset=utf-8", + "text": "{\n \"nextComment\": {\n \"zid\": 1,\n \"tid\": 2,\n \"txt\": \"Generated statement 2\",\n \"translations\": []\n },\n \"currentPid\": 7\n}", + "beforeDeferred": { + "postgresStatements": 7, + "dynamoCalls": 2, + "mathBytes": 0 + } + }, + "sql": [ + "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", + "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (1=1)) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from conversations where zid = ($1);", + "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);" + ], + "dynamo": [ + { + "TableName": "Delphi_CommentClustersLLMTopicNames", + "KeyConditionExpression": "conversation_id = :cid AND topic_key = :tk", + "ExpressionAttributeValues": { + ":cid": "1", + ":tk": "job#0#1" + } + }, + { + "TableName": "Delphi_CommentHierarchicalClusterAssignments", + "KeyConditionExpression": "conversation_id = :cid", + "ExpressionAttributeValues": { + ":cid": "1" + } + } + ], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "topical", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 2, + "weight": 1 + }, + { + "tid": 4, + "weight": 1 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 7, "dynamoCalls": 2 } } diff --git a/server/src/db/activity.ts b/server/src/db/activity.ts new file mode 100644 index 000000000..fbb254535 --- /dev/null +++ b/server/src/db/activity.ts @@ -0,0 +1,16 @@ +/** SQL projections of activity; the retained column is the metadata/import clock. + * Only response readers use these expressions. Authorization/configuration reads + * keep their cheap row lookup. No vote value is interpreted by these counts. + */ +export function conversationModifiedSql(alias: string): string { + return `CASE WHEN ${alias}.modified IS NULL THEN NULL ELSE GREATEST(${alias}.modified, + (SELECT MAX(v.created) FROM votes v WHERE v.zid = ${alias}.zid), + (SELECT MAX(cm.created) FROM comments cm WHERE cm.zid = ${alias}.zid), + (SELECT MAX(cm.modified) FROM comments cm WHERE cm.zid = ${alias}.zid)) END`; +} + +// COUNT is cast to the existing integer wire type, including zero and revotes. +export function participantVoteCountSql(alias: string): string { + return `(SELECT CASE WHEN COUNT(*) = 0 AND ${alias}.vote_count IS NULL THEN NULL ELSE COUNT(*)::integer END FROM votes v + WHERE v.zid = ${alias}.zid AND v.pid = ${alias}.pid)`; +} diff --git a/server/src/db/participation-scope.ts b/server/src/db/participation-scope.ts index 8e5f375c7..37348d92b 100644 --- a/server/src/db/participation-scope.ts +++ b/server/src/db/participation-scope.ts @@ -3,9 +3,10 @@ * * Votes, comments, the next statement and participationInit enter this scope * as the first handler of their routes (app.ts). Everything that request does - * after it, its middleware, its handler and the bookkeeping it schedules, is + * after it, its middleware and its handler, is * in the scope, and db/pg-query.ts gives every query made in it a connection - * from the participation pools. Work that did not come through one of those + * from the participation pools. Notification state explicitly uses its bounded + * notification pool instead. Work that did not come through one of those * routes is never in the scope, so it has no way to reach those pools. * * The pool is chosen by where the work came from, not at each call site, so diff --git a/server/src/db/pg-query.ts b/server/src/db/pg-query.ts index e23f33e87..dd8cfa5dc 100644 --- a/server/src/db/pg-query.ts +++ b/server/src/db/pg-query.ts @@ -68,7 +68,8 @@ export type PoolRole = | "read" | "result-snapshot" | "report-export" - | "agent-exchange"; + | "agent-exchange" + | "notification"; const poolRoles = new WeakMap(); function withRole(pool: Pool, role: PoolRole): Pool { poolRoles.set(pool, role); @@ -165,11 +166,40 @@ function participationPoolsInstance(): PoolPair { // The pair a query uses: the participation pools for work that came through a // participation route (db/participation-scope.ts), the pair above for // everything else. Nothing outside that scope can reach the participation -// pools, and nothing inside it is given another pair. +// pools. Notification state explicitly uses its own bounded pool. function pools(): PoolPair { return onParticipationPath() ? participationPoolsInstance() : sharedPools; } +// Notification writes never inherit participation scope. Admission bounds the +// entire in-process queue as well as the number of PostgreSQL connections. +export const NOTIFICATION_POOL_MAX = 2; +export const NOTIFICATION_PENDING_MAX = 64; +let notificationPool: Pool | undefined; +let notificationPending = 0; +async function queryP_notification(queryString: string, params: any[] = []) { + if (notificationPending >= NOTIFICATION_PENDING_MAX) { + throw new Error("notification_queue_full"); + } + notificationPending++; + try { + if (!notificationPool) { + notificationPool = withRole(new Pool({ + ...pgConnection, + max: NOTIFICATION_POOL_MAX, + connectionTimeoutMillis: 250, + statement_timeout: 1000, + lock_timeout: 250, + } as unknown as PoolConfig), "notification"); + notificationPool.on("error", error => logger.error("pg_notification_pool", error)); + } + const result = await notificationPool.query(queryString, params); + return result.rows; + } finally { + notificationPending--; + } +} + // Same syntax as pg.client.query, but uses connection pool // Also takes care of calling 'done'. function queryImpl(pool: Pool, queryString: string, ...args: any[]) { @@ -685,6 +715,7 @@ export default { queryP_readOnly_wRetryIfEmpty, queryP_reportExport, queryP_agentExchange, + queryP_notification, isPoolAcquireTimeout, stream_queryP_readOnly, stream_queryP_reportExport, diff --git a/server/src/participant.ts b/server/src/participant.ts index 1af6ab951..d2289a935 100644 --- a/server/src/participant.ts +++ b/server/src/participant.ts @@ -414,7 +414,7 @@ function getSocialParticipants( const q = "with " + - "p as (select uid, pid, mod from participants where zid = ($1) and vote_count >= 1), " + + "p as (select uid, pid, mod from participants p0 where zid = ($1) and EXISTS (SELECT 1 FROM votes v WHERE v.zid=p0.zid AND v.pid=p0.pid)), " + "xids_subset as (select * from xids where owner in (select org_id from conversations where zid = ($1)) and x_profile_image_url is not null), " + "xid_ptpts as (select p.uid, 100 as priority from p inner join xids_subset on xids_subset.uid = p.uid where p.mod >= ($4)), " + "self as (select CAST($2 as INTEGER) as uid, 1000 as priority), " + diff --git a/server/src/routes/comments.ts b/server/src/routes/comments.ts index 0ba7f7ed7..4d8035ed7 100644 --- a/server/src/routes/comments.ts +++ b/server/src/routes/comments.ts @@ -28,9 +28,7 @@ import { finishOne, safeTimestampToMillis, sendEmailByUid, - updateConversationModifiedTime, updateLastInteractionTimeForConversation, - updateVoteCount, } from "../server-helpers"; import { parsePagination, createPaginationMeta } from "../utils/pagination"; @@ -295,10 +293,10 @@ async function handle_GET_comments(req: RequestWithP, res: any): Promise { } function addNotificationTask(zid: number): Promise { - return pg.queryP( + return pg.queryP_notification( "insert into notification_tasks (zid) values ($1) on conflict (zid) do update set modified = now_as_millis();", [zid] - ); + ).catch((error) => logger.warn("notification_task_deferred", { error })); } export async function isProConvo(owner: number): Promise { @@ -545,15 +543,8 @@ async function handle_POST_comments(req: RequestWithP, res: any) { addNotificationTask(zid); } - // 9. Schedule async updates - const createdTimeMillis = safeTimestampToMillis(comment.created); - setTimeout(() => { - updateConversationModifiedTime(zid, new Date(createdTimeMillis)); - updateLastInteractionTimeForConversation(zid, uid); - if (!_.isUndefined(vote)) { - updateVoteCount(zid, pid); - } - }, 100); + // Notification state cannot occupy a participation connection. + void updateLastInteractionTimeForConversation(zid, uid); // 10. Build response const response: any = { @@ -980,12 +971,9 @@ async function handle_POST_comments_bulk( } } - setTimeout(() => { - if (lastInteractionTime > new Date(0)) { - updateConversationModifiedTime(zid!, lastInteractionTime); - updateLastInteractionTimeForConversation(zid!, uid!); - } - }, 100); + if (lastInteractionTime > new Date(0)) { + void updateLastInteractionTimeForConversation(zid!, uid!); + } res.json({ results, diff --git a/server/src/routes/conversations.ts b/server/src/routes/conversations.ts index 09ce3f36d..c9d3a0c4f 100644 --- a/server/src/routes/conversations.ts +++ b/server/src/routes/conversations.ts @@ -7,6 +7,7 @@ import { getZinvite } from "../utils/zinvite"; import { sql_conversations } from "../db/sql"; import logger from "../utils/logger"; import pg from "../db/pg-query"; +import { conversationModifiedSql } from "../db/activity"; import { parsePagination, createPaginationMeta } from "../utils/pagination"; import { doGetConversationPreloadInfo, @@ -216,7 +217,7 @@ export async function getConversations(req: { p: ConversationType }, res: any) { // Build and execute main query const query = buildConversationsQuery(req, participantInOrSiteAdminOf); - let data = (await pg.queryP_readOnly(query.toString())) as any[]; + let data = (await pg.queryP_readOnly(`SELECT c.*, ${conversationModifiedSql("c")} AS modified FROM (${query.toString()}) c`)) as any[]; // Process the conversation data data = await processConversationData(data, req, isSiteAdmin); @@ -277,7 +278,7 @@ async function handle_GET_all_conversations( const ms = nowMs - Number(req.p.recently_updated_days) * 24 * 60 * 60 * 1000; params.push(ms); - where.push(`c.modified >= ($${params.length})`); + where.push(`${conversationModifiedSql("c")} >= ($${params.length})`); } if (!_.isUndefined(req.p.recently_created_days)) { const ms = @@ -306,7 +307,7 @@ async function handle_GET_all_conversations( switch (sortByRaw) { case "updated": case "modified": - sortBy = "c.modified"; + sortBy = conversationModifiedSql("c"); break; case "participant_count": sortBy = "pc.participant_count"; @@ -328,7 +329,7 @@ async function handle_GET_all_conversations( const sql = ` SELECT - c.*, + c.*, ${conversationModifiedSql("c")} AS modified, COALESCE(pc.participant_count, 0) AS participant_count, COALESCE(cc.comment_count, 0) AS comment_count, u.email AS owner_email @@ -350,7 +351,7 @@ async function handle_GET_all_conversations( ${paginationSql}; `; - const rows = (await pg.queryP_readOnly(sql, [ + const rows = (await pg.queryP_reportExport(sql, [ ...params, ...pagination.params, ])) as any[]; @@ -376,7 +377,7 @@ async function handle_GET_all_conversations( ${whereSql} ) t; `; - const totalRows = (await pg.queryP_readOnly(totalSql, params)) as Array<{ + const totalRows = (await pg.queryP_reportExport(totalSql, params)) as Array<{ count: string; }>; const total = Number(totalRows?.[0]?.count || 0); @@ -525,8 +526,8 @@ function doGetConversationsRecent( time *= 1000; } time = parseInt(time); - pg.queryP_readOnly( - "select * from conversations where " + field + " >= ($1);", + pg.queryP_reportExport( + `select c.*, ${conversationModifiedSql("c")} AS modified from conversations c where ${field === "modified" ? conversationModifiedSql("c") : "c.created"} >= ($1);`, [time] ) .then((rows: any) => { @@ -981,7 +982,7 @@ function handle_PUT_conversations( .returning("*"); Promise.all([verifyMetaPromise, settingGuard]).then( function () { - pg.query(q.toString(), function (err: any, result: { rows: any[] }) { + pg.query(q.toString() + `, ${conversationModifiedSql("conversations")} AS modified`, function (err: any, result: { rows: any[] }) { if (err) { failJson(res, 500, "polis_err_update_conversation", err); return; diff --git a/server/src/routes/notify.ts b/server/src/routes/notify.ts index 706ca03ef..23950c5f5 100644 --- a/server/src/routes/notify.ts +++ b/server/src/routes/notify.ts @@ -115,7 +115,7 @@ function unsubscribeFromNotifications(zid: number, uid?: number) { } function maybeAddNotificationTask(zid: number, timeInMillis: number) { - return pg.queryP( + return pg.queryP_notification( "insert into notification_tasks (zid, modified) values ($1, $2) on conflict (zid) do nothing;", [zid, timeInMillis] ); @@ -123,7 +123,7 @@ function maybeAddNotificationTask(zid: number, timeInMillis: number) { function claimNextNotificationTask() { return pg - .queryP( + .queryP_notification( "delete from notification_tasks where zid = (select zid from notification_tasks order by random() for update skip locked limit 1) returning *;" ) .then((rows: string | any[]) => { @@ -146,7 +146,7 @@ function doNotificationBatch() { // Since we claimed the task above, there will be no record, so we need to // put it back to trigger a retry - unless there's a new one there, in which case we should // leave the new one. - maybeAddNotificationTask(task.zid, task.modified); + return maybeAddNotificationTask(task.zid, task.modified).then(() => undefined); } } ); @@ -156,7 +156,7 @@ function doNotificationBatch() { function getDbTime() { return pg - .queryP("select now_as_millis();", []) + .queryP_notification("select now_as_millis();", []) .then((rows: { now_as_millis: any }[]) => { return rows[0].now_as_millis; }); @@ -166,8 +166,19 @@ function doNotificationsForZid(zid: number, timeOfLastEvent: any) { let shouldTryAgain = false; return pg - .queryP( - "select * from participants where zid = ($1) and last_notified < ($2) and subscribed > 0;", + .queryP_notification( + `SELECT p.*, + GREATEST(p.last_interaction, activity.latest) AS last_interaction, + CASE WHEN activity.latest > p.last_interaction THEN 0 ELSE p.nsli END AS nsli + FROM participants p + CROSS JOIN LATERAL ( + SELECT GREATEST( + (SELECT MAX(v.created) FROM votes v WHERE v.zid=p.zid AND v.pid=p.pid), + (SELECT MAX(c.created) FROM comments c WHERE c.zid=p.zid AND c.uid=p.uid), + (SELECT MAX(m.created) FROM crowd_mod m WHERE m.zid=p.zid AND m.pid=p.pid) + ) AS latest + ) activity + WHERE p.zid = ($1) AND p.last_notified < ($2) AND p.subscribed > 0;`, [zid, timeOfLastEvent] ) .then((candidates: any[]) => { @@ -265,7 +276,7 @@ function doNotificationsForZid(zid: number, timeOfLastEvent: any) { const pids = _.pluck(needNotification, "pid"); return pg - .queryP( + .queryP_notification( "select uid, subscribe_email from participants_extended where uid in (select uid from participants where pid in (" + pids.join(",") + "));", @@ -289,9 +300,9 @@ function doNotificationsForZid(zid: number, timeOfLastEvent: any) { conversation_id, uidToEmail[uid] ).then(() => { - return pg.queryP( - "update participants set last_notified = now_as_millis(), nsli = nsli + 1 where uid = ($1) and zid = ($2);", - [uid, zid] + return pg.queryP_notification( + "update participants set last_notified = now_as_millis(), last_interaction = GREATEST(last_interaction, $3::bigint), nsli = CASE WHEN last_interaction > $3::bigint THEN nsli ELSE $4::integer + 1 END where uid = ($1) and zid = ($2);", + [uid, zid, pid_to_ptpt[item.pid].last_interaction, pid_to_ptpt[item.pid].nsli] ); }); } @@ -309,9 +320,9 @@ let notificationLoopStarted = false; function doNotificationLoop() { logger.debug("doNotificationLoop"); - doNotificationBatch().then(() => { - setTimeout(doNotificationLoop, 10000); - }); + doNotificationBatch() + .catch((error) => logger.warn("notification_batch_deferred", { error })) + .finally(() => setTimeout(doNotificationLoop, 10000)); } function sendNotificationEmail( diff --git a/server/src/routes/participation.ts b/server/src/routes/participation.ts index ed434d960..1ad4e2a48 100644 --- a/server/src/routes/participation.ts +++ b/server/src/routes/participation.ts @@ -14,6 +14,7 @@ import { ParticipantFields, ExpressResponse } from "../d"; import { sql_participants_extended } from "../db/sql"; import logger from "../utils/logger"; import pg from "../db/pg-query"; +import { participantVoteCountSql } from "../db/activity"; import { doFamousQuery, getOneConversation } from "../server-helpers"; // basic defaultdict implementation @@ -62,7 +63,7 @@ function _getParticipant(zid: number, uid?: number) { "_getParticipant", function (resolve: (arg0: any) => void, reject: (arg0: Error) => any) { pg.query_readOnly( - "SELECT * FROM participants WHERE zid = ($1) AND uid = ($2);", + `SELECT p.*, ${participantVoteCountSql("p")} AS vote_count FROM participants p WHERE zid = ($1) AND uid = ($2);`, [zid, uid], function (err: any, results: { rows: any[] }) { if (err) { @@ -87,7 +88,7 @@ function handle_GET_participants( const zid = req.p.zid; pg.queryP_readOnly( - "select * from participants where uid = ($1) and zid = ($2)", + `select p.*, ${participantVoteCountSql("p")} AS vote_count from participants p where uid = ($1) and zid = ($2)`, [uid, zid] ) .then(function (rows: string | any[]) { diff --git a/server/src/routes/votes.ts b/server/src/routes/votes.ts index 8cdd084d5..246c9e034 100644 --- a/server/src/routes/votes.ts +++ b/server/src/routes/votes.ts @@ -16,9 +16,7 @@ import { finishArray, finishOne, safeTimestampToMillis, - updateConversationModifiedTime, updateLastInteractionTimeForConversation, - updateVoteCount, } from "../server-helpers"; import Config from "../config"; import { SendMessageCommand } from "@aws-sdk/client-sqs"; @@ -234,12 +232,8 @@ async function handle_POST_votes(req: RequestWithP, res: any) { const voteRecord = voteResult.vote; const createdTimeMillis = safeTimestampToMillis(voteRecord.created); - // 2. Async updates (don't wait for them) - setTimeout(() => { - updateConversationModifiedTime(zid, createdTimeMillis); - updateLastInteractionTimeForConversation(zid, uid); - updateVoteCount(zid, pid); - }, 100); + // Notification state uses its own bounded lane; counts/activity are reads. + void updateLastInteractionTimeForConversation(zid, uid); // 3. Handle star if present if (!_.isUndefined(starred)) { diff --git a/server/src/routes/xids.ts b/server/src/routes/xids.ts index 00f340e83..f91b36bf2 100644 --- a/server/src/routes/xids.ts +++ b/server/src/routes/xids.ts @@ -47,13 +47,14 @@ async function getXidsPaginated( offset: number ): Promise { const sql = - "select p.pid, xids.xid, COALESCE(p.vote_count, 0) as vote_count from xids inner join " + + "with counts as (select pid, count(*)::integer as vote_count from votes where zid = ($1) group by pid) " + + "select p.pid, xids.xid, COALESCE(counts.vote_count, 0) as vote_count from xids inner join " + "(select * from participants where zid = ($1)) as p on xids.uid = p.uid " + - " where xids.owner in (select owner from conversations where zid = ($1))" + + " left join counts on counts.pid = p.pid where xids.owner in (select owner from conversations where zid = ($1))" + ` LIMIT ($2) OFFSET ($3)`; const params: number[] = [zid, limit, offset]; - const rows = await pg.queryP_readOnly(sql, params); + const rows = await pg.queryP_reportExport(sql, params); return Array.isArray(rows) ? rows : []; } diff --git a/server/src/server-helpers.ts b/server/src/server-helpers.ts index 428c35981..841211d62 100644 --- a/server/src/server-helpers.ts +++ b/server/src/server-helpers.ts @@ -18,6 +18,7 @@ import { UserInfo } from "./d"; import Config from "./config"; import logger from "./utils/logger"; import pg from "./db/pg-query"; +import { conversationModifiedSql } from "./db/activity"; import { storageToSemantic } from "./votes/convention"; // TODO consider "p2a24a2dadadu15" format @@ -439,17 +440,13 @@ function updateConversationModifiedTime(zid: number, t?: Date | number) { } function updateLastInteractionTimeForConversation(zid: number, uid?: number) { - return pg.queryP( + return pg.queryP_notification( "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", [zid, uid] - ); -} - -function updateVoteCount(zid: number, pid: number) { - return pg.queryP( - "update participants set vote_count = (select count(*) from votes where zid = ($1) and pid = ($2)) where zid = ($1) and pid = ($2)", - [zid, pid] - ); + ).catch((error) => { + // Best effort: a busy notification lane must never reject a committed vote. + logger.warn("notification_interaction_deferred", { error }); + }); } function addStar( @@ -677,7 +674,7 @@ function getOneConversation(zid: number, uid?: number, lang?: string) { return new Promise(function (resolve: any, _reject: any) { Promise.all([ pg.queryP_readOnly( - "select * from conversations left join (select uid, site_id from users) as u on conversations.owner = u.uid where conversations.zid = ($1);", + `select conversations.*, u.*, ${conversationModifiedSql("conversations")} as modified from conversations left join (select uid, site_id from users) as u on conversations.owner = u.uid where conversations.zid = ($1);`, [zid] ), getConversationHasMetadata(zid), @@ -735,6 +732,5 @@ export { sendEmailByUid, updateConversationModifiedTime, updateLastInteractionTimeForConversation, - updateVoteCount, userHasAnsweredZeQuestions, }; From fc0e10e032d8ddaccae97e940d6bd3f4b6fb9cb0 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Tue, 20 Oct 2026 21:23:01 -0700 Subject: [PATCH 14/30] cli: polis update replaces the binary from a verified release; --version makes no request (#3242) The updater resolves the newest release at the configured release location, verifies the asset's SHA-256, replaces the binary atomically and keeps a backup; every failure has its own exit code and leaves the installation untouched, and a sync failure after replacement reports an unknown outcome. --version prints the version and commit, plain or JSON, offline. Co-authored-by: Claude Fable 5.1 --- .github/workflows/polis-cli-release-build.yml | 43 +- polis-cli/Cargo.lock | 40 ++ polis-cli/crates/polis/Cargo.toml | 3 + polis-cli/crates/polis/src/commands.rs | 6 +- polis-cli/crates/polis/src/main.rs | 12 + polis-cli/crates/polis/src/update.rs | 486 ++++++++++++++++++ polis-cli/crates/polis/tests/update.rs | 401 +++++++++++++++ polis-cli/docs/releases.md | 97 +++- polis-cli/tests/differential/cases.py | 2 + scripts/build-polis-cli-release.py | 17 +- scripts/publish-polis-cli-release.py | 90 ++++ scripts/test-polis-cli.sh | 2 +- .../tests/test_polis_cli_release_publish.py | 64 +++ 13 files changed, 1241 insertions(+), 22 deletions(-) create mode 100644 polis-cli/crates/polis/src/update.rs create mode 100644 polis-cli/crates/polis/tests/update.rs create mode 100644 scripts/publish-polis-cli-release.py create mode 100644 scripts/tests/test_polis_cli_release_publish.py diff --git a/.github/workflows/polis-cli-release-build.yml b/.github/workflows/polis-cli-release-build.yml index 35a70e398..8453ef16a 100644 --- a/.github/workflows/polis-cli-release-build.yml +++ b/.github/workflows/polis-cli-release-build.yml @@ -1,12 +1,18 @@ -name: polis-cli release build (no publishing) +name: polis-cli release -# Select the reviewed ref when dispatching. Artifacts are review inputs only. +# Manual dispatch builds review artifacts; only an existing CLI tag publishes. on: workflow_dispatch: + push: + tags: ['cli-v*'] permissions: contents: read +concurrency: + group: polis-cli-release-${{ github.ref }} + cancel-in-progress: false + jobs: build: strategy: @@ -30,6 +36,11 @@ jobs: - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 with: python-version: '3.12' + - name: Verify release tag matches the workspace version + if: github.event_name == 'push' + env: + RELEASE_TAG: ${{ github.ref_name }} + run: python3 scripts/build-polis-cli-release.py --check-tag "$RELEASE_TAG" - name: Format, clippy and tests run: bash scripts/test-polis-cli.sh - name: Build, smoke-test and package native CLI @@ -40,3 +51,31 @@ jobs: path: ${{ runner.temp }}/polis-cli-release/* if-no-files-found: error retention-days: 14 + + publish: + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') + needs: build + runs-on: ubuntu-24.04 + timeout-minutes: 10 + permissions: + contents: write + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 + with: + python-version: '3.12' + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 + with: + pattern: polis-cli-*-${{ github.sha }} + path: ${{ runner.temp }}/polis-cli-release + merge-multiple: true + - name: Validate all targets and publish the existing tag + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ github.ref_name }} + RELEASE_COMMIT: ${{ github.sha }} + RELEASE_DIRECTORY: ${{ runner.temp }}/polis-cli-release + run: python3 scripts/publish-polis-cli-release.py --directory "$RELEASE_DIRECTORY" --tag "$RELEASE_TAG" --commit "$RELEASE_COMMIT" --repository "$GH_REPO" diff --git a/polis-cli/Cargo.lock b/polis-cli/Cargo.lock index 011c38b05..8a4c68e44 100644 --- a/polis-cli/Cargo.lock +++ b/polis-cli/Cargo.lock @@ -299,6 +299,16 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" +[[package]] +name = "filetime" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759" +dependencies = [ + "cfg-if", + "libc", +] + [[package]] name = "find-msvc-tools" version = "0.1.14" @@ -743,14 +753,17 @@ dependencies = [ "clap", "clap_complete", "csv", + "flate2", "keyring", "libc", "polis-client", "polis-contracts", "reqwest", + "semver", "serde", "serde_json", "sha2", + "tar", "tempfile", "url", "uuid", @@ -1047,6 +1060,12 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + [[package]] name = "serde" version = "1.0.229" @@ -1202,6 +1221,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tar" +version = "0.4.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "tempfile" version = "3.27.0" @@ -1599,6 +1629,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" +[[package]] +name = "xattr" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" +dependencies = [ + "libc", + "rustix", +] + [[package]] name = "yoke" version = "0.8.3" diff --git a/polis-cli/crates/polis/Cargo.toml b/polis-cli/crates/polis/Cargo.toml index e40fae24e..deda6baef 100644 --- a/polis-cli/crates/polis/Cargo.toml +++ b/polis-cli/crates/polis/Cargo.toml @@ -23,3 +23,6 @@ url = "2" sha2 = "0.10" base64 = "0.22" clap_complete = "4" +flate2 = "1" +tar = "0.4" +semver = "1" diff --git a/polis-cli/crates/polis/src/commands.rs b/polis-cli/crates/polis/src/commands.rs index a56331ab9..d6fd83f4c 100644 --- a/polis-cli/crates/polis/src/commands.rs +++ b/polis-cli/crates/polis/src/commands.rs @@ -46,7 +46,8 @@ pub fn available(path: &str) -> bool { crate::admin::available(path) || matches!( path, - "site list" + "update" + | "site list" | "site add" | "site use" | "site remove" @@ -512,6 +513,9 @@ report exports, stored Delphi results, and raw API.\nThe full product surface is "powershell", "elvish", ]))); + root = root.subcommand(Command::new("update").about("Install the latest stable CLI release, keeping polis.prev") + .arg(arg("release-base-url", "Release list URL; overrides POLIS_RELEASE_BASE_URL")) + .after_help("Explicit update only; never runs during other commands. Uses HTTPS release assets and SHA256 checksums, validates the platform and manifest, then atomically replaces the running executable. Keeps the previous executable as polis.prev. Requires a writable installation directory and a regular executable named polis. No sign-in or site configuration is read. Release source is independent of --site. See polis-cli/docs/releases.md for the release API, trust and rollback.")); root = root.subcommand(leaf("questions").after_help(crate::questions::text())); for name in ["browse", "tutorial"] { root = root.subcommand(leaf(name).arg(pos("target", false))); diff --git a/polis-cli/crates/polis/src/main.rs b/polis-cli/crates/polis/src/main.rs index 8ff6505cd..8cecbcc52 100644 --- a/polis-cli/crates/polis/src/main.rs +++ b/polis-cli/crates/polis/src/main.rs @@ -35,6 +35,7 @@ mod seeds; mod setup; mod sites; mod sizes; +mod update; mod voting; use clap::ArgMatches; use polis_client::Client; @@ -733,6 +734,17 @@ fn main() -> ExitCode { "CSV is available for read results only. Use --json, or the export command's --format and --output options." )), false); } + if path == "update" { + return render( + "unresolved", + update::execute( + leaf.get_one::("release-base-url") + .map(String::as_str), + *root.get_one::("timeout").unwrap(), + ), + json_mode, + ); + } profiles::noninteractive(root.get_flag("no-interactive")); // Help and schema never depend on credentials or profile files. if matches!( diff --git a/polis-cli/crates/polis/src/update.rs b/polis-cli/crates/polis/src/update.rs new file mode 100644 index 000000000..4d0bdb892 --- /dev/null +++ b/polis-cli/crates/polis/src/update.rs @@ -0,0 +1,486 @@ +//! Explicit executable updates. This module never reads site credentials. +use polis_contracts::{Error, Result}; +use reqwest::blocking::Client; +use semver::Version; +use serde::Deserialize; +use serde_json::{json, Value}; +use sha2::{Digest, Sha256}; +use std::{ + fs, + io::{Read, Write}, + path::Path, + time::Duration, +}; +use url::Url; + +pub const DEFAULT_RELEASE_BASE: &str = "https://api.github.com/repos/compdemocracy/polis/releases"; +const MAX_ARCHIVE: u64 = 200 * 1024 * 1024; +const MAX_BINARY: u64 = 300 * 1024 * 1024; + +fn fail(message: &str) -> Error { + Error::new("update_failed", message, "The installed executable is unchanged unless stated otherwise. Check the release source and install directory, then run polis update explicitly again.", 1) +} +fn valid_url(raw: &str) -> Result { + let url = Url::parse(raw).map_err(|_| Error::input("Invalid release URL."))?; + let local = matches!(url.host_str(), Some("127.0.0.1" | "[::1]" | "localhost")); + if !(url.scheme() == "https" || (url.scheme() == "http" && local)) + || !url.username().is_empty() + || url.password().is_some() + || url.fragment().is_some() + { + return Err(Error::input("Release URLs require HTTPS (HTTP is allowed only on loopback), no credentials, and no fragment.")); + } + Ok(url) +} +fn get(client: &Client, url: Url, limit: u64) -> Result> { + let response = client + .get(url) + .send() + .map_err(|_| fail("Cannot download release data."))?; + if !response.status().is_success() { + return Err(fail("Release server returned an unsuccessful status.")); + } + let mut bytes = Vec::new(); + response + .take(limit + 1) + .read_to_end(&mut bytes) + .map_err(|_| fail("Cannot read release data."))?; + if bytes.len() as u64 > limit { + return Err(fail("Release data exceeds its size limit.")); + } + Ok(bytes) +} +#[derive(Deserialize)] +struct Asset { + name: String, + browser_download_url: String, +} +#[derive(Deserialize)] +struct Release { + tag_name: String, + draft: bool, + prerelease: bool, + #[serde(default)] + body: Option, + assets: Vec, +} +#[derive(Deserialize)] +struct Manifest { + schema: String, + version: String, + commit: String, + target: String, + source: String, + binary_sha256: String, +} +fn target() -> Result<&'static str> { + match (std::env::consts::OS, std::env::consts::ARCH) { + ("macos", "aarch64") => Ok("aarch64-apple-darwin"), + ("macos", "x86_64") => Ok("x86_64-apple-darwin"), + ("linux", "x86_64") => Ok("x86_64-unknown-linux-gnu"), + ("linux", "aarch64") => Ok("aarch64-unknown-linux-gnu"), + _ => Err(fail("No release target for this operating system and CPU.")), + } +} +fn latest(client: &Client, base: Url) -> Result<(Version, Release)> { + let mut chosen: Option<(Version, Release)> = None; + for page in 1..=10 { + let mut url = base.clone(); + url.query_pairs_mut() + .append_pair("per_page", "100") + .append_pair("page", &page.to_string()); + let releases: Vec = serde_json::from_slice(&get(client, url, 8 * 1024 * 1024)?) + .map_err(|_| fail("Invalid release list."))?; + let last = releases.len() < 100; + for release in releases { + if release.draft || release.prerelease { + continue; + } + let Some(version) = release + .tag_name + .strip_prefix("cli-v") + .and_then(|s| Version::parse(s).ok()) + else { + continue; + }; + if !version.pre.is_empty() || !version.build.is_empty() { + continue; + } + if chosen.as_ref().is_none_or(|(v, _)| version > *v) { + chosen = Some((version, release)); + } + } + if last { + return chosen.ok_or_else(|| fail("No published stable CLI release was found.")); + } + } + Err(fail( + "Release list exceeds ten pages; cannot determine the latest CLI release.", + )) +} +fn digest(bytes: &[u8]) -> String { + format!("{:x}", Sha256::digest(bytes)) +} +fn unpack( + bytes: &[u8], + name: &str, + version: &Version, + platform: &str, +) -> Result<(Vec, Manifest)> { + let root = name + .strip_suffix(".tar.gz") + .ok_or_else(|| fail("Invalid archive name."))?; + let decoder = flate2::read::GzDecoder::new(bytes); + let mut archive = tar::Archive::new(decoder.take(MAX_BINARY + 1024 * 1024)); + let mut binary = None; + let mut manifest = None; + let mut seen = std::collections::BTreeSet::new(); + for entry in archive + .entries() + .map_err(|_| fail("Invalid release archive."))? + { + let mut entry = entry.map_err(|_| fail("Invalid archive member."))?; + let path = entry.path().map_err(|_| fail("Invalid archive path."))?; + let path = path.to_str().ok_or_else(|| fail("Invalid archive path."))?; + let part = path + .strip_prefix(&format!("{root}/")) + .ok_or_else(|| fail("Unexpected archive directory."))? + .to_owned(); + if !matches!( + part.as_str(), + "polis" | "manifest.json" | "LICENSE" | "README.txt" + ) || !entry.header().entry_type().is_file() + || !seen.insert(part.clone()) + { + return Err(fail("Unexpected, linked, or duplicate archive member.")); + } + let limit = if part == "polis" { + MAX_BINARY + } else { + 64 * 1024 + }; + if entry.size() > limit { + return Err(fail("Archive member exceeds its size limit.")); + } + let mut data = Vec::new(); + entry + .read_to_end(&mut data) + .map_err(|_| fail("Cannot read archive member."))?; + match part.as_str() { + "polis" => binary = Some(data), + "manifest.json" => { + manifest = Some( + serde_json::from_slice::(&data) + .map_err(|_| fail("Invalid release manifest."))?, + ) + } + _ => (), + } + } + if seen.len() != 4 { + return Err(fail("Incomplete release archive.")); + } + let binary = binary.ok_or_else(|| fail("Release archive lacks polis."))?; + let manifest = manifest.ok_or_else(|| fail("Release archive lacks a manifest."))?; + if manifest.schema != "polis-cli-release/1" + || manifest.version != version.to_string() + || manifest.target != platform + || manifest.source != "clean-checkout" + || manifest.commit.len() != 40 + || !manifest + .commit + .bytes() + .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) + || manifest.binary_sha256 != digest(&binary) + || binary.is_empty() + || root != format!("polis-{version}-{}-{platform}", &manifest.commit[..12]) + { + return Err(fail( + "Release manifest, target, source, or binary checksum does not match.", + )); + } + Ok((binary, manifest)) +} +#[cfg(unix)] +fn install(executable: &Path, binary: &[u8], expected: &str) -> Result<()> { + install_with_directory_sync(executable, binary, expected, fs::File::sync_all) +} +#[cfg(unix)] +fn install_with_directory_sync( + executable: &Path, + binary: &[u8], + expected: &str, + mut sync_directory: impl FnMut(&fs::File) -> std::io::Result<()>, +) -> Result<()> { + use std::os::fd::AsRawFd; + use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; + let parent = executable + .parent() + .ok_or_else(|| fail("Cannot locate installation directory."))?; + let lock = fs::OpenOptions::new() + .read(true) + .write(true) + .create(true) + .truncate(false) + .mode(0o600) + .custom_flags(libc::O_NOFOLLOW) + .open(parent.join(".polis-update.lock")) + .map_err(|_| fail("Cannot open the update lock in the installation directory."))?; + // Keep the lock inode: deleting it allows another updater to lock a different inode. + if unsafe { libc::flock(lock.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) } != 0 { + return Err(fail("Another update is in progress.")); + } + let meta = fs::symlink_metadata(executable) + .map_err(|_| fail("Cannot inspect installed executable."))?; + if !meta.is_file() || executable.file_name().is_none_or(|name| name != "polis") { + return Err(fail( + "Install the executable as a regular file named polis before updating.", + )); + } + if digest(&fs::read(executable).map_err(|_| fail("Cannot recheck installed executable."))?) + != expected + { + return Err(fail( + "The installed executable changed while downloading; run the installed version again.", + )); + } + let mut staged = tempfile::NamedTempFile::new_in(parent) + .map_err(|_| fail("Installation directory is not writable."))?; + staged + .write_all(binary) + .map_err(|_| fail("Cannot stage the new executable."))?; + staged + .as_file() + .set_permissions(fs::Permissions::from_mode(0o755)) + .map_err(|_| fail("Cannot set executable permissions."))?; + staged + .as_file() + .sync_all() + .map_err(|_| fail("Cannot sync the new executable."))?; + let mut backup = tempfile::NamedTempFile::new_in(parent) + .map_err(|_| fail("Cannot stage the previous executable."))?; + let mut original = + fs::File::open(executable).map_err(|_| fail("Cannot read installed executable."))?; + std::io::copy(&mut original, &mut backup) + .map_err(|_| fail("Cannot preserve the previous executable."))?; + backup + .as_file() + .set_permissions(fs::Permissions::from_mode( + meta.permissions().mode() & 0o777, + )) + .map_err(|_| fail("Cannot set backup permissions."))?; + backup + .as_file() + .sync_all() + .map_err(|_| fail("Cannot sync the previous executable."))?; + backup + .persist(parent.join("polis.prev")) + .map_err(|_| fail("Cannot save polis.prev."))?; + let directory = + fs::File::open(parent).map_err(|_| fail("Cannot open installation directory."))?; + sync_directory(&directory).map_err(|_| fail("Cannot sync polis.prev."))?; + staged + .persist(executable) + .map_err(|_| fail("Cannot atomically replace polis; polis.prev has been saved."))?; + sync_directory(&directory).map_err(|_| { + let mut error = Error::new( + "update_sync_failed", + "The executable was replaced and polis.prev saved, but syncing the directory failed.", + "Inspect polis --version before retrying; installation durability is uncertain.", + 7, + ); + error.outcome = "unknown"; + error + })?; + Ok(()) +} +#[cfg(not(unix))] +fn install(_: &Path, _: &[u8], _: &str) -> Result<()> { + Err(fail("This platform does not support CLI updates.")) +} + +pub fn execute(base: Option<&str>, timeout: u64) -> Result { + let platform = target()?; + let configured = base + .map(str::to_owned) + .or_else(|| std::env::var("POLIS_RELEASE_BASE_URL").ok()) + .unwrap_or_else(|| DEFAULT_RELEASE_BASE.to_owned()); + let base = valid_url(&configured)?; + if base.query().is_some() { + return Err(Error::input( + "Release base URL must not have query parameters.", + )); + } + let client = Client::builder() + .timeout(Duration::from_secs(timeout)) + .user_agent("polis-cli-updater") + .redirect(reqwest::redirect::Policy::custom(|attempt| { + if attempt.previous().len() >= 5 + || valid_url(attempt.url().as_str()).is_err() + || (attempt.previous().iter().any(|u| u.scheme() == "https") + && attempt.url().scheme() != "https") + { + attempt.error("Invalid release redirect") + } else { + attempt.follow() + } + })) + .build() + .map_err(|_| fail("Cannot create release client."))?; + let executable = + std::env::current_exe().map_err(|_| fail("Cannot locate running executable."))?; + let installed_digest = + digest(&fs::read(&executable).map_err(|_| fail("Cannot read installed executable."))?); + let (version, release) = latest(&client, base)?; + let current = Version::parse(env!("CARGO_PKG_VERSION")) + .map_err(|_| fail("Invalid installed version."))?; + if version <= current { + return Ok( + json!({"state":"up_to_date", "version":current.to_string(), "commit":env!("POLIS_BUILD_COMMIT"), "latest":version.to_string(), "message":"No newer stable CLI release is available."}), + ); + } + let suffix = format!("-{platform}.tar.gz"); + let candidates: Vec<_> = release + .assets + .iter() + .filter(|a| a.name.starts_with(&format!("polis-{version}-")) && a.name.ends_with(&suffix)) + .collect(); + if candidates.len() != 1 { + return Err(fail( + "The latest CLI release does not contain exactly one archive for this platform.", + )); + } + let asset = candidates[0]; + if !asset + .name + .bytes() + .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'.' | b'_')) + { + return Err(fail("Invalid release asset name.")); + } + let checksums: Vec<_> = release + .assets + .iter() + .filter(|a| a.name == format!("{}.sha256", asset.name)) + .collect(); + if checksums.len() != 1 { + return Err(fail( + "The release must contain one checksum for this archive.", + )); + } + let checksum = get( + &client, + valid_url(&checksums[0].browser_download_url)?, + 1024, + )?; + let bytes = get( + &client, + valid_url(&asset.browser_download_url)?, + MAX_ARCHIVE, + )?; + let expected = format!("{} {}\n", digest(&bytes), asset.name); + if checksum != expected.as_bytes() { + return Err(fail("Release archive checksum mismatch.")); + } + let (binary, manifest) = unpack(&bytes, &asset.name, &version, platform)?; + install(&executable, &binary, &installed_digest)?; + Ok( + json!({"state":"updated", "from":{"version":current.to_string(),"commit":env!("POLIS_BUILD_COMMIT")}, "to":{"version":version.to_string(),"commit":manifest.commit}, "target":platform, "backup":"polis.prev", "changes":release.body.unwrap_or_default(), "message":"Updated polis; the previous executable is saved as polis.prev."}), + ) +} + +#[cfg(all(test, unix))] +mod tests { + use super::*; + use std::os::fd::AsRawFd; + + #[test] + fn directory_sync_failure_after_replacement_reports_unknown() { + let directory = tempfile::tempdir().unwrap(); + let executable = directory.path().join("polis"); + fs::write(&executable, b"original executable").unwrap(); + fs::write(directory.path().join("polis.prev"), b"older backup").unwrap(); + let mut syncs = 0; + let error = install_with_directory_sync( + &executable, + b"new executable", + &digest(b"original executable"), + |directory| { + syncs += 1; + if syncs == 2 { + Err(std::io::Error::from_raw_os_error(libc::EIO)) + } else { + directory.sync_all() + } + }, + ) + .unwrap_err(); + assert_eq!(syncs, 2); + assert_eq!(error.exit, 7); + let response = polis_contracts::envelope("unresolved", &Err(error)); + assert_eq!(response["ok"], false); + assert_eq!(response["error"]["code"], "update_sync_failed"); + assert_eq!(response["error"]["outcome"], "unknown"); + assert_eq!( + response["error"]["message"], + "The executable was replaced and polis.prev saved, but syncing the directory failed." + ); + assert_eq!( + response["error"]["action"], + "Inspect polis --version before retrying; installation durability is uncertain." + ); + assert_eq!(fs::read(&executable).unwrap(), b"new executable"); + assert_eq!( + fs::read(directory.path().join("polis.prev")).unwrap(), + b"original executable" + ); + assert_eq!(fs::read_dir(directory.path()).unwrap().count(), 3); + } + + #[test] + fn changed_executable_during_download_is_not_replaced() { + let directory = tempfile::tempdir().unwrap(); + let executable = directory.path().join("polis"); + fs::write(&executable, b"another installed version").unwrap(); + fs::write(directory.path().join("polis.prev"), b"prior backup").unwrap(); + assert!(install(&executable, b"download", &digest(b"original version")).is_err()); + assert_eq!(fs::read(&executable).unwrap(), b"another installed version"); + assert_eq!( + fs::read(directory.path().join("polis.prev")).unwrap(), + b"prior backup" + ); + } + + #[test] + fn live_lock_refuses_replacement_and_released_lock_allows_it() { + let directory = tempfile::tempdir().unwrap(); + let executable = directory.path().join("polis"); + fs::write(&executable, b"original").unwrap(); + let lock = fs::File::create(directory.path().join(".polis-update.lock")).unwrap(); + assert_eq!( + unsafe { libc::flock(lock.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) }, + 0 + ); + assert!(install(&executable, b"download", &digest(b"original")).is_err()); + assert_eq!(fs::read(&executable).unwrap(), b"original"); + assert!(!directory.path().join("polis.prev").exists()); + drop(lock); + install(&executable, b"download", &digest(b"original")).unwrap(); + assert_eq!(fs::read(&executable).unwrap(), b"download"); + assert_eq!( + fs::read(directory.path().join("polis.prev")).unwrap(), + b"original" + ); + } + + #[test] + fn backup_failure_preserves_executable_and_cleans_staging() { + let directory = tempfile::tempdir().unwrap(); + let executable = directory.path().join("polis"); + fs::write(&executable, b"original").unwrap(); + fs::create_dir(directory.path().join("polis.prev")).unwrap(); + assert!(install(&executable, b"download", &digest(b"original")).is_err()); + assert_eq!(fs::read(&executable).unwrap(), b"original"); + assert_eq!(fs::read_dir(directory.path()).unwrap().count(), 3); + } +} diff --git a/polis-cli/crates/polis/tests/update.rs b/polis-cli/crates/polis/tests/update.rs new file mode 100644 index 000000000..60b9806a3 --- /dev/null +++ b/polis-cli/crates/polis/tests/update.rs @@ -0,0 +1,401 @@ +use flate2::{write::GzEncoder, Compression}; +use serde_json::{json, Value}; +use sha2::{Digest, Sha256}; +use std::{ + collections::HashMap, + fs, + io::{Read, Write}, + net::TcpListener, + process::Command, + sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, + }, + thread, + time::Duration, +}; + +fn target() -> &'static str { + match (std::env::consts::OS, std::env::consts::ARCH) { + ("macos", "aarch64") => "aarch64-apple-darwin", + ("macos", "x86_64") => "x86_64-apple-darwin", + ("linux", "aarch64") => "aarch64-unknown-linux-gnu", + ("linux", "x86_64") => "x86_64-unknown-linux-gnu", + _ => panic!("unsupported test platform"), + } +} +fn digest(b: &[u8]) -> String { + format!("{:x}", Sha256::digest(b)) +} +struct Server { + base: String, + stop: Arc, + requests: Arc, + handle: Option>, +} +impl Drop for Server { + fn drop(&mut self) { + self.stop.store(true, Ordering::SeqCst); + self.handle.take().unwrap().join().unwrap(); + } +} +fn server(mode: &str) -> (Server, Vec) { + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let origin = format!("http://{}", listener.local_addr().unwrap()); + listener.set_nonblocking(true).unwrap(); + let version = if mode == "old" { + env!("CARGO_PKG_VERSION") + } else { + "999.0.0" + }; + let commit = "a".repeat(40); + let root = format!("polis-{version}-{}-{}", &commit[..12], target()); + let name = format!("{root}.tar.gz"); + // This executable must never be run during verification or installation. + let binary = b"#!/bin/sh\nprintf 'replacement ran unexpectedly' >&2\nexit 99\n".to_vec(); + let manifest = json!({"schema":"polis-cli-release/1","version":version,"commit":commit,"target":if mode=="wrong_target" {"wrong"}else{target()},"source":if mode=="unverified" {"unverified-archive"}else{"clean-checkout"},"binary_sha256":if mode=="binary_hash" {"0".repeat(64)}else{digest(&binary)}}); + let mut tar = tar::Builder::new(GzEncoder::new(Vec::new(), Compression::default())); + let members = [ + ("polis", binary.clone()), + ("manifest.json", serde_json::to_vec(&manifest).unwrap()), + ("LICENSE", b"fixture license".to_vec()), + ("README.txt", b"fixture readme".to_vec()), + ]; + for (part, bytes) in &members { + let mut header = tar::Header::new_gnu(); + header.set_size(bytes.len() as u64); + header.set_mode(0o755); + header.set_cksum(); + tar.append_data(&mut header, format!("{root}/{part}"), &bytes[..]) + .unwrap(); + } + if mode == "duplicate" { + let mut header = tar::Header::new_gnu(); + header.set_size(1); + header.set_mode(0o755); + header.set_cksum(); + tar.append_data(&mut header, format!("{root}/polis"), &b"x"[..]) + .unwrap(); + } + if mode == "symlink" { + let mut header = tar::Header::new_gnu(); + header.set_entry_type(tar::EntryType::Symlink); + header.set_size(0); + header.set_mode(0o755); + header.set_link_name("/tmp/outside").unwrap(); + header.set_cksum(); + tar.append_data(&mut header, format!("{root}/linked"), &b""[..]) + .unwrap(); + } + let archive = tar.into_inner().unwrap().finish().unwrap(); + let checksum = format!( + "{} {name}\n", + if mode == "mismatch" { + "0".repeat(64) + } else { + digest(&archive) + } + ); + let assets = if mode == "missing" { + json!([]) + } else { + json!([ + {"name":name,"browser_download_url":format!("{origin}/archive")}, + {"name":format!("{name}.sha256"),"browser_download_url":format!("{origin}/checksum")} + ]) + }; + let releases = json!([ + {"tag_name":"server-v9999.0.0","draft":false,"prerelease":false,"assets":[]}, + {"tag_name":"cli-v9999.0.0","draft":true,"prerelease":false,"assets":[]}, + {"tag_name":"cli-v9998.0.0","draft":false,"prerelease":true,"assets":[]}, + {"tag_name":format!("cli-v{version}"),"draft":false,"prerelease":false,"body":"New commands.\u{1b}[31m","assets":assets} + ]); + let releases = if mode == "empty" { json!([]) } else { releases }; + let not_found = mode == "not_found"; + let offline = mode == "offline"; + let routes = HashMap::from([ + ("/releases", serde_json::to_vec(&releases).unwrap()), + ("/archive", archive), + ("/checksum", checksum.into_bytes()), + ]); + let stop = Arc::new(AtomicBool::new(false)); + let done = stop.clone(); + let requests = Arc::new(AtomicUsize::new(0)); + let observed = requests.clone(); + let handle = thread::spawn(move || { + while !done.load(Ordering::SeqCst) { + match listener.accept() { + Ok((mut stream, _)) => { + stream.set_nonblocking(false).unwrap(); + stream + .set_read_timeout(Some(Duration::from_secs(5))) + .unwrap(); + stream + .set_write_timeout(Some(Duration::from_secs(5))) + .unwrap(); + let mut request = Vec::new(); + let mut b = [0; 1]; + while !request.ends_with(b"\r\n\r\n") { + assert!(request.len() < 16384); + if stream.read(&mut b).unwrap() == 0 { + break; + } + request.push(b[0]); + } + observed.fetch_add(1, Ordering::SeqCst); + // An unavailable distributor closes without an HTTP response. + if offline { + continue; + } + let request = String::from_utf8(request).unwrap(); + assert!(!request.to_lowercase().contains("authorization:")); + let path = request + .split_whitespace() + .nth(1) + .unwrap() + .split('?') + .next() + .unwrap(); + let body = routes + .get(path) + .unwrap_or_else(|| panic!("unexpected path {path}")); + write!( + stream, + "HTTP/1.1 {}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n", + if not_found { "404 Not Found" } else { "200 OK" }, + body.len() + ) + .unwrap(); + stream.write_all(body).unwrap(); + } + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { + thread::sleep(Duration::from_millis(2)) + } + Err(e) => panic!("{e}"), + } + } + }); + ( + Server { + base: format!("{origin}/releases"), + stop, + requests, + handle: Some(handle), + }, + binary, + ) +} +fn run(mode: &str, json_mode: bool, env_source: bool) { + let (server, binary) = server(mode); + let dir = tempfile::tempdir().unwrap(); + let exe = dir.path().join("polis"); + fs::copy(env!("CARGO_BIN_EXE_polis"), &exe).unwrap(); + let original = fs::read(&exe).unwrap(); + let config = dir.path().join("config"); + fs::create_dir(&config).unwrap(); + fs::write( + config.join("profiles.json"), + b"invalid config; must not be read", + ) + .unwrap(); + fs::write(dir.path().join("polis.prev"), b"older backup").unwrap(); + let mut cmd = Command::new(&exe); + cmd.args(["update", "--timeout", "5"]) + .env("POLIS_CONFIG_DIR", &config) + .env("POLIS_KEYCHAIN", "off") + .env("POLIS_TOKEN", "unused-fixture-token"); + if env_source { + cmd.env("POLIS_RELEASE_BASE_URL", &server.base); + } else { + cmd.args(["--release-base-url", &server.base]) + .env("POLIS_RELEASE_BASE_URL", "invalid"); + } + if json_mode { + cmd.arg("--json"); + } + #[cfg(unix)] + let original_permissions = { + use std::os::unix::fs::PermissionsExt; + let permissions = fs::metadata(dir.path()).unwrap().permissions(); + if mode.starts_with("denied_") { + assert_ne!( + unsafe { libc::geteuid() }, + 0, + "permission tests require a non-root user" + ); + if mode == "denied_staging" { + fs::write(dir.path().join(".polis-update.lock"), b"").unwrap(); + } + fs::set_permissions(dir.path(), fs::Permissions::from_mode(0o555)).unwrap(); + } + permissions + }; + let output = cmd.output(); + #[cfg(unix)] + fs::set_permissions(dir.path(), original_permissions).unwrap(); + let out = output.unwrap(); + let stdout = String::from_utf8(out.stdout).unwrap(); + let stderr = String::from_utf8(out.stderr).unwrap(); + let success = matches!(mode, "match" | "old"); + assert_eq!(out.status.success(), success, "{stdout}\n{stderr}"); + assert!(!stdout.contains('\u{1b}')); + assert!(!stdout.contains("unused-fixture-token")); + if json_mode { + let data: Value = serde_json::from_str(&stdout).unwrap(); + assert_eq!(data["ok"], success); + let expected_message = match mode { + "offline" => Some("Cannot download release data."), + "not_found" => Some("Release server returned an unsuccessful status."), + "empty" => Some("No published stable CLI release was found."), + "denied_lock" => Some("Cannot open the update lock in the installation directory."), + "denied_staging" => Some("Installation directory is not writable."), + _ => None, + }; + if let Some(message) = expected_message { + assert_eq!(out.status.code(), Some(1)); + assert_eq!(data["error"]["code"], "update_failed"); + assert_eq!(data["error"]["message"], message); + assert_eq!(data["error"]["outcome"], "not_sent"); + assert!(stderr.is_empty()); + } + if mode == "match" { + assert_eq!(data["data"]["to"]["version"], "999.0.0"); + assert_eq!(data["data"]["to"]["commit"], "a".repeat(40)); + assert_eq!(data["data"]["changes"], "New commands.\u{1b}[31m"); + } + if mode == "old" { + assert_eq!(data["data"]["state"], "up_to_date"); + } + } + if mode == "match" { + assert_eq!(fs::read(&exe).unwrap(), binary); + assert_eq!(fs::read(dir.path().join("polis.prev")).unwrap(), original); + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + assert_eq!( + fs::metadata(&exe).unwrap().permissions().mode() & 0o777, + 0o755 + ); + } + } else { + assert_eq!(fs::read(&exe).unwrap(), original); + assert_eq!( + fs::read(dir.path().join("polis.prev")).unwrap(), + b"older backup" + ); + } + assert_eq!( + fs::read(config.join("profiles.json")).unwrap(), + b"invalid config; must not be read" + ); +} +#[test] +fn checksum_match_atomically_installs_and_keeps_previous() { + run("match", true, false); +} +#[test] +fn checksum_mismatch_keeps_installed_binary_and_backup() { + run("mismatch", true, false); +} +#[test] +fn no_newer_version_does_not_replace() { + run("old", true, false); +} +#[test] +fn platform_missing_does_not_replace() { + run("missing", true, false); +} +#[test] +fn environment_source_and_human_output() { + run("match", false, true); +} +#[test] +fn manifest_and_archive_rejections_preserve_installation() { + for mode in [ + "wrong_target", + "unverified", + "binary_hash", + "duplicate", + "symlink", + ] { + run(mode, true, false); + } +} +#[test] +fn invalid_release_url_fails_before_network_or_credentials() { + for url in [ + "http://example.com/releases", + "https://user:password@example.com/releases", + "file:///tmp/release", + "https://example.com/releases?token=secret", + ] { + let out = Command::new(env!("CARGO_BIN_EXE_polis")) + .args(["update", "--release-base-url", url, "--json"]) + .env("POLIS_KEYCHAIN", "off") + .output() + .unwrap(); + assert!(!out.status.success()); + let text = String::from_utf8(out.stdout).unwrap(); + assert!(!text.contains("password")); + assert!(!text.contains("token=secret")); + } +} + +#[test] +fn offline_distributor_preserves_installation() { + run("offline", true, false); +} +#[test] +fn missing_release_preserves_installation() { + run("not_found", true, false); + run("empty", true, false); +} +#[cfg(unix)] +#[test] +fn permission_denied_install_directory_preserves_installation() { + run("denied_lock", true, false); + run("denied_staging", true, false); +} +#[test] +fn version_plain_and_json_make_no_release_or_proxy_requests() { + let (server, _) = server("match"); + let dir = tempfile::tempdir().unwrap(); + let profile = dir.path().join("profiles.json"); + fs::write(&profile, b"invalid profile; must not be read").unwrap(); + for args in [vec!["--version"], vec!["--version", "--json"]] { + let out = Command::new(env!("CARGO_BIN_EXE_polis")) + .args(&args) + .env("POLIS_CONFIG_DIR", dir.path()) + .env("POLIS_KEYCHAIN", "off") + .env("POLIS_SITE", "unconfigured-site") + .env("POLIS_RELEASE_BASE_URL", &server.base) + .env("HTTP_PROXY", &server.base) + .env("HTTPS_PROXY", &server.base) + .env("ALL_PROXY", &server.base) + .env("NO_PROXY", "") + .output() + .unwrap(); + assert_eq!(out.status.code(), Some(0)); + assert!(out.stderr.is_empty()); + let stdout = String::from_utf8(out.stdout).unwrap(); + let expected = format!( + "polis {} (commit {}; {})", + env!("CARGO_PKG_VERSION"), + env!("POLIS_BUILD_COMMIT"), + env!("POLIS_BUILD_SOURCE") + ); + if args.contains(&"--json") { + let data: Value = serde_json::from_str(&stdout).unwrap(); + assert_eq!(data["ok"], true); + assert_eq!(data["data"]["help"].as_str().unwrap().trim(), expected); + } else { + assert_eq!(stdout.trim(), expected); + } + assert_eq!(server.requests.load(Ordering::SeqCst), 0); + assert_eq!( + fs::read(&profile).unwrap(), + b"invalid profile; must not be read" + ); + } +} diff --git a/polis-cli/docs/releases.md b/polis-cli/docs/releases.md index 3e99de1dd..798f9f5e3 100644 --- a/polis-cli/docs/releases.md +++ b/polis-cli/docs/releases.md @@ -25,8 +25,9 @@ toolchain, `cargo build --locked --release`, and the actual Cargo target directo It builds the production binary without fixture features, checks version/help, and refuses modified or untracked build inputs. It never publishes or installs. -The manual **polis-cli release build (no publishing)** workflow uses these same -commands on native macOS and Linux runners. Its artifacts expire after 14 days; +The **polis-cli release** workflow uses these same commands on native macOS +and Linux runners. Manual dispatch builds review artifacts only. A pushed +`cli-vMAJOR.MINOR.PATCH` tag builds and publishes after all four jobs pass. Its artifacts expire after 14 days; they are review inputs, not permanent release URLs. All target jobs must pass before a distributor claims that version supports all four targets. A passing ARM64 Mac build alone does not qualify Intel or Linux. GNU/Linux binaries use @@ -51,7 +52,7 @@ that output as a clean release. For ordinary development, use Cargo directly. ## Install or replace an explicitly selected artifact Download the archive for your OS and CPU and its expected checksum from your -trusted distributor. There is no automatic installer or download in this CLI. +trusted distributor. For a first installation, select and verify an archive explicitly. A checksum verifies bytes against that expected digest; it does not authenticate the distributor on its own. In the download directory: @@ -71,9 +72,9 @@ unpacked artifact directory, install into a directory you own on PATH: mkdir -p "$HOME/.local/bin" # If replacing an existing binary, first save it under a new backup filename. # Stop if that backup filename already exists. -test ! -e "$HOME/.local/bin/polis.previous" || exit 1 +test ! -e "$HOME/.local/bin/polis.prev" || exit 1 if test -e "$HOME/.local/bin/polis"; then - cp -p "$HOME/.local/bin/polis" "$HOME/.local/bin/polis.previous" + cp -p "$HOME/.local/bin/polis" "$HOME/.local/bin/polis.prev" fi install -m 755 ./polis "$HOME/.local/bin/polis.new" "$HOME/.local/bin/polis.new" --version @@ -88,16 +89,80 @@ backup until the replacement works. To roll back, explicitly restore that saved binary and verify its version. No sudo, credential transfer or server mutation is required. -Updating repeats the same pinned-artifact procedure. The CLI does not check for -updates during sign-in, reads, votes or comments. An explicit update-check command -can be added later; no update network request or automatic replacement exists. +## Update the installed CLI -## Publication remains separate +```sh +polis --version +polis update +polis update --json +# Use a distributor's compatible release API instead of the default: +polis update --release-base-url https://releases.example.org/cli/releases +``` + +`polis update` is explicit; no update requests run during sign-in, reads, votes, +comments, or any other command. It does not load profiles or credentials, and +`--site` does not select the software distributor. The release source is the +`--release-base-url` flag, then `POLIS_RELEASE_BASE_URL`, then +`https://api.github.com/repos/compdemocracy/polis/releases`. The URL is a GitHub +release-list compatible endpoint: an array of objects with `tag_name`, `draft`, +`prerelease`, optional `body`, and `assets` containing `name` and +`browser_download_url`. It receives `per_page=100&page=N`; a page shorter than +100 ends the list. More than ten full pages fails instead of guessing. + +The updater chooses the highest stable semantic version with a `cli-v` tag; +it ignores draft, prerelease, and non-CLI releases. Equal or older versions do +nothing, even if their commit differs. A version bump is required for an update. +The newest release must contain the running platform's archive and its checksum; +a missing platform fails, without silently selecting an older release. + +Downloads require HTTPS, except loopback HTTP for local testing. Credentials in +URLs are refused; no site token is sent. Up to five redirects are allowed, with +no HTTPS downgrade. Requests each obey `--timeout`; responses and archive members +have size limits. Archive SHA256, manifest version/commit/target/source, binary +SHA256, and the four expected regular archive members are checked before any +replacement. Downloads are never executed as a verification step. Checksums +verify integrity against the selected distributor; they do not independently +authenticate that distributor. Choose the release base URL accordingly. + +The running executable must resolve to a regular file named `polis` in a writable +directory. A launcher symlink resolves to that executable; other installations on +PATH are unaffected. The updater stages in the same directory, syncs both files, +saves the installed binary as `polis.prev`, then uses an atomic rename to replace +`polis`. An existing `polis.prev` is replaced by the immediately previous binary. +An installation lock serializes replacement; its empty `.polis-update.lock` file +is retained so overlapping processes always lock the same inode. A changed +installed binary during download causes a refusal. The old executable remains +available until rename; interruptions before that leave it in place. A directory +sync failure after rename is reported as an uncertain outcome (exit 7). + +Success reports the old and new version/commit, platform, backup name and release +notes. `--json` uses the normal CLI envelope, with `data.state` equal to `updated` +or `up_to_date`; terminal control characters in release notes are escaped. +Configuration and sign-ins are untouched. Verify with `polis --version` after +updating. To roll back from the installation directory, keep the backup and +atomically restore a copy: + +```sh +cp -p polis.prev polis.rollback +mv -f polis.rollback polis +./polis --version +``` -The semantic version lives in `polis-cli/Cargo.toml`. A distributor first reviews -and increments it with its lockfile, qualifies native targets, and records the -chosen full commit under a CLI-specific release tag such as `cli-v0.1.0`. -Only then publish the exact reviewed archives and checksums to permanent release -storage, with the appropriate signing/attestation policy. This build workflow has -read-only repository permissions and no release creation, tag writes or package -publishing steps. +## Publish from a reviewed tag + +The semantic version lives in `polis-cli/Cargo.toml`; increment it and refresh +`Cargo.lock` in the reviewed change. A `cli-vMAJOR.MINOR.PATCH` tag must match that +exact version. Pushing the tag starts the existing four-target native matrix. +The publish job alone has `contents: write`; builds retain read-only permission. +It downloads the current run's assets and validates exactly four archives and +four checksums, all with clean source status and the tagged full commit. + +The job creates a draft release for the existing tag (`--verify-tag`), uploads +the complete set, then publishes with generated release notes. It does not change +the repository's general latest-release pointer: the updater selects the CLI tag +namespace independently. A failed upload leaves a draft; an existing release +causes a rerun to stop, rather than overwrite its assets. Inspect and remove the +failed draft explicitly before rerunning. Signing/notarization and older glibc +compatibility remain separate distribution choices; the workflow adds neither. +No tag, public release, or workflow execution is needed to test this code: the +CLI uses a loopback release server and publication tests mock the GitHub CLI. diff --git a/polis-cli/tests/differential/cases.py b/polis-cli/tests/differential/cases.py index 7333d90ae..773994cea 100644 --- a/polis-cli/tests/differential/cases.py +++ b/polis-cli/tests/differential/cases.py @@ -13,6 +13,8 @@ def add(command,args=(),*,exit=0,scope='live',stdin=None,actor='owner'): # Local discovery is exercised as commands, not substituted for API calls. for command,args in [('schema',[]),('help',[]),('completion',['bash']),('tutorial',[]),('questions',[]),('agent guide',[]),('conversation share',[C]),('plan upgrade',[]),('plan manage',[])]: add(command,args,scope='local') + # Release transport/install behavior is covered by the local updater server tests. + add('update',['--release-base-url','file:///invalid-release-source'],exit=2,scope='invalid-input') add('auth login',['--with-token'],stdin='owner') add('auth status');add('auth token',scope='credential') add('account view');add('plan view') diff --git a/scripts/build-polis-cli-release.py b/scripts/build-polis-cli-release.py index 85e4cd429..dcc5cd3da 100644 --- a/scripts/build-polis-cli-release.py +++ b/scripts/build-polis-cli-release.py @@ -94,14 +94,27 @@ def package(outdir, binary, version, commit, target, source, compiler, lock, lic return archive +def check_tag(tag, version): + if not re.fullmatch(r"cli-v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)", tag) or tag != f"cli-v{version}": + raise ValueError("Release tag must be cli-v followed by the exact stable workspace version.") + + def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--target", choices=TARGETS, required=True) - parser.add_argument("--output", type=Path, required=True) + parser.add_argument("--target", choices=TARGETS) + parser.add_argument("--output", type=Path) + parser.add_argument("--check-tag") parser.add_argument("--source-commit") parser.add_argument("--allow-unverified-source", action="store_true") args = parser.parse_args() try: + if args.check_tag is not None: + version = tomllib.loads((ROOT / "polis-cli/Cargo.toml").read_text())["workspace"]["package"]["version"] + check_tag(args.check_tag, version) + print("Release tag matches workspace version.") + return + if args.target is None or args.output is None: + raise ValueError("Building requires --target and --output.") commit, source = provenance(ROOT, args.source_commit, args.allow_unverified_source) workspace = ROOT / "polis-cli" compiler = output(["rustc", "-vV"], workspace) diff --git a/scripts/publish-polis-cli-release.py b/scripts/publish-polis-cli-release.py new file mode 100644 index 000000000..cf425ca79 --- /dev/null +++ b/scripts/publish-polis-cli-release.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +"""Validate the complete native CLI set, then publish an existing release tag.""" +import argparse +import hashlib +import importlib.util +import json +from pathlib import Path +import re +import subprocess +import tarfile + +SPEC = importlib.util.spec_from_file_location("build_release", Path(__file__).with_name("build-polis-cli-release.py")) +build = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(build) + + +def validate(directory, tag, commit): + build.commit_id(commit) + if not re.fullmatch(r"cli-v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)", tag): + raise ValueError("Publication requires a stable cli-vMAJOR.MINOR.PATCH tag.") + version = tag.removeprefix("cli-v") + expected = set() + assets = [] + for target in build.TARGETS: + name = f"polis-{version}-{commit[:12]}-{target}" + archive = directory / (name + ".tar.gz") + checksum = directory / (archive.name + ".sha256") + expected.update((archive.name, checksum.name)) + if archive.is_symlink() or checksum.is_symlink() or not archive.is_file() or not checksum.is_file(): + raise ValueError("Missing or linked release asset.") + if archive.stat().st_size > 200 * 1024 * 1024: + raise ValueError("Release archive exceeds the updater limit.") + digest = hashlib.sha256(archive.read_bytes()).hexdigest() + if checksum.read_text() != f"{digest} {archive.name}\n": + raise ValueError("Release checksum mismatch.") + with tarfile.open(archive) as tar: + members = tar.getmembers() + names = {f"{name}/{part}" for part in ("polis", "manifest.json", "LICENSE", "README.txt")} + if len(members) != 4 or {m.name for m in members} != names or not all(m.isfile() for m in members): + raise ValueError("Unexpected release archive members.") + if any(m.size > (300 * 1024 * 1024 if m.name.endswith('/polis') else 64 * 1024) for m in members): + raise ValueError("Release member exceeds the updater limit.") + manifest = json.load(tar.extractfile(f"{name}/manifest.json")) + for key, value in dict(schema="polis-cli-release/1", version=version, commit=commit, + target=target, source="clean-checkout").items(): + if manifest.get(key) != value: + raise ValueError(f"Release manifest mismatch: {key}.") + binary = tar.extractfile(f"{name}/polis").read() + if not binary or hashlib.sha256(binary).hexdigest() != manifest.get("binary_sha256"): + raise ValueError("Release binary checksum mismatch.") + assets.extend((archive, checksum)) + if {p.name for p in directory.iterdir()} != expected: + raise ValueError("Publication requires exactly the four archives and their checksums.") + return assets + + +def publish(directory, tag, commit, repository): + if not re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+", repository): + raise ValueError("Invalid release repository.") + assets = validate(directory, tag, commit) + # --verify-tag prevents creation of a missing tag. Existing releases cause create + # to fail: reruns never overwrite a release or silently reuse earlier assets. + subprocess.run(["gh", "release", "create", tag, "--repo", repository, + "--verify-tag", "--draft", "--title", f"Polis CLI {tag[5:]}", + "--generate-notes"], check=True) + subprocess.run(["gh", "release", "upload", tag, "--repo", repository, + *map(str, assets)], check=True) + subprocess.run(["gh", "release", "edit", tag, "--repo", repository, + "--draft=false", "--latest=false"], check=True) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--directory", type=Path, required=True) + parser.add_argument("--tag", required=True) + parser.add_argument("--commit", required=True) + parser.add_argument("--repository", required=True) + parser.add_argument("--validate-only", action="store_true") + args = parser.parse_args() + try: + if args.validate_only: + validate(args.directory, args.tag, args.commit) + else: + publish(args.directory, args.tag, args.commit, args.repository) + except (ValueError, OSError, subprocess.CalledProcessError) as error: + parser.exit(1, f"release publication: {error}\n") + + +if __name__ == "__main__": + main() diff --git a/scripts/test-polis-cli.sh b/scripts/test-polis-cli.sh index 236c48808..64a20f65a 100755 --- a/scripts/test-polis-cli.sh +++ b/scripts/test-polis-cli.sh @@ -32,7 +32,7 @@ cargo clippy --locked -p polis --features fixture-ids --all-targets -- -D warnin cargo test --locked -p polis --features fixture-ids --bin polis seeds::fixture_tests # Release archive/provenance checks share the same local and hosted entry point. -PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s ../scripts/tests -p test_polis_cli_release.py +PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s ../scripts/tests -p 'test_polis_cli_release*.py' # The documented local member/vote join preserves export cells and unmatched rows. PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests/raw_data -p 'test_*.py' diff --git a/scripts/tests/test_polis_cli_release_publish.py b/scripts/tests/test_polis_cli_release_publish.py new file mode 100644 index 000000000..5e7dc0980 --- /dev/null +++ b/scripts/tests/test_polis_cli_release_publish.py @@ -0,0 +1,64 @@ +import importlib.util +from pathlib import Path +import subprocess +import tempfile +import unittest +from unittest.mock import patch + +SPEC = importlib.util.spec_from_file_location("publish", Path(__file__).resolve().parents[1] / "publish-polis-cli-release.py") +publish = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(publish) +COMMIT = "a" * 40 + + +class PublishTests(unittest.TestCase): + def bundle(self, directory, source="clean-checkout"): + for target in publish.build.TARGETS: + publish.build.package(directory, b"generated binary", "1.2.3", COMMIT, target, + source, "rustc fixture", b"lock", b"license") + + def test_four_targets_checked_before_any_publication(self): + with tempfile.TemporaryDirectory() as d, patch.object(publish.subprocess, "run") as run: + self.bundle(Path(d)) + assets = publish.validate(Path(d), "cli-v1.2.3", COMMIT) + self.assertEqual(len(assets), 8) + publish.publish(Path(d), "cli-v1.2.3", COMMIT, "example/project") + calls = [call.args[0] for call in run.call_args_list] + self.assertEqual(len(calls), 3) + self.assertEqual(calls[0][0:4], ["gh", "release", "create", "cli-v1.2.3"]) + self.assertIn("--verify-tag", calls[0]) + self.assertIn("--draft", calls[0]) + self.assertIn("--generate-notes", calls[0]) + self.assertEqual(calls[1][0:3], ["gh", "release", "upload"]) + self.assertEqual(calls[1][6:], list(map(str, assets))) + self.assertIn("--draft=false", calls[2]) + self.assertIn("--latest=false", calls[2]) + + def test_bad_tag_wrong_commit_missing_platform_and_checksum_fail_before_publish(self): + for mode in ["tag", "version", "commit", "missing", "checksum", "extra", "unverified"]: + with self.subTest(mode=mode), tempfile.TemporaryDirectory() as d, patch.object(publish.subprocess, "run") as run: + directory = Path(d) + self.bundle(directory, "unverified-archive" if mode == "unverified" else "clean-checkout") + if mode == "missing": next(directory.glob("*.tar.gz")).unlink() + if mode == "checksum": next(directory.glob("*.sha256")).write_text("0"*64) + if mode == "extra": (directory/"unexpected").write_text("extra") + tag = "bad" if mode == "tag" else "cli-v1.2.4" if mode == "version" else "cli-v1.2.3" + commit = "b"*40 if mode == "commit" else COMMIT + with self.assertRaises(ValueError): publish.publish(directory, tag, commit, "example/project") + run.assert_not_called() + + def test_upload_failure_leaves_release_draft(self): + with tempfile.TemporaryDirectory() as d, patch.object(publish.subprocess, "run") as run: + self.bundle(Path(d)) + run.side_effect = [None, subprocess.CalledProcessError(1, "gh upload")] + with self.assertRaises(subprocess.CalledProcessError): publish.publish(Path(d), "cli-v1.2.3", COMMIT, "example/project") + self.assertEqual(run.call_count, 2) + + def test_tag_guard(self): + publish.build.check_tag("cli-v1.2.3", "1.2.3") + for tag in ["v1.2.3", "cli-v1.2.4", "cli-v01.2.3", "cli-v1.2.3-beta", "cli-v1.2.3\n"]: + with self.assertRaises(ValueError): publish.build.check_tag(tag, "1.2.3") + + +if __name__ == "__main__": + unittest.main() From 089568ba004ad3b198f7872ee9d37ff5825c3272 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Tue, 20 Oct 2026 21:39:37 -0700 Subject: [PATCH 15/30] cdk: the web security group takes port 80 from the load balancer only, as deployed (#3119) The web security group no longer opens SSH (22), HTTP (80) or HTTPS (443) to the internet in code. Production has run this way since 2026-10-11: the web instances take port 80 from the load balancer's security group only, and nothing else reaches them from outside the VPC. Until now the code still added the three 0.0.0.0/0 rules, so the next deploy from this branch would have reopened them. Also brought over from the deployed stack, unchanged: - SSH stays off unless asked for, and turning it on now requires naming a range (CDK_SSH_ALLOWED_IP_RANGE); there is no 0.0.0.0/0 default. - cdk/originAccess.ts: two controls that let only the CDN reach the load balancer, both off by default. `-c restrictAlbIngress=true` replaces the load balancer's 80/443-from-anywhere rules with a prefix list or a list of CIDRs (config/cloudflare-ips-v4.json holds the CDN's published IPv4 ranges); `-c requireOriginHeader=true` makes both listeners answer 403 unless the request carries the CDN's origin header, read from Secrets Manager by name. dns.ts takes the listener settings from it. - test/originAccess.test.ts covers the web group, SSH, and both controls on and off. With every flag off, the load balancer's rules and listeners are exactly as before. The whole-stack snapshot changes only by the three web rules. The other deployed edits were already here and are untouched: the Delphi small box on r7i.2xlarge, the operational alarms, the ops dashboards policy, the large memory class (now the worker class table), the backup function packaging and the build box. Not changed here, and not yet in the deployed stack: the inactive coordinator service (always synthesized) and the reworded description of the CI worker's security group (synthesized with enableCiEc2; a description change replaces the group). Checked with `cdk synth -c enableCiEc2=true --no-lookups` of this branch and of the deployed tree: apart from those two and the CDK metadata resource that lists the constructs used, the templates are identical, including the backup function's asset hash. cdk tests: 10 suites, 182 passed; tsc clean. Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s Co-authored-by: Claude Fable 5.1 --- cdk/config/cloudflare-ips-v4.json | 22 +++ cdk/dns.ts | 32 +++- cdk/lib/cdk-stack.ts | 31 +++- cdk/originAccess.ts | 158 +++++++++++++++++ .../__snapshots__/workerClasses.test.ts.snap | 23 --- cdk/test/originAccess.test.ts | 163 ++++++++++++++++++ 6 files changed, 392 insertions(+), 37 deletions(-) create mode 100644 cdk/config/cloudflare-ips-v4.json create mode 100644 cdk/originAccess.ts create mode 100644 cdk/test/originAccess.test.ts diff --git a/cdk/config/cloudflare-ips-v4.json b/cdk/config/cloudflare-ips-v4.json new file mode 100644 index 000000000..e4c1583e7 --- /dev/null +++ b/cdk/config/cloudflare-ips-v4.json @@ -0,0 +1,22 @@ +{ + "source": "https://www.cloudflare.com/ips-v4", + "retrieved": "2026-10-11", + "note": "Cloudflare's published IPv4 ranges. Refresh from the source before each deploy that uses this file; a stale list blocks new Cloudflare edges.", + "cidrs": [ + "173.245.48.0/20", + "103.21.244.0/22", + "103.22.200.0/22", + "103.31.4.0/22", + "141.101.64.0/18", + "108.162.192.0/18", + "190.93.240.0/20", + "188.114.96.0/20", + "197.234.240.0/22", + "198.41.128.0/17", + "162.158.0.0/15", + "104.16.0.0/13", + "104.24.0.0/14", + "172.64.0.0/13", + "131.0.72.0/22" + ] +} diff --git a/cdk/dns.ts b/cdk/dns.ts index 3baddecc2..87bda05c7 100644 --- a/cdk/dns.ts +++ b/cdk/dns.ts @@ -2,12 +2,16 @@ import { Construct } from "constructs"; import * as cdk from 'aws-cdk-lib'; import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2'; import * as acm from 'aws-cdk-lib/aws-certificatemanager'; +import { OriginHeader } from './originAccess'; export default ( self: Construct, vpc: cdk.aws_ec2.Vpc, lbSecurityGroup: cdk.aws_ec2.SecurityGroup, - asgWeb: cdk.aws_autoscaling.AutoScalingGroup + asgWeb: cdk.aws_autoscaling.AutoScalingGroup, + // Both default to today's behaviour: listeners open to the world, and every + // request forwarded. See cdk/originAccess.ts. + access: { openListeners: boolean; originHeader?: OriginHeader } = { openListeners: true }, ) => { const lb = new elbv2.ApplicationLoadBalancer(self, 'Lb', { vpc, @@ -27,11 +31,28 @@ export default ( } }); + // With an origin header required, a request without it gets 403 and only a + // matching request reaches the web instances. Load balancer health checks + // go straight to the targets and are not affected. + const { originHeader } = access; + const routing = originHeader + ? { defaultAction: elbv2.ListenerAction.fixedResponse(403, { contentType: 'text/plain', messageBody: 'Forbidden' }) } + : { defaultTargetGroups: [webTargetGroup] }; + const requireHeader = (listener: elbv2.ApplicationListener, id: string) => { + if (!originHeader) return; + listener.addAction(id, { + priority: 1, + conditions: [elbv2.ListenerCondition.httpHeader(originHeader.name, [originHeader.value])], + action: elbv2.ListenerAction.forward([webTargetGroup]), + }); + }; + const httpListener = lb.addListener('HttpListener', { port: 80, - open: true, - defaultTargetGroups: [webTargetGroup], + open: access.openListeners, + ...routing, }); + requireHeader(httpListener, 'HttpOriginHeader'); const certificate = new acm.Certificate(self, 'WebAppCertificate', { domainName: 'pol.is', @@ -41,9 +62,10 @@ export default ( const httpsListener = lb.addListener('HttpsListener', { port: 443, certificates: [certificate], - open: true, - defaultTargetGroups: [webTargetGroup], + open: access.openListeners, + ...routing, }); + requireHeader(httpsListener, 'HttpsOriginHeader'); const webScalingPolicy = asgWeb.scaleOnRequestCount('WebScalingPolicy', { targetRequestsPerMinute: 600, diff --git a/cdk/lib/cdk-stack.ts b/cdk/lib/cdk-stack.ts index d5065c277..cadb904bf 100644 --- a/cdk/lib/cdk-stack.ts +++ b/cdk/lib/cdk-stack.ts @@ -46,6 +46,7 @@ import createWorkerClasses, { import createOpsDashboardsAccess, { opsDashboardsEnabled } from '../opsDashboards'; import { ImportWorkerService } from './import-worker-service'; import { CertificationCiEc2 } from '../ciEc2'; +import { configureAlbIngress, originHeader } from '../originAccess'; import { BuildBox } from '../buildBox'; import { CoordinatorInactiveService } from '../coordinator'; @@ -66,7 +67,6 @@ export class CdkStack extends cdk.Stack { constructor(scope: Construct, id: string, props: PolisStackProps) { super(scope, id, props); - const defaultSSHRange = '0.0.0.0/0'; // The Ollama GPU stack is temporarily retired to cut cost. Everything it // needs (ASG, GPU launch template, EFS, internal NLB, service-URL secret, // SG rules and outputs) is gated behind this flag (CDK_ENABLE_OLLAMA). The @@ -115,9 +115,15 @@ export class CdkStack extends cdk.Stack { ); } - // Conditional SSH Access + // Conditional SSH Access. Off in production: the instances are reached + // through Systems Manager (the instance role carries + // AmazonSSMManagedInstanceCore), and CodeDeploy's agent only connects out. + // There is no default range: turning SSH on requires naming one. if (props.enableSSHAccess) { - const sshPeer = ec2.Peer.ipv4(props.sshAllowedIpRange || defaultSSHRange); + if (!props.sshAllowedIpRange) { + throw new Error('enableSSHAccess requires sshAllowedIpRange (CDK_SSH_ALLOWED_IP_RANGE)'); + } + const sshPeer = ec2.Peer.ipv4(props.sshAllowedIpRange); webSecurityGroup.addIngressRule(sshPeer, ec2.Port.tcp(22), 'Allow SSH access'); mathWorkerSecurityGroup.addIngressRule(sshPeer, ec2.Port.tcp(22), 'Allow SSH access'); delphiSecurityGroup.addIngressRule(sshPeer, ec2.Port.tcp(22), 'Allow SSH access'); @@ -126,9 +132,12 @@ export class CdkStack extends cdk.Stack { } } - webSecurityGroup.addIngressRule(ec2.Peer.ipv4(props.sshAllowedIpRange || defaultSSHRange), ec2.Port.tcp(22), 'Allow SSH'); // Control SSH separately - webSecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(80), 'Allow HTTP from anywhere'); - webSecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(443), 'Allow HTTPS from anywhere'); + // The web instances take traffic only from the load balancer: the target + // group adds "port 80 from the load balancer's security group" below + // (createALBAndDNS). Nothing else reaches them from outside the VPC; they + // keep public addresses for outbound traffic only. (The group's + // description still mentions SSH; changing a description replaces the + // group, so it is left as is.) // --- Key Pairs @@ -161,8 +170,9 @@ export class CdkStack extends cdk.Stack { description: 'Security group for the load balancer', allowAllOutbound: true, }); - lbSecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(80), 'Allow HTTP from anywhere'); - lbSecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(443), 'Allow HTTPS from anywhere'); + // 80/443 from anywhere unless `-c restrictAlbIngress=true` names the CDN's + // ranges (cdk/originAccess.ts). + const albAccess = configureAlbIngress(this, lbSecurityGroup); // Create ECR repos const { ecrWebRepository, ecrDelphiRepository, ecrMathRepository, imageTagParameter } = createECRRepos(this, instanceRole); @@ -427,7 +437,10 @@ export class CdkStack extends cdk.Stack { this, vpc, lbSecurityGroup, - asgWeb + asgWeb, + // `-c requireOriginHeader=true` answers 403 to requests without the + // CDN's origin header (cdk/originAccess.ts). Off by default. + { openListeners: albAccess.openListeners, originHeader: originHeader(this) } ); // --- Operational alarms (P-031 slice 1). diff --git a/cdk/originAccess.ts b/cdk/originAccess.ts new file mode 100644 index 000000000..580f58305 --- /dev/null +++ b/cdk/originAccess.ts @@ -0,0 +1,158 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import * as cdk from 'aws-cdk-lib'; +import * as ec2 from 'aws-cdk-lib/aws-ec2'; +import { Construct } from 'constructs'; + +// Who may reach the load balancer, and what it requires of them. +// +// Both controls are OFF by default: without these context keys the load +// balancer accepts 80/443 from anywhere and forwards every request, exactly +// as before. They exist so that only the CDN in front of the site can reach +// the origin. Turn them on in this order (cdk/README.md, "Closing the origin"): +// 1. create the origin secret and the CDN rule that sends it as a header; +// 2. deploy with `-c requireOriginHeader=true -c originHeaderSecretName=...`; +// 3. deploy with `-c restrictAlbIngress=true` and one ingress source. +// Turning on step 2 before the CDN sends the header answers every request +// with 403. + +export const RESTRICT_ALB_INGRESS_CONTEXT = 'restrictAlbIngress'; +// One of these three names the allowed sources when the restriction is on. +export const ALB_INGRESS_PREFIX_LIST_CONTEXT = 'albIngressPrefixListId'; +export const ALB_INGRESS_CIDRS_FILE_CONTEXT = 'albIngressCidrsFile'; +export const ALB_INGRESS_CIDRS_CONTEXT = 'albIngressCidrs'; + +export const REQUIRE_ORIGIN_HEADER_CONTEXT = 'requireOriginHeader'; +export const ORIGIN_HEADER_SECRET_CONTEXT = 'originHeaderSecretName'; +export const ORIGIN_HEADER_SECRET_VERSION_CONTEXT = 'originHeaderSecretVersionId'; +export const ORIGIN_HEADER_NAME_CONTEXT = 'originHeaderName'; +export const DEFAULT_ORIGIN_HEADER_NAME = 'X-Polis-Origin-Auth'; + +// The ports the load balancer listens on. Both stay reachable from the CDN: +// which one it uses depends on the CDN's TLS mode. +export const ALB_PORTS = [80, 443]; +// The default per-group inbound rule quota. Each CIDR costs one rule per port. +const MAX_INGRESS_RULES = 60; + +const flag = (scope: Construct, key: string): boolean => { + const v = scope.node.tryGetContext(key); + return v === true || v === 'true'; +}; + +const str = (scope: Construct, key: string): string | undefined => { + const v = scope.node.tryGetContext(key); + if (v === undefined || v === null || v === '') return undefined; + if (typeof v !== 'string') throw new Error(`-c ${key} must be a string`); + return v.trim(); +}; + +export const restrictAlbIngressEnabled = (scope: Construct) => flag(scope, RESTRICT_ALB_INGRESS_CONTEXT); +export const requireOriginHeaderEnabled = (scope: Construct) => flag(scope, REQUIRE_ORIGIN_HEADER_CONTEXT); + +export type AlbIngressSource = + | { kind: 'prefixList'; prefixListId: string } + | { kind: 'cidrs'; cidrs: string[] }; + +const IPV4_CIDR = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/; + +export const validateIpv4Cidr = (cidr: string): string => { + const m = IPV4_CIDR.exec(cidr); + if (!m || m.slice(1, 5).some((o) => Number(o) > 255) || Number(m[5]) > 32) { + throw new Error(`not an IPv4 CIDR: '${cidr}'`); + } + if (Number(m[5]) === 0) { + throw new Error(`'${cidr}' allows every address; the restriction would be a no-op`); + } + return cidr; +}; + +const parseCidrList = (raw: unknown, where: string): string[] => { + const list = Array.isArray(raw) + ? raw + : typeof raw === 'string' + ? raw.split(',') + : undefined; + if (!list) throw new Error(`${where}: expected a list of IPv4 CIDRs`); + const cidrs = list.map((c) => String(c).trim()).filter(Boolean).map(validateIpv4Cidr); + if (cidrs.length === 0) throw new Error(`${where}: the list of IPv4 CIDRs is empty`); + return [...new Set(cidrs)]; +}; + +// Reads a JSON file holding either an array of CIDRs or an object with a +// `cidrs` array (other keys, such as where the list came from, are ignored). +// A relative path is resolved against the cdk/ directory. +export const readCidrsFile = (file: string): string[] => { + const resolved = path.resolve(__dirname, file); + const parsed = JSON.parse(fs.readFileSync(resolved, 'utf8')); + return parseCidrList(Array.isArray(parsed) ? parsed : parsed?.cidrs, resolved); +}; + +export const albIngressSource = (scope: Construct): AlbIngressSource => { + const prefixList = str(scope, ALB_INGRESS_PREFIX_LIST_CONTEXT); + const file = str(scope, ALB_INGRESS_CIDRS_FILE_CONTEXT); + const inline = scope.node.tryGetContext(ALB_INGRESS_CIDRS_CONTEXT); + const given = [prefixList, file, inline].filter((v) => v !== undefined && v !== ''); + if (given.length !== 1) { + throw new Error( + `-c ${RESTRICT_ALB_INGRESS_CONTEXT}=true needs exactly one of -c ${ALB_INGRESS_PREFIX_LIST_CONTEXT}=pl-..., ` + + `-c ${ALB_INGRESS_CIDRS_FILE_CONTEXT}= or -c ${ALB_INGRESS_CIDRS_CONTEXT}= ` + + `(got ${given.length})`); + } + if (prefixList !== undefined) { + if (!/^pl-[0-9a-f]{8,17}$/.test(prefixList)) { + throw new Error(`-c ${ALB_INGRESS_PREFIX_LIST_CONTEXT}: not a prefix list id: '${prefixList}'`); + } + return { kind: 'prefixList', prefixListId: prefixList }; + } + const cidrs = file !== undefined ? readCidrsFile(file) : parseCidrList(inline, `-c ${ALB_INGRESS_CIDRS_CONTEXT}`); + if (cidrs.length * ALB_PORTS.length > MAX_INGRESS_RULES) { + throw new Error( + `${cidrs.length} CIDRs x ${ALB_PORTS.length} ports exceeds the ${MAX_INGRESS_RULES}-rule security group ` + + `quota; use a managed prefix list (-c ${ALB_INGRESS_PREFIX_LIST_CONTEXT}) instead`); + } + return { kind: 'cidrs', cidrs }; +}; + +// Adds the load balancer's inbound rules. Returns whether the listeners may +// still open themselves to the world (`open: true`), which is the case only +// when the restriction is off. +export const configureAlbIngress = (scope: Construct, lbSecurityGroup: ec2.SecurityGroup): { openListeners: boolean } => { + if (!restrictAlbIngressEnabled(scope)) { + lbSecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(80), 'Allow HTTP from anywhere'); + lbSecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(443), 'Allow HTTPS from anywhere'); + return { openListeners: true }; + } + const source = albIngressSource(scope); + const peers: Array<{ peer: ec2.IPeer; label: string }> = source.kind === 'prefixList' + ? [{ peer: ec2.Peer.prefixList(source.prefixListId), label: `prefix list ${source.prefixListId}` }] + : source.cidrs.map((c) => ({ peer: ec2.Peer.ipv4(c), label: c })); + for (const port of ALB_PORTS) { + for (const { peer, label } of peers) { + lbSecurityGroup.addIngressRule(peer, ec2.Port.tcp(port), `Allow ${port} from the CDN (${label})`); + } + } + return { openListeners: false }; +}; + +export interface OriginHeader { + name: string; + // A CloudFormation dynamic reference to the secret; the value itself never + // appears in the repository or the synthesized template. + value: string; +} + +export const originHeader = (scope: Construct): OriginHeader | undefined => { + if (!requireOriginHeaderEnabled(scope)) return undefined; + const secretName = str(scope, ORIGIN_HEADER_SECRET_CONTEXT); + if (!secretName) { + throw new Error( + `-c ${REQUIRE_ORIGIN_HEADER_CONTEXT}=true needs -c ${ORIGIN_HEADER_SECRET_CONTEXT}=`); + } + const name = str(scope, ORIGIN_HEADER_NAME_CONTEXT) ?? DEFAULT_ORIGIN_HEADER_NAME; + if (!/^[A-Za-z0-9-]{1,40}$/.test(name)) { + throw new Error(`-c ${ORIGIN_HEADER_NAME_CONTEXT}: not a plain header name: '${name}'`); + } + const versionId = str(scope, ORIGIN_HEADER_SECRET_VERSION_CONTEXT); + const value = cdk.SecretValue.secretsManager(secretName, versionId ? { versionId } : {}).unsafeUnwrap(); + return { name, value }; +}; diff --git a/cdk/test/__snapshots__/workerClasses.test.ts.snap b/cdk/test/__snapshots__/workerClasses.test.ts.snap index 6689991a9..6d0a48593 100644 --- a/cdk/test/__snapshots__/workerClasses.test.ts.snap +++ b/cdk/test/__snapshots__/workerClasses.test.ts.snap @@ -5241,29 +5241,6 @@ rm -fr $TMP_DIR", "IpProtocol": "-1", }, ], - "SecurityGroupIngress": [ - { - "CidrIp": "0.0.0.0/0", - "Description": "Allow SSH", - "FromPort": 22, - "IpProtocol": "tcp", - "ToPort": 22, - }, - { - "CidrIp": "0.0.0.0/0", - "Description": "Allow HTTP from anywhere", - "FromPort": 80, - "IpProtocol": "tcp", - "ToPort": 80, - }, - { - "CidrIp": "0.0.0.0/0", - "Description": "Allow HTTPS from anywhere", - "FromPort": 443, - "IpProtocol": "tcp", - "ToPort": 443, - }, - ], "VpcId": { "Ref": "Vpc8378EB38", }, diff --git a/cdk/test/originAccess.test.ts b/cdk/test/originAccess.test.ts new file mode 100644 index 000000000..12f3f0974 --- /dev/null +++ b/cdk/test/originAccess.test.ts @@ -0,0 +1,163 @@ +import * as cdk from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import { CdkStack } from '../lib/cdk-stack'; +import { + ALB_INGRESS_CIDRS_CONTEXT, ALB_INGRESS_CIDRS_FILE_CONTEXT, ALB_INGRESS_PREFIX_LIST_CONTEXT, + DEFAULT_ORIGIN_HEADER_NAME, ORIGIN_HEADER_NAME_CONTEXT, ORIGIN_HEADER_SECRET_CONTEXT, + REQUIRE_ORIGIN_HEADER_CONTEXT, RESTRICT_ALB_INGRESS_CONTEXT, readCidrsFile, validateIpv4Cidr, +} from '../originAccess'; + +// The production stack as deployed (`-c enableCiEc2=true`), bundling skipped. +const stack = (context: Record = {}, props: Record = {}) => { + const app = new cdk.App({ context: { 'aws:cdk:bundling-stacks': [], enableCiEc2: true, ...context } }); + return new CdkStack(app, 'CdkStack', { + env: { account: '123456789012', region: 'us-east-1' }, + envFile: '/dev/null', + enableSSHAccess: false, + enableOllama: false, + ...props, + }); +}; +const synth = (context: Record = {}) => Template.fromStack(stack(context)); + +type Rule = { group: string; port: number; cidr?: string; sourceGroup?: string; prefixList?: string }; +const groupId = (logicalId: string) => logicalId; +const refOf = (v: any): string | undefined => v?.['Fn::GetAtt']?.[0] ?? v?.Ref; + +// Every inbound rule in the template, inline or as a separate resource. +const ingress = (t: Template): Rule[] => { + const rules: Rule[] = []; + const res = t.toJSON().Resources as Record; + for (const [id, r] of Object.entries(res)) { + if (r.Type === 'AWS::EC2::SecurityGroup') { + for (const i of r.Properties.SecurityGroupIngress ?? []) { + rules.push({ group: groupId(id), port: i.FromPort, cidr: i.CidrIp, sourceGroup: refOf(i.SourceSecurityGroupId), prefixList: i.SourcePrefixListId }); + } + } + if (r.Type === 'AWS::EC2::SecurityGroupIngress') { + const p = r.Properties; + rules.push({ group: refOf(p.GroupId)!, port: p.FromPort, cidr: p.CidrIp, sourceGroup: refOf(p.SourceSecurityGroupId), prefixList: p.SourcePrefixListId }); + } + } + return rules; +}; +const isWeb = (g: string) => g.startsWith('WebSecurityGroup'); +const isLb = (g: string) => g.startsWith('LBSecurityGroup'); +const listeners = (t: Template) => Object.values(t.findResources('AWS::ElasticLoadBalancingV2::Listener')) as any[]; + +const CLOUDFLARE = readCidrsFile('config/cloudflare-ips-v4.json'); + +describe('web instances (always on)', () => { + const t = synth(); + test('the web security group admits port 80 from the load balancer and nothing else', () => { + const web = ingress(t).filter((r) => isWeb(r.group)); + expect(web).toEqual([{ group: expect.stringMatching(/^WebSecurityGroup/), port: 80, sourceGroup: expect.stringMatching(/^LBSecurityGroup/), cidr: undefined, prefixList: undefined }]); + }); + test('no security group in the stack admits SSH', () => { + expect(ingress(t).filter((r) => r.port === 22)).toEqual([]); + }); + test('turning SSH on requires an explicit range', () => { + expect(() => stack({}, { enableSSHAccess: true })).toThrow(/sshAllowedIpRange/); + }); +}); + +describe('flags off', () => { + const t = synth(); + test('the load balancer still takes 80 and 443 from anywhere', () => { + const lb = ingress(t).filter((r) => isLb(r.group)); + expect(lb.map((r) => [r.port, r.cidr])).toEqual([[80, '0.0.0.0/0'], [443, '0.0.0.0/0']]); + }); + test('both listeners forward by default and carry no rules', () => { + for (const l of listeners(t)) expect(l.Properties.DefaultActions[0].Type).toBe('forward'); + t.resourceCountIs('AWS::ElasticLoadBalancingV2::ListenerRule', 0); + }); + test('explicit false equals no flag', () => { + expect(synth({ [RESTRICT_ALB_INGRESS_CONTEXT]: 'false', [REQUIRE_ORIGIN_HEADER_CONTEXT]: 'false' }).toJSON()) + .toEqual(t.toJSON()); + }); + test('a source given without the flag changes nothing', () => { + expect(synth({ [ALB_INGRESS_CIDRS_FILE_CONTEXT]: 'config/cloudflare-ips-v4.json' }).toJSON()).toEqual(t.toJSON()); + }); +}); + +describe(`${RESTRICT_ALB_INGRESS_CONTEXT}`, () => { + test('from a CIDR file: exactly the listed ranges on 80 and 443, nothing from anywhere', () => { + const t = synth({ [RESTRICT_ALB_INGRESS_CONTEXT]: 'true', [ALB_INGRESS_CIDRS_FILE_CONTEXT]: 'config/cloudflare-ips-v4.json' }); + const lb = ingress(t).filter((r) => isLb(r.group)); + expect(lb).toHaveLength(CLOUDFLARE.length * 2); + for (const port of [80, 443]) { + expect(lb.filter((r) => r.port === port).map((r) => r.cidr).sort()).toEqual([...CLOUDFLARE].sort()); + } + expect(ingress(t).filter((r) => r.cidr === '0.0.0.0/0')).toEqual([]); + // The web group is unchanged by the flag. + expect(ingress(t).filter((r) => isWeb(r.group))).toEqual(ingress(synth()).filter((r) => isWeb(r.group))); + }); + test('from a prefix list: one rule per port', () => { + const t = synth({ [RESTRICT_ALB_INGRESS_CONTEXT]: true, [ALB_INGRESS_PREFIX_LIST_CONTEXT]: 'pl-0123456789abcdef0' }); + const lb = ingress(t).filter((r) => isLb(r.group)); + expect(lb.map((r) => [r.port, r.prefixList, r.cidr])).toEqual([ + [80, 'pl-0123456789abcdef0', undefined], [443, 'pl-0123456789abcdef0', undefined], + ]); + }); + test('inline ranges', () => { + const t = synth({ [RESTRICT_ALB_INGRESS_CONTEXT]: 'true', [ALB_INGRESS_CIDRS_CONTEXT]: '198.51.100.0/24, 203.0.113.0/24' }); + expect(ingress(t).filter((r) => isLb(r.group)).map((r) => `${r.port} ${r.cidr}`)).toEqual([ + '80 198.51.100.0/24', '80 203.0.113.0/24', '443 198.51.100.0/24', '443 203.0.113.0/24', + ]); + }); + test('refuses no source, two sources, a /0 range and too many rules', () => { + const on = { [RESTRICT_ALB_INGRESS_CONTEXT]: 'true' }; + expect(() => synth(on)).toThrow(/exactly one/); + expect(() => synth({ ...on, [ALB_INGRESS_PREFIX_LIST_CONTEXT]: 'pl-0123456789abcdef0', [ALB_INGRESS_CIDRS_CONTEXT]: '198.51.100.0/24' })).toThrow(/exactly one/); + expect(() => synth({ ...on, [ALB_INGRESS_CIDRS_CONTEXT]: '0.0.0.0/0' })).toThrow(/every address/); + expect(() => synth({ ...on, [ALB_INGRESS_PREFIX_LIST_CONTEXT]: 'sg-123' })).toThrow(/prefix list/); + const many = Array.from({ length: 31 }, (_, i) => `10.${i}.0.0/16`).join(','); + expect(() => synth({ ...on, [ALB_INGRESS_CIDRS_CONTEXT]: many })).toThrow(/quota/); + }); + test('CIDR validation', () => { + expect(validateIpv4Cidr('104.16.0.0/13')).toBe('104.16.0.0/13'); + for (const bad of ['104.16.0.0', '300.1.1.1/8', '1.2.3.4/33', '2400:cb00::/32']) expect(() => validateIpv4Cidr(bad)).toThrow(); + }); +}); + +describe(`${REQUIRE_ORIGIN_HEADER_CONTEXT}`, () => { + const on = { [REQUIRE_ORIGIN_HEADER_CONTEXT]: 'true', [ORIGIN_HEADER_SECRET_CONTEXT]: 'polis/origin-header' }; + test('both listeners answer 403 by default and forward only with the header', () => { + const t = synth(on); + const ls = listeners(t); + expect(ls).toHaveLength(2); + for (const l of ls) { + expect(l.Properties.DefaultActions).toEqual([{ + Type: 'fixed-response', + FixedResponseConfig: { StatusCode: '403', ContentType: 'text/plain', MessageBody: 'Forbidden' }, + }]); + } + const rules = Object.values(t.findResources('AWS::ElasticLoadBalancingV2::ListenerRule')) as any[]; + expect(rules).toHaveLength(2); + for (const r of rules) { + expect(r.Properties.Priority).toBe(1); + expect(r.Properties.Actions[0].Type).toBe('forward'); + expect(r.Properties.Conditions).toEqual([{ + Field: 'http-header', + HttpHeaderConfig: { + HttpHeaderName: DEFAULT_ORIGIN_HEADER_NAME, + Values: ['{{resolve:secretsmanager:polis/origin-header:SecretString:::}}'], + }, + }]); + } + }); + test('it does not change who can reach the load balancer', () => { + const lb = ingress(synth(on)).filter((r) => isLb(r.group)); + expect(lb.map((r) => [r.port, r.cidr])).toEqual([[80, '0.0.0.0/0'], [443, '0.0.0.0/0']]); + }); + test('header name is configurable; the secret name is required', () => { + const t = synth({ ...on, [ORIGIN_HEADER_NAME_CONTEXT]: 'X-Other' }); + expect(JSON.stringify(t.findResources('AWS::ElasticLoadBalancingV2::ListenerRule'))).toContain('"X-Other"'); + expect(() => synth({ [REQUIRE_ORIGIN_HEADER_CONTEXT]: 'true' })).toThrow(/originHeaderSecretName/); + }); + test('both flags together', () => { + const t = synth({ ...on, [RESTRICT_ALB_INGRESS_CONTEXT]: 'true', [ALB_INGRESS_PREFIX_LIST_CONTEXT]: 'pl-0123456789abcdef0' }); + t.resourceCountIs('AWS::ElasticLoadBalancingV2::ListenerRule', 2); + expect(ingress(t).filter((r) => r.cidr === '0.0.0.0/0')).toEqual([]); + }); +}); From 83f7f63f27bce5c98c485d104dd33c62668c8f5c Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Tue, 20 Oct 2026 23:37:38 -0700 Subject: [PATCH 16/30] migrations: every harness applies a migration through polis-migrate's contract; concurrent index builds get a restricted header (#3244) The replays, the coordinator tools, several test fixtures and db-reset sent each migration file to PostgreSQL as one query, an implicit transaction that refuses anything which must run outside one. A shared Node helper and a shared Python helper now hand header-marked files to polis-migrate, which gains a restricted concurrent-indexes header: one autocommit per plain btree index under the deploy's advisory lock, verified valid before history is written, everything else refused with a test. No migration is added. Co-authored-by: Claude Fable 5.1 --- ci/vote_convention/compose.yml | 8 +- ci/vote_convention/init-migrations.sh | 23 ++ coordinator-rs/ci/run.py | 12 +- coordinator-rs/tools/d05/run.py | 6 +- coordinator-rs/tools/d07/boundary.py | 6 +- coordinator-rs/tools/d07/startup.py | 4 +- coordinator-rs/tools/schema_census.py | 10 +- delphi/tests/coordinator/conftest.py | 5 +- delphi/tests/poller/recovery/conftest.py | 18 +- delphi/tests/projgate/projection_gate_test.py | 27 +- docs/migrations.md | 36 ++- queue-rs/polis-migrate/src/indexes.rs | 232 +++++++++++++++++- queue-rs/polis-migrate/src/lib.rs | 24 ++ queue-rs/polis-migrate/src/main.rs | 22 +- .../tests/fixtures/concurrent-indexes.sql | 4 + queue-rs/polis-migrate/tests/forward.py | 2 +- queue-rs/polis-migrate/tests/indexes.py | 120 +++++++++ server/bin/apply-test-migration.py | 41 ++++ server/bin/db-reset.js | 39 +-- server/characterization/Dockerfile | 9 + .../characterization/Dockerfile.dockerignore | 5 + .../collective-statement/main.cjs | 2 +- .../collective-statement/mutations.cjs | 1 + .../collective-statement/schema.test.cjs | 2 +- server/characterization/delphi/compose.yml | 5 +- server/characterization/delphi/main.cjs | 2 +- server/characterization/migrations.cjs | 33 +++ 27 files changed, 618 insertions(+), 80 deletions(-) create mode 100644 ci/vote_convention/init-migrations.sh create mode 100644 queue-rs/polis-migrate/tests/fixtures/concurrent-indexes.sql create mode 100644 server/bin/apply-test-migration.py create mode 100644 server/characterization/Dockerfile create mode 100644 server/characterization/Dockerfile.dockerignore create mode 100644 server/characterization/migrations.cjs diff --git a/ci/vote_convention/compose.yml b/ci/vote_convention/compose.yml index 8ef489142..4abeab85e 100644 --- a/ci/vote_convention/compose.yml +++ b/ci/vote_convention/compose.yml @@ -3,7 +3,11 @@ # per storage convention. Nothing here talks to a cloud service. services: postgres: - image: postgres:17-alpine + build: + context: ../../server + dockerfile: Dockerfile-db + additional_contexts: + queue-rs: ../../queue-rs environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: gate @@ -11,7 +15,7 @@ services: ports: - "127.0.0.1:${VOTE_GATE_PG_PORT:-5470}:5432" volumes: - - ../../server/postgres/migrations:/docker-entrypoint-initdb.d:ro + - ./init-migrations.sh:/docker-entrypoint-initdb.d/00-migrations.sh:ro healthcheck: test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U postgres -d gate_template"] # TCP: up only after the init scripts interval: 2s diff --git a/ci/vote_convention/init-migrations.sh b/ci/vote_convention/init-migrations.sh new file mode 100644 index 000000000..0d87071c2 --- /dev/null +++ b/ci/vote_convention/init-migrations.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -eu +# Keep the gate's historical full inventory, including held files. Only the +# marked index files need the deployment runner's autocommit and verification. +export DATABASE_URL="host=/var/run/postgresql user=$POSTGRES_USER dbname=$POSTGRES_DB sslmode=disable" +for file in /migrations/*.sql; do + if awk ' + /^[[:space:]]*$/ { next } + /^[[:space:]]*--/ { + line=$0 + sub(/^[[:space:]]*/, "", line) + sub(/[[:space:]]*$/, "", line) + if (line == "-- polis-migrate: concurrent-indexes") marked=1 + next + } + { exit } + END { exit !marked } + ' "$file"; then + polis-migrate prepare-indexes --file "$file" + else + psql -X -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -f "$file" + fi +done diff --git a/coordinator-rs/ci/run.py b/coordinator-rs/ci/run.py index 6dc81bea2..81cb25c80 100644 --- a/coordinator-rs/ci/run.py +++ b/coordinator-rs/ci/run.py @@ -23,6 +23,10 @@ from replay_pins import child_runtimes, kernel_environment, select_pin, validate_kernel ROOT = Path(__file__).resolve().parents[2] + +import runpy +apply_migration = runpy.run_path(str(ROOT / "server/bin/apply-test-migration.py"))["apply_migration"] + CI = ROOT / "coordinator-rs/ci" ART = ROOT / "coordinator-rs/artifacts" EVIDENCE = ROOT / "coordinator-rs/evidence" @@ -104,6 +108,7 @@ def main(): from tls_fixture import TlsFixture tls_fixture = TlsFixture() env.update(tls_fixture.environment()) + env["POLIS_MIGRATE_CA_FILE"] = env["COORDINATOR_DB_CA_BUNDLE"] def run(name, argv, cwd=None, expected=0, command_env=None): cwd = ROOT if cwd is None else cwd @@ -199,10 +204,9 @@ def run(name, argv, cwd=None, expected=0, command_env=None): conn.close() bundle_url = f"postgresql://postgres@127.0.0.1:{port}/d02_bundle" conn = psycopg2.connect(bundle_url) - with conn: - with conn.cursor() as cur: - for path in sorted((ROOT / "server/postgres/migrations").glob("*.sql")): - cur.execute(path.read_text()) + conn.autocommit = True + for path in sorted((ROOT / "server/postgres/migrations").glob("*.sql")): + apply_migration(conn, path, ca_file=env["POLIS_MIGRATE_CA_FILE"]) conn.close() log = run("pytest", [sys.executable, "-m", "pytest", "-o", "addopts=", "-p", "no:cacheprovider", "-p", "required_inventory", "--confcutdir=delphi/tests/coordinator", diff --git a/coordinator-rs/tools/d05/run.py b/coordinator-rs/tools/d05/run.py index 08110c544..56bc8bdf8 100644 --- a/coordinator-rs/tools/d05/run.py +++ b/coordinator-rs/tools/d05/run.py @@ -20,6 +20,10 @@ from tunnel import Tunnel ROOT = Path(__file__).resolve().parents[3] + +import runpy +apply_migration = runpy.run_path(str(ROOT / "server/bin/apply-test-migration.py"))["apply_migration"] + sys.path.insert(0, str(ROOT / "delphi/tests")) from vote_fixtures import AGREE, DISAGREE, PASS, seed_vote # noqa: E402 (the fixture vote writer) TABLES = ("ticks", "bidtopid", "ptptstats", "main") @@ -156,7 +160,7 @@ def prepare(self): self.connection = psycopg2.connect(f"postgresql://postgres@127.0.0.1:{self.port}/p027") self.connection.autocommit = True for path in sorted((ROOT/"server/postgres/migrations").glob("*.sql")): - self.query(path.read_text()) + apply_migration(self.connection, path) self.query("CREATE ROLE d05_control LOGIN; CREATE ROLE d05_publisher LOGIN; CREATE ROLE d05_operator_p LOGIN; CREATE ROLE d05_operator_l LOGIN") self.query("GRANT polis_coordinator_control TO d05_control,d05_operator_p,d05_operator_l; GRANT polis_coordinator_publisher TO d05_publisher") self.query("GRANT USAGE ON SCHEMA public TO d05_control,d05_publisher,d05_operator_p,d05_operator_l") diff --git a/coordinator-rs/tools/d07/boundary.py b/coordinator-rs/tools/d07/boundary.py index ae48a6da6..7e8c09d89 100644 --- a/coordinator-rs/tools/d07/boundary.py +++ b/coordinator-rs/tools/d07/boundary.py @@ -20,6 +20,10 @@ import psycopg2 ROOT = Path(__file__).resolve().parents[3] + +import runpy +apply_migration = runpy.run_path(str(ROOT / "server/bin/apply-test-migration.py"))["apply_migration"] + SQL = "server/postgres/migrations/000021_create_polis_coordinator.sql" SQL_SHA256 = "d50f169ad7afe12d14582a6a746c622d402ecafd8131aae246812263bf2d5e82" IMAGES = ("postgres:17-alpine", "p027-server", "p027-file-server", @@ -179,7 +183,7 @@ def run(self): migrations = sorted((ROOT / "server/postgres/migrations").glob("*.sql")) self.receipt["migrations"] = {p.name: sha(p.read_bytes()) for p in migrations} for path in migrations: - q(path.read_text()) + apply_migration(admin, path) catalog = q("SELECT pg_temp.pc_catalog()")[0][0] q("SELECT pg_temp.pc_assert_provenance()") self.receipt["postgres"] = q("SELECT version()")[0][0] diff --git a/coordinator-rs/tools/d07/startup.py b/coordinator-rs/tools/d07/startup.py index 8b3e27361..80b7b9730 100644 --- a/coordinator-rs/tools/d07/startup.py +++ b/coordinator-rs/tools/d07/startup.py @@ -18,7 +18,7 @@ import psycopg2 from psycopg2.extras import execute_values -from boundary import Boundary, ROOT, SQL, SQL_SHA256, sha, public_census +from boundary import Boundary, ROOT, SQL, SQL_SHA256, sha, public_census, apply_migration sys.path.insert(0,str(ROOT/'coordinator-rs/tools/d05')) from tunnel import Tunnel sys.path.insert(0,str(ROOT/'delphi/tests')) @@ -77,7 +77,7 @@ def run(self): q=lambda sql,args=None:self.query(conn,sql,args) migrations=sorted((ROOT/'server/postgres/migrations').glob('*.sql')) self.receipt['migrations']={p.name:sha(p.read_bytes()) for p in migrations} - for path in migrations:q(path.read_text()) + for path in migrations:apply_migration(conn, path) q('SELECT pg_temp.pc_assert_provenance()') self.check('schema',len(migrations)==21) q('CREATE ROLE d07_legacy LOGIN; GRANT USAGE ON SCHEMA public TO d07_legacy') diff --git a/coordinator-rs/tools/schema_census.py b/coordinator-rs/tools/schema_census.py index 25434097c..61ba3d7df 100644 --- a/coordinator-rs/tools/schema_census.py +++ b/coordinator-rs/tools/schema_census.py @@ -25,6 +25,10 @@ import psycopg2 ROOT = Path(__file__).resolve().parents[2] + +import runpy +apply_migration = runpy.run_path(str(ROOT / "server/bin/apply-test-migration.py"))["apply_migration"] + MIGRATIONS = ROOT / "server/postgres/migrations" CATALOG = ROOT / "coordinator-rs/src/schema/catalog.json" ROWS = ROOT / "coordinator-rs/src/schema/rows.rs" @@ -151,17 +155,17 @@ def main(): reviewed_types() files = migrations(args.through) conn = psycopg2.connect(args.url) - with conn, conn.cursor() as cur: + conn.autocommit = True + with conn.cursor() as cur: cur.execute("SELECT count(*) FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace " "WHERE n.nspname = 'public'") if cur.fetchone()[0]: raise SystemExit("census database is not empty") for path in files: - cur.execute(path.read_text()) + apply_migration(conn, path) cur.execute("SELECT version()") print(cur.fetchone()[0], file=sys.stderr) measured = measure(cur) - conn.rollback() conn.close() old = json.loads(CATALOG.read_text()) old_tables = {t["table"]: t for t in old["tables"]} diff --git a/delphi/tests/coordinator/conftest.py b/delphi/tests/coordinator/conftest.py index 87290eada..90e98dd60 100644 --- a/delphi/tests/coordinator/conftest.py +++ b/delphi/tests/coordinator/conftest.py @@ -81,6 +81,7 @@ def pytest_configure(config): ROOT = ROOT if ROOT is not None else _HERE.parents[2] + BINARY = ROOT / "coordinator-rs/target/fault/debug/polis-coordinator" REFERENCE = "aaaf7ca5c93f9a758b28e7a361c3b9544e24305a" WRITER_REF = "b3262008f" @@ -138,6 +139,8 @@ def connect(url): @pytest.fixture(scope="session") def template(): + import runpy + apply_migration = runpy.run_path(str(ROOT / "server/bin/apply-test-migration.py"))["apply_migration"] base = os.environ["POLIS_TEST_POSTGRES_URL"] name = "p026_template_" + uuid.uuid4().hex[:10] admin = connect(base) @@ -149,7 +152,7 @@ def template(): try: with c.cursor() as cur: for path in sorted((ROOT / "server/postgres/migrations").glob("*.sql")): - cur.execute(path.read_text()) + apply_migration(c, path) # Exercise the production drift named in CO04: ticks lacks this column. cur.execute("ALTER TABLE math_ticks DROP COLUMN caching_tick") # The production 000021 migration above supplies all ownership state; diff --git a/delphi/tests/poller/recovery/conftest.py b/delphi/tests/poller/recovery/conftest.py index c61d85b4c..b664cddc4 100644 --- a/delphi/tests/poller/recovery/conftest.py +++ b/delphi/tests/poller/recovery/conftest.py @@ -34,8 +34,9 @@ Nothing here hides the matrix from that job by policy — the skip is a statement about the image's contents, and it is one step away from being satisfied:: - docker compose ... cp server/postgres/migrations delphi:/app/migrations - ... exec -e POLIS_MIGRATIONS_DIR=/app/migrations delphi ... + docker compose ... cp server/postgres delphi:/app/postgres + ... exec -e POLIS_MIGRATIONS_DIR=/app/postgres/migrations \ + -e POLIS_MIGRATE_BIN=/usr/local/bin/polis-migrate delphi ... which makes the whole matrix run there (verified: 122 passed, 1 skipped — R11's docker-compose.yml assertion, still outside the image — and 12 xfailed). @@ -44,6 +45,9 @@ Schema freshness ---------------- +The packaged invocation also needs a polis-migrate binary built for the container +installed at POLIS_MIGRATE_BIN. In a source checkout the helper builds it with Cargo. + The migrations are applied ONCE per session into a template database; each test then gets its own database created with ``CREATE DATABASE ... TEMPLATE``. That is a genuinely fresh migrated schema per test (no cross-test residue in @@ -285,11 +289,13 @@ def migrated_template(recovery_migrations_dir: str, conn = psycopg2.connect(tmpl_url, connect_timeout=5) conn.autocommit = True try: + import runpy + from pathlib import Path + apply_migration = runpy.run_path(str( + Path(recovery_migrations_dir).parents[1] / "bin" / "apply-test-migration.py" + ))["apply_migration"] for name in files: - with open(os.path.join(recovery_migrations_dir, name), "r") as fh: - sql = fh.read() - with conn.cursor() as cur: - cur.execute(sql) + apply_migration(conn, Path(recovery_migrations_dir) / name) finally: conn.close() diff --git a/delphi/tests/projgate/projection_gate_test.py b/delphi/tests/projgate/projection_gate_test.py index 2d7e7c20a..990252579 100644 --- a/delphi/tests/projgate/projection_gate_test.py +++ b/delphi/tests/projgate/projection_gate_test.py @@ -120,19 +120,20 @@ def dsn() -> Iterator[str]: else: pytest.skip("postgres container did not become ready in time") - for path in migrations: - with open(path, "rb") as fh: - applied = subprocess.run( - [docker, "exec", "-i", cid, "psql", "-v", "ON_ERROR_STOP=1", - "-U", "postgres", "-d", "postgres"], - stdin=fh, capture_output=True, text=True, - ) - if applied.returncode != 0: - pytest.skip( - f"migration {os.path.basename(path)} failed to apply: " - f"{applied.stderr[-500:]}" - ) - url = f"postgresql://postgres:test@localhost:{port}/postgres" + import runpy + from pathlib import Path + import psycopg2 + apply_migration = runpy.run_path( + os.path.join(_server_dir, "bin", "apply-test-migration.py") + )["apply_migration"] + url = f"postgresql://postgres:test@127.0.0.1:{port}/postgres" + conn = psycopg2.connect(url) + conn.autocommit = True + try: + for path in migrations: + apply_migration(conn, Path(path)) + finally: + conn.close() _seed(url) yield url finally: diff --git a/docs/migrations.md b/docs/migrations.md index 1193571da..c6ca4fe40 100644 --- a/docs/migrations.md +++ b/docs/migrations.md @@ -90,8 +90,9 @@ the actual migrations (including role administration for the queue). A database advisory lock serializes runners on the same connection across per-file commits. A second runner waits up to five minutes, then reads the -committed history. Each ordinary file and its APPLIED row commit in one transaction. The two -000022 index builds are the explicit autocommit exception described below. +committed history. Each ordinary file and its APPLIED row commit in one transaction. +Concurrent index files and the two +000022 index builds are the explicit autocommit exceptions described below. An optional historical outer BEGIN/COMMIT pair is removed; any other top-level transaction control is rejected. Dollar-quoted function bodies stay intact. SQL errors abort the file. Earlier successfully committed files stay applied. @@ -124,6 +125,27 @@ If history recording fails after both builds, both valid indexes remain; retry records their checked state without rebuilding. Concurrent builds have the same bounded statement/lock timeouts; a timeout is not a success receipt. +### Concurrent index file header + +New files containing only concurrent index builds opt out of the ordinary file +transaction with `-- polis-migrate: concurrent-indexes` in the leading line-comment +header. The runner accepts only `CREATE INDEX CONCURRENTLY IF NOT EXISTS name ON +[public.]table (column, ...)` statements: simple lowercase identifiers, ordinary +btree columns, no expressions, predicates, options, transaction control or other +SQL. Each build is a separate autocommit statement, on the same connection under +the migration advisory lock. The runner restores the session's 5 s lock wait and +5 min statement and transaction budgets before the file, even if a previous file +changed them. These apply to each build; there is no aggregate file timeout. + +All named objects are checked before building any index. Exact valid definitions +are reused; a conflicting or invalid object refuses the file. As with 000022, +inspect a failed build, explicitly `DROP INDEX CONCURRENTLY public.` only +if it is the expected interrupted index, and rerun. `IF NOT EXISTS` alone would +silently accept an invalid index and is not the validity check. The runner never +drops an index automatically. After all builds, catalog validity is checked again +in the transaction that records APPLIED. A failed history write leaves the valid +indexes for the next run. Ordinary files retain atomic SQL/history semantics. + ## Release contents and new migrations `server/postgres/migrations/release.txt` explicitly selects every required file. @@ -266,3 +288,13 @@ predicate must lead to a reviewed forward repair or a documented compatible variant, never to manually inserting a migration row. Unknown historical variants remain review cases; this document does not authorize a deployment that fails reconciliation. Run the [read-only first-deploy report](migration-upgrade-notes.md) before the first transition; it does not replace application-health verification. + +Historical schema tests that intentionally replay an older inventory use +`polis-migrate prepare-indexes --file PATH` only for header-marked index files. +It shares the deployment parser, advisory lock, budgets, preflight and final +validity checks, but does not write migration history. The harness must commit +earlier DDL and release its transaction before invoking it. The Python helper +`server/bin/apply-test-migration.py` and Node helper +`server/characterization/migrations.cjs` enforce this boundary; both accept +`POLIS_MIGRATE_BIN` or build the locked runner with Cargo. Normal installations, +including database resets, continue to use `apply`/`deploy`. diff --git a/queue-rs/polis-migrate/src/indexes.rs b/queue-rs/polis-migrate/src/indexes.rs index f2127f0c9..6ba4a5dd4 100644 --- a/queue-rs/polis-migrate/src/indexes.rs +++ b/queue-rs/polis-migrate/src/indexes.rs @@ -1,4 +1,4 @@ -//! Resumable, autocommit execution for the immutable watermark index migration. +//! Resumable, autocommit execution for the concurrent index migrations. //! The caller holds the database-wide migration lock across every statement. use anyhow::{Context, Result, ensure}; use postgres::Client; @@ -8,7 +8,12 @@ const INDEXES: [(&str, &str, &str); 2] = [ ("comments_modified_idx", "comments", "modified"), ]; -fn state(client: &mut Client, name: &str, table: &str, column: &str) -> Result> { +fn state( + client: &mut impl postgres::GenericClient, + name: &str, + table: &str, + column: &str, +) -> Result> { let rows = client.query( "SELECT x.indisvalid AND x.indisready AND x.indislive AS usable, pg_get_indexdef(c.oid), c.relkind @@ -24,24 +29,32 @@ fn state(client: &mut Client, name: &str, table: &str, column: &str) -> Result = row.get(0); Ok(Some(usable == Some(true))) } pub fn prepare(client: &mut Client) -> Result<()> { - // Preflight BOTH identities before changing either one. A conflicting or + prepare_named(client, "000022", &INDEXES) +} + +fn prepare_named( + client: &mut Client, + migration: &str, + indexes: &[(&str, &str, &str)], +) -> Result<()> { + // Preflight all identities before changing any one. A conflicting or // invalid preexisting index is never dropped or replaced automatically. - for (name, table, column) in INDEXES { + for &(name, table, column) in indexes { if let Some(usable) = state(client, name, table, column)? { ensure!( usable, - "000022: public.{name} is invalid/not ready; inspect the interrupted build, then explicitly DROP INDEX CONCURRENTLY public.{name} before retrying apply; history has not recorded 000022" + "{migration}: public.{name} is invalid/not ready; inspect the interrupted build, then explicitly DROP INDEX CONCURRENTLY public.{name} before retrying apply; history has not recorded {migration}" ); } } - for (name, table, column) in INDEXES { + for &(name, table, column) in indexes { // Recheck after the preceding build. Uncoordinated external DDL is not // serialized by the runner's advisory lock; any collision fails closed. if state(client, name, table, column)? == Some(true) { @@ -49,18 +62,217 @@ pub fn prepare(client: &mut Client) -> Result<()> { } ensure!( state(client, name, table, column)?.is_none(), - "000022: concurrent catalog change for public.{name}; inspect before retrying" + "{migration}: concurrent catalog change for public.{name}; inspect before retrying" ); println!("BUILDING CONCURRENTLY public.{name}"); client.batch_execute(&format!( "CREATE INDEX CONCURRENTLY {name} ON public.{table} USING btree ({column})" )).with_context(|| format!( - "000022: concurrent build interrupted for public.{name}; inspect validity before retrying; valid earlier indexes are retained and no 000022 history row was committed" + "{migration}: concurrent build interrupted for public.{name}; inspect validity before retrying; valid earlier indexes are retained and no {migration} history row was committed" ))?; ensure!( state(client, name, table, column)? == Some(true), - "000022: index public.{name} did not reach the expected valid state" + "{migration}: index public.{name} did not reach the expected valid state" ); } Ok(()) } + +/// Deliberately narrow opt-out: only plain public btree indexes, no arbitrary SQL. +#[derive(Debug)] +pub struct ConcurrentIndexes(Vec<(String, String, String)>); + +impl ConcurrentIndexes { + pub fn parse(source: &str) -> Result> { + const MARKER: &str = "-- polis-migrate: concurrent-indexes"; + let header = source + .lines() + .take_while(|line| line.trim().is_empty() || line.trim_start().starts_with("--")); + if !header.into_iter().any(|line| line.trim() == MARKER) { + return Ok(None); + } + let mut indexes = Vec::new(); + let mut names = std::collections::BTreeSet::new(); + for statement in crate::sql::statements(source)? { + let normalized = statement + .replace('(', " ( ") + .replace(')', " ) ") + .replace(',', " , "); + let words: Vec<_> = normalized.split_whitespace().collect(); + ensure!( + words.len() >= 11 + && words[..6] + .iter() + .zip(["CREATE", "INDEX", "CONCURRENTLY", "IF", "NOT", "EXISTS"]) + .all(|(a, b)| a.eq_ignore_ascii_case(b)) + && words[7].eq_ignore_ascii_case("ON") + && words[9] == "(" + && words.last() == Some(&")"), + "concurrent-indexes accepts only CREATE INDEX CONCURRENTLY IF NOT EXISTS name ON [public.]table (columns)" + ); + let ident = |s: &str| { + !s.is_empty() + && s.len() <= 63 + && s.bytes().enumerate().all(|(i, b)| { + b.is_ascii_lowercase() || b == b'_' || (i > 0 && b.is_ascii_digit()) + }) + }; + let name = words[6]; + let table = words[8].strip_prefix("public.").unwrap_or(words[8]); + let columns = &words[10..words.len() - 1]; + ensure!( + ident(name) + && ident(table) + && !columns.is_empty() + && columns.len() % 2 == 1 + && columns.iter().enumerate().all(|(i, s)| if i % 2 == 0 { + ident(s) + } else { + *s == "," + }), + "concurrent-indexes requires simple lowercase identifiers and column lists" + ); + ensure!( + names.insert(name.to_owned()), + "duplicate concurrent index name: {name}" + ); + indexes.push(( + name.to_owned(), + table.to_owned(), + columns + .iter() + .step_by(2) + .copied() + .collect::>() + .join(", "), + )); + } + ensure!(!indexes.is_empty(), "empty concurrent-indexes migration"); + Ok(Some(Self(indexes))) + } + + pub fn prepare(&self, client: &mut Client, migration: &str) -> Result<()> { + let indexes: Vec<_> = self + .0 + .iter() + .map(|(n, t, c)| (n.as_str(), t.as_str(), c.as_str())) + .collect(); + prepare_named(client, migration, &indexes) + } + + pub fn verify(&self, client: &mut impl postgres::GenericClient) -> Result<()> { + for (name, table, columns) in &self.0 { + ensure!( + state(client, name, table, columns)? == Some(true), + "concurrent index public.{name} is missing or invalid before recording history" + ); + } + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn assert_refused(source: &str) { + let result = + ConcurrentIndexes::parse(&format!("-- polis-migrate: concurrent-indexes\n{source}")); + assert!( + matches!(&result, Err(error) if error.to_string().contains("concurrent-indexes")), + "{source}: {result:?}" + ); + } + + #[test] + fn refuses_predicate() { + assert_refused( + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid) WHERE zid IS NOT NULL;", + ); + } + + #[test] + fn refuses_storage_options() { + assert_refused( + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid) WITH (fillfactor = 70);", + ); + } + + #[test] + fn refuses_include() { + assert_refused( + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid) INCLUDE (created);", + ); + } + + #[test] + fn refuses_tablespace() { + assert_refused( + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid) TABLESPACE pg_default;", + ); + } + + #[test] + fn refuses_explicit_access_method() { + assert_refused( + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example USING btree (zid);", + ); + } + + #[test] + fn refuses_standalone_commit() { + assert_refused("COMMIT;"); + } + + #[test] + fn refuses_outer_transaction_wrapper() { + assert_refused( + "BEGIN; CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid); COMMIT;", + ); + } + + #[test] + fn refuses_missing_concurrently() { + assert_refused("CREATE INDEX IF NOT EXISTS example_idx ON example (zid);"); + } + + #[test] + fn refuses_missing_if_not_exists() { + assert_refused("CREATE INDEX CONCURRENTLY example_idx ON example (zid);"); + } + + #[test] + fn refuses_uppercase_identifier() { + assert_refused("CREATE INDEX CONCURRENTLY IF NOT EXISTS Example_idx ON example (zid);"); + } + + #[test] + fn refuses_quoted_identifier() { + assert_refused("CREATE INDEX CONCURRENTLY IF NOT EXISTS \"example_idx\" ON example (zid);"); + } + + #[test] + fn narrow_header_contract() -> Result<()> { + let header = "-- file.sql\n-- polis-migrate: concurrent-indexes\n"; + let statement = + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON public.example (zid, created);"; + assert!(ConcurrentIndexes::parse(statement)?.is_none()); + assert!(ConcurrentIndexes::parse(&format!("{header}{statement}"))?.is_some()); + for invalid in [ + "BEGIN;", + "DROP INDEX example_idx;", + "SELECT 1;", + "CREATE INDEX example_idx ON example (zid);", + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON other.example (zid);", + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (lower(zid));", + "CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid DESC);", + ] { + assert!( + ConcurrentIndexes::parse(&format!("{header}{invalid}")).is_err(), + "{invalid}" + ); + } + assert!(ConcurrentIndexes::parse(&format!("{header}{statement}{statement}")).is_err()); + Ok(()) + } +} diff --git a/queue-rs/polis-migrate/src/lib.rs b/queue-rs/polis-migrate/src/lib.rs index b9d13157c..152ccad6d 100644 --- a/queue-rs/polis-migrate/src/lib.rs +++ b/queue-rs/polis-migrate/src/lib.rs @@ -17,6 +17,7 @@ pub struct Migration { pub checksum: String, pub body: String, pub retired: bool, + concurrent_indexes: Option, /// This release's forward-compatibility declaration (compat.txt), if any. pub compat: Option, } @@ -79,6 +80,7 @@ pub fn load(dir: &Path) -> Result { name: name.clone(), checksum: format!("{:x}", Sha256::digest(source.as_bytes())), body: sql::body(&source)?, + concurrent_indexes: indexes::ConcurrentIndexes::parse(&source)?, retired: matches!(&name[..6], "000004" | "000005" | "000007"), compat: None, }, @@ -397,6 +399,20 @@ pub fn apply(client: &mut Client, release: &Release) -> Result { Ok(count) } +/// Historical schema harnesses retain their own migration inventory and session. +/// Prepare only a header-marked file, using the deployment parser, lock, budgets +/// and catalog checks. This does not create or adopt migration history. +pub fn prepare_indexes(dsn: &str, source: &str) -> Result<()> { + let indexes = indexes::ConcurrentIndexes::parse(source)? + .ok_or_else(|| anyhow::anyhow!("prepare-indexes requires the concurrent-indexes header"))?; + let mut client = connect(dsn)?; + lock(&mut client)?; + indexes.prepare(&mut client, "concurrent-indexes")?; + indexes.verify(&mut client)?; + client.query_one("SELECT pg_advisory_unlock($1)", &[&LOCK])?; + Ok(()) +} + fn apply_locked(client: &mut Client, release: &Release) -> Result { let migrations = &release.migrations; // Validate history and every pending retirement before CREATE HISTORY or @@ -464,6 +480,11 @@ fn apply_locked(client: &mut Client, release: &Release) -> Result { ); indexes::prepare(client)?; } + if let Some(indexes) = &m.concurrent_indexes { + // Restore budgets if an earlier file changed session settings. + setup(client)?; + indexes.prepare(client, &m.name)?; + } let mut tx = client.transaction()?; tx.batch_execute("SET LOCAL standard_conforming_strings=on; SET LOCAL search_path=public,pg_catalog; SET LOCAL lock_timeout='5s'; SET LOCAL statement_timeout='5min'; SET LOCAL transaction_timeout='5min';")?; let status = if m.retired { @@ -473,6 +494,9 @@ fn apply_locked(client: &mut Client, release: &Release) -> Result { m.name ); "ADOPTED" + } else if let Some(indexes) = &m.concurrent_indexes { + indexes.verify(&mut tx)?; + "APPLIED" } else { tx.batch_execute(&m.body).with_context(|| { format!("migration {} failed (transaction not committed)", m.name) diff --git a/queue-rs/polis-migrate/src/main.rs b/queue-rs/polis-migrate/src/main.rs index 79ad7c638..dd348852a 100644 --- a/queue-rs/polis-migrate/src/main.rs +++ b/queue-rs/polis-migrate/src/main.rs @@ -5,7 +5,7 @@ fn run() -> Result<()> { let command = args.next().unwrap_or_default(); if matches!(command.as_str(), "--help" | "-h") { println!( - "polis-migrate deploy|apply|check|reconcile [--dir PATH] [--through NNNNNN]\nDATABASE_URL is read from the environment; reconcile requires --through. See docs/migrations.md." + "polis-migrate deploy|apply|check|reconcile [--dir PATH] [--through NNNNNN]\npolis-migrate prepare-indexes --file PATH (historical schema tests only)\nDATABASE_URL is read from the environment; reconcile requires --through. See docs/migrations.md." ); return Ok(()); } @@ -13,8 +13,15 @@ fn run() -> Result<()> { env::var("POLIS_MIGRATIONS_DIR").unwrap_or_else(|_| "server/postgres/migrations".into()), ); let mut through = None; + let mut file = None; while let Some(arg) = args.next() { match arg.as_str() { + "--file" => { + file = Some(PathBuf::from( + args.next() + .ok_or_else(|| anyhow::anyhow!("--file needs a path"))?, + )); + } "--dir" => { dir = args .next() @@ -30,6 +37,19 @@ fn run() -> Result<()> { _ => bail!("unknown argument: {arg}"), } } + if command == "prepare-indexes" { + if through.is_some() { + bail!("prepare-indexes does not accept --through"); + } + let file = file.ok_or_else(|| anyhow::anyhow!("prepare-indexes requires --file"))?; + let source = std::fs::read_to_string(&file)?; + let dsn = + env::var("DATABASE_URL").map_err(|_| anyhow::anyhow!("DATABASE_URL is required"))?; + return polis_migrate::prepare_indexes(&dsn, &source); + } + if file.is_some() { + bail!("--file is only for prepare-indexes"); + } if !matches!(command.as_str(), "deploy" | "apply" | "check" | "reconcile") { bail!("expected deploy, apply, check or reconcile (see --help)"); } diff --git a/queue-rs/polis-migrate/tests/fixtures/concurrent-indexes.sql b/queue-rs/polis-migrate/tests/fixtures/concurrent-indexes.sql new file mode 100644 index 000000000..b69d9c698 --- /dev/null +++ b/queue-rs/polis-migrate/tests/fixtures/concurrent-indexes.sql @@ -0,0 +1,4 @@ +-- polis-migrate: concurrent-indexes +CREATE INDEX CONCURRENTLY IF NOT EXISTS votes_zid_created_idx ON votes (zid, created); +CREATE INDEX CONCURRENTLY IF NOT EXISTS comments_zid_created_idx ON comments (zid, created); +CREATE INDEX CONCURRENTLY IF NOT EXISTS comments_zid_modified_idx ON comments (zid, modified); diff --git a/queue-rs/polis-migrate/tests/forward.py b/queue-rs/polis-migrate/tests/forward.py index 051da8d6a..337acd7d7 100644 --- a/queue-rs/polis-migrate/tests/forward.py +++ b/queue-rs/polis-migrate/tests/forward.py @@ -58,7 +58,7 @@ def test_03_rollback_past_additive_migrations_starts(self): self.assertIn('applied 0 migration(s)', out) for name in newer: self.assertIn(f'tolerating {name}', out) - self.assertIn('8 newer additive migration(s) tolerated', p.runner(db, 'check', dir=old).stdout) + self.assertIn(f'{len(newer)} newer additive migration(s) tolerated', p.runner(db, 'check', dir=old).stdout) gate = p.gate(db, True, dir=old) self.assertIn('tolerating 000030_create_delphi_writers.sql', gate.stdout) self.assertEqual(before, history(db)) diff --git a/queue-rs/polis-migrate/tests/indexes.py b/queue-rs/polis-migrate/tests/indexes.py index 657ffd666..6fb5b48a1 100644 --- a/queue-rs/polis-migrate/tests/indexes.py +++ b/queue-rs/polis-migrate/tests/indexes.py @@ -81,4 +81,124 @@ def test_06_invalid_build_refusal_explicit_recovery(self): self.assertEqual(p.sql(db,"SELECT count(*) FROM migrations WHERE name LIKE '000022%'"),'0') p.sql(db,'DROP INDEX CONCURRENTLY public.comments_modified_idx') self.runnew(db,'apply');self.runnew(db,'check') + +class ActivityIndexProof(unittest.TestCase): + def setUp(self): + self.tmp=tempfile.TemporaryDirectory();self.addCleanup(self.tmp.cleanup);self.d=pathlib.Path(self.tmp.name) + self.name='000043_add_conversation_activity_indexes.sql' + (self.d/'held.txt').write_text('') + (self.d/'000000_initial.sql').write_text('CREATE TABLE votes(zid integer, created bigint); CREATE TABLE comments(zid integer, created bigint, modified bigint);') + self.db='activity_'+self._testMethodName + p.sql('postgres',f'CREATE DATABASE {self.db}') + self.runnew('apply') + shutil.copy(pathlib.Path(__file__).with_name('fixtures')/'concurrent-indexes.sql',self.d/self.name) + def runnew(self,*args,**kw): + (self.d/'release.txt').write_text(''.join(f.name+'\n' for f in sorted(self.d.glob('*.sql')))) + return p.runner(self.db,*args,dir=self.d,**kw) + def valid(self): + return p.sql(self.db,"SELECT count(*) FROM pg_index WHERE indisvalid AND indisready AND indislive AND indexrelid IN (to_regclass('votes_zid_created_idx'),to_regclass('comments_zid_created_idx'),to_regclass('comments_zid_modified_idx'))") + def test_fresh_and_repeat(self): + self.runnew('apply');self.runnew('check');self.assertEqual(self.valid(),'3') + self.assertIn('applied 0 migration(s)',self.runnew('apply').stdout) + def test_prepare_indexes_without_history(self): + p.sql(self.db,'DROP TABLE migrations') + result=self.runnew('prepare-indexes','--file',str(self.d/self.name)) + self.assertIn('BUILDING CONCURRENTLY',result.stdout);self.assertEqual(self.valid(),'3') + before=p.sql(self.db,"SELECT indexrelid FROM pg_index ORDER BY indexrelid") + self.runnew('prepare-indexes','--file',str(self.d/self.name)) + self.assertEqual(before,p.sql(self.db,"SELECT indexrelid FROM pg_index ORDER BY indexrelid")) + self.assertEqual(p.sql(self.db,"SELECT to_regclass('migrations') IS NULL"),'t') + def test_prepare_indexes_refuses_conflict(self): + p.sql(self.db,'CREATE INDEX comments_zid_modified_idx ON comments(created)') + result=self.runnew('prepare-indexes','--file',str(self.d/self.name),ok=False) + self.assertIn('conflicting object',result.stderr) + self.assertEqual(p.sql(self.db,"SELECT to_regclass('votes_zid_created_idx') IS NULL"),'t') + def test_prepare_indexes_requires_header(self): + (self.d/self.name).write_text('CREATE TABLE forbidden(id int);') + result=self.runnew('prepare-indexes','--file',str(self.d/self.name),ok=False) + self.assertIn('requires the concurrent-indexes header',result.stderr) + self.assertEqual(p.sql(self.db,"SELECT to_regclass('forbidden') IS NULL"),'t') + def test_session_budgets_restored(self): + (self.d/'000001_session_settings.sql').write_text("SET statement_timeout='1s'; SET lock_timeout='1ms'; SET transaction_timeout='2min';") + p.sql(self.db,"CREATE FUNCTION check_build_budget() RETURNS event_trigger LANGUAGE plpgsql AS $$ BEGIN IF current_setting('statement_timeout') <> '5min' OR current_setting('lock_timeout') <> '5s' OR current_setting('transaction_timeout') <> '5min' THEN RAISE EXCEPTION 'concurrent build budgets were not restored'; END IF; END $$; CREATE EVENT TRIGGER check_build_budget ON ddl_command_start WHEN TAG IN ('CREATE INDEX') EXECUTE FUNCTION check_build_budget();") + self.runnew('apply');self.assertEqual(self.valid(),'3') + def test_all_identities_preflight(self): + p.sql(self.db,'CREATE INDEX comments_zid_modified_idx ON comments(created)') + self.assertIn('conflicting object',self.runnew('apply',ok=False).stderr) + self.assertEqual(p.sql(self.db,"SELECT to_regclass('votes_zid_created_idx') IS NULL"),'t') + def test_history_failure_keeps_valid_builds(self): + p.sql(self.db,"CREATE FUNCTION refuse_record() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'generated history fault'; END $$; CREATE TRIGGER refuse_record BEFORE INSERT ON migrations FOR EACH ROW EXECUTE FUNCTION refuse_record();") + self.runnew('apply',ok=False);self.assertEqual(self.valid(),'3') + before=p.sql(self.db,"SELECT indexrelid FROM pg_index WHERE indrelid IN ('votes'::regclass,'comments'::regclass) ORDER BY indexrelid") + p.sql(self.db,'DROP TRIGGER refuse_record ON migrations');self.runnew('apply') + self.assertEqual(before,p.sql(self.db,"SELECT indexrelid FROM pg_index WHERE indrelid IN ('votes'::regclass,'comments'::regclass) ORDER BY indexrelid")) + def test_cancel_refuse_recover_with_writer(self): + # Plain generated rows have no vote value or semantic interpretation. + holder=subprocess.Popen(p.COMPOSE+['exec','-T','postgres','psql','-X','-U','postgres','-d',self.db,'-Atq'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True) + holder.stdin.write("BEGIN; INSERT INTO votes VALUES(1,1); SELECT 'held';\n");holder.stdin.flush() + self.assertEqual(holder.stdout.readline().strip(),'held') + (self.d/'release.txt').write_text('000000_initial.sql\n'+self.name+'\n') + runner=subprocess.Popen([str(p.BIN),'apply','--dir',str(self.d)],env=p.env(self.db),stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True) + try: + deadline=time.monotonic()+15 + while p.sql(self.db,"SELECT EXISTS(SELECT 1 FROM pg_index WHERE indexrelid=to_regclass('votes_zid_created_idx') AND NOT indisvalid)")!='t': + self.assertLess(time.monotonic(),deadline);time.sleep(.05) + p.sql(self.db,"SET lock_timeout='1s'; INSERT INTO votes VALUES(2,2)") + self.assertIn('t',p.sql(self.db,"SELECT pg_cancel_backend(pid) FROM pg_stat_activity WHERE datname=current_database() AND application_name='polis-migrate' AND query LIKE 'CREATE INDEX CONCURRENTLY%';")) + runner.communicate(timeout=30);self.assertNotEqual(runner.returncode,0) + finally: + holder.stdin.write('COMMIT;\n\\q\n');holder.stdin.flush();holder.communicate(timeout=15) + if runner.poll() is None:runner.terminate();runner.communicate(timeout=15) + self.assertIn('invalid/not ready',self.runnew('apply',ok=False).stderr) + self.assertEqual(p.sql(self.db,"SELECT count(*) FROM migrations WHERE name LIKE '000043%'"),'0') + self.assertEqual(p.sql(self.db,"SELECT to_regclass('comments_zid_created_idx') IS NULL"),'t') + p.sql(self.db,'DROP INDEX CONCURRENTLY public.votes_zid_created_idx') + self.runnew('apply');self.runnew('check');self.assertEqual(self.valid(),'3') + +class HeaderRefusalProof(unittest.TestCase): + def assert_refused_without_execution(self,statement,wrapped=False): + db='header_'+self._testMethodName + p.sql('postgres',f'CREATE DATABASE {db}') + p.sql(db,'CREATE TABLE example(zid integer, created bigint); CREATE SEQUENCE execution_probe;') + with tempfile.TemporaryDirectory() as tmp: + directory=pathlib.Path(tmp) + (directory/'held.txt').write_text('') + # Sequence advances survive rollback, so an unchanged probe proves the + # earlier selected migration never executed, even if a transaction failed. + (directory/'000000_initial.sql').write_text("SELECT nextval('execution_probe');") + valid='CREATE INDEX CONCURRENTLY IF NOT EXISTS earlier_idx ON example (created);\n' + source=statement if wrapped else valid+statement + (directory/'000001_indexes.sql').write_text('-- polis-migrate: concurrent-indexes\n'+source) + (directory/'release.txt').write_text('000000_initial.sql\n000001_indexes.sql\n') + result=p.runner(db,'apply',dir=directory,ok=False) + self.assertRegex(result.stderr,'concurrent-indexes|transaction control') + self.assertNotIn('BUILDING CONCURRENTLY',result.stdout) + self.assertNotIn('APPLIED ',result.stdout) + self.assertEqual(p.sql(db,'SELECT is_called FROM execution_probe'),'f') + self.assertEqual(p.sql(db,"SELECT to_regclass('public.migrations') IS NULL"),'t') + self.assertEqual(p.sql(db,"SELECT count(*) FROM pg_index WHERE indrelid='public.example'::regclass"),'0') + + def test_predicate(self): + self.assert_refused_without_execution('CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid) WHERE zid IS NOT NULL;') + def test_storage_options(self): + self.assert_refused_without_execution('CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid) WITH (fillfactor = 70);') + def test_include(self): + self.assert_refused_without_execution('CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid) INCLUDE (created);') + def test_tablespace(self): + self.assert_refused_without_execution('CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid) TABLESPACE pg_default;') + def test_explicit_access_method(self): + self.assert_refused_without_execution('CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example USING btree (zid);') + def test_standalone_commit(self): + self.assert_refused_without_execution('COMMIT;') + def test_outer_transaction_wrapper(self): + self.assert_refused_without_execution('BEGIN; CREATE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON example (zid); COMMIT;',wrapped=True) + def test_missing_concurrently(self): + self.assert_refused_without_execution('CREATE INDEX IF NOT EXISTS example_idx ON example (zid);') + def test_missing_if_not_exists(self): + self.assert_refused_without_execution('CREATE INDEX CONCURRENTLY example_idx ON example (zid);') + def test_uppercase_identifier(self): + self.assert_refused_without_execution('CREATE INDEX CONCURRENTLY IF NOT EXISTS Example_idx ON example (zid);') + def test_quoted_identifier(self): + self.assert_refused_without_execution('CREATE INDEX CONCURRENTLY IF NOT EXISTS "example_idx" ON example (zid);') + if __name__=='__main__':unittest.main(verbosity=2) diff --git a/server/bin/apply-test-migration.py b/server/bin/apply-test-migration.py new file mode 100644 index 000000000..b7a405d75 --- /dev/null +++ b/server/bin/apply-test-migration.py @@ -0,0 +1,41 @@ +"""Apply a historical harness migration without changing its SQL or inventory. + +Header-marked files delegate to the deployment runner's concurrent-index parser +and verifier. The caller must commit earlier work and use an autocommit session; +otherwise a separate builder could wait on the caller's transaction forever. +""" +import os +from pathlib import Path +import subprocess + +ROOT = Path(__file__).resolve().parents[2] +MARKER = "-- polis-migrate: concurrent-indexes" + + +def apply_migration(connection, path, *, ca_file=None): + source = path.read_text() + if not connection.autocommit or connection.get_transaction_status() != 0: + raise ValueError("migration harness requires an idle autocommit connection") + header = [] + for line in source.splitlines(): + if line.strip() and not line.lstrip().startswith("--"): + break + header.append(line.strip()) + if MARKER in header: + from psycopg2.extensions import make_dsn + # connection.dsn omits the password. Forward it only in the child + # environment, preserving the transport of the admitted connection. + dsn = make_dsn(connection.dsn, password=connection.info.password, + sslmode="require" if connection.info.ssl_in_use else "disable") + environment = dict(os.environ, DATABASE_URL=dsn) + if ca_file: + environment["POLIS_MIGRATE_CA_FILE"] = str(ca_file) + runner = os.environ.get("POLIS_MIGRATE_BIN") + command = [runner] if runner else [ + "cargo", "run", "--quiet", "--locked", "-p", "polis-migrate", "--"] + subprocess.run(command + ["prepare-indexes", "--file", str(path.resolve())], + cwd=None if runner else ROOT / "queue-rs", check=True, + env=environment) + else: + with connection.cursor() as cursor: + cursor.execute(source) diff --git a/server/bin/db-reset.js b/server/bin/db-reset.js index 7877a9c48..2d375708c 100644 --- a/server/bin/db-reset.js +++ b/server/bin/db-reset.js @@ -12,8 +12,7 @@ * Make sure your DATABASE_URL points to a test/development database. */ -import { exec } from 'child_process'; -import fs from 'fs'; +import { execFile } from 'child_process'; import path from 'path'; import { fileURLToPath } from 'url'; import { promisify } from 'util'; @@ -23,7 +22,7 @@ import pg from 'pg'; // Setup dirname for ES modules const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const execAsync = promisify(exec); +const execFileAsync = promisify(execFile); // Load environment variables dotenv.config(); @@ -124,33 +123,15 @@ async function resetDatabase() { // Close connection to postgres database await client.end(); - // Get list of migration files + // Use the same release selection, history and concurrent-index contract as deploy. const migrationsDir = path.join(__dirname, '..', 'postgres', 'migrations'); - const migrationFiles = fs - .readdirSync(migrationsDir) - .filter((file) => file.endsWith('.sql')) - .filter((file) => !file.includes('archived')) - .sort(); - - // Apply each migration - console.log('🔄 Applying migrations...'); - - for (const migrationFile of migrationFiles) { - console.log(` ➡️ Applying ${migrationFile}...`); - const migrationPath = path.join(migrationsDir, migrationFile); - - // Use psql to apply the migration - const { stdout: _stdout, stderr } = await execAsync( - `PGPASSWORD="${dbConfig.password}" psql -h ${dbConfig.host} -p ${dbConfig.port} -U ${dbConfig.username} -d ${dbConfig.database} -f "${migrationPath}"` - ); - - if (stderr && !stderr.includes('NOTICE')) { - console.warn(` ⚠️ Warnings: ${stderr}`); - } - } - - console.log('\x1b[32m%s\x1b[0m', '✅ Database reset complete!'); - console.log(`📁 Applied ${migrationFiles.length} migrations`); + const { stdout, stderr } = await execFileAsync( + process.env.POLIS_MIGRATE_BIN || 'polis-migrate', ['apply', '--dir', migrationsDir], + { env: { ...process.env, DATABASE_URL: databaseUrl } } + ); + process.stdout.write(stdout); + process.stderr.write(stderr); + console.log('Database reset complete!'); console.log('\x1b[32m%s\x1b[0m', '✨ Your database is fresh and ready to use!'); } catch (error) { console.error('\x1b[31m%s\x1b[0m', '❌ Error resetting database:'); diff --git a/server/characterization/Dockerfile b/server/characterization/Dockerfile new file mode 100644 index 000000000..3e33aa0be --- /dev/null +++ b/server/characterization/Dockerfile @@ -0,0 +1,9 @@ +FROM rust:1.98.1-bookworm AS migrate-build +WORKDIR /src +COPY queue-rs/ . +RUN cargo build --locked --release -p polis-migrate + +FROM node:22-bookworm-slim +RUN apt-get update && apt-get install -y --no-install-recommends libssl3 ca-certificates && rm -rf /var/lib/apt/lists/* +COPY --from=migrate-build /src/target/release/polis-migrate /usr/local/bin/polis-migrate +ENV POLIS_MIGRATE_BIN=/usr/local/bin/polis-migrate diff --git a/server/characterization/Dockerfile.dockerignore b/server/characterization/Dockerfile.dockerignore new file mode 100644 index 000000000..8b1bb7de1 --- /dev/null +++ b/server/characterization/Dockerfile.dockerignore @@ -0,0 +1,5 @@ +** +!queue-rs/ +!queue-rs/** +queue-rs/target/ +queue-rs/**/target/ diff --git a/server/characterization/collective-statement/main.cjs b/server/characterization/collective-statement/main.cjs index a22bc57ab..b3b3e50e5 100644 --- a/server/characterization/collective-statement/main.cjs +++ b/server/characterization/collective-statement/main.cjs @@ -197,7 +197,7 @@ async function setupPostgres() { .filter((f) => f.endsWith(".sql")) .sort(); for (const f of files) - await db.query(fs.readFileSync(path.join(dir, f), "utf8")); + await require("../migrations.cjs").applyMigration(db, path.join(dir, f), pgApp.toString()); // The shape the recordings stand on, read after the migrations and before // the fixture (which replaces now_as_millis() and adds rows, not shape). const schema = await readSchema((sql, params) => db.query(sql, params)); diff --git a/server/characterization/collective-statement/mutations.cjs b/server/characterization/collective-statement/mutations.cjs index 5f9377dc1..8061703f4 100644 --- a/server/characterization/collective-statement/mutations.cjs +++ b/server/characterization/collective-statement/mutations.cjs @@ -54,6 +54,7 @@ function scratchCopy() { path.join(dest, "node_modules") ); fs.symlinkSync(path.join(ROOT, "delphi"), path.join(root, "delphi")); + fs.symlinkSync(path.join(ROOT, "queue-rs"), path.join(root, "queue-rs")); return { root, dest }; } diff --git a/server/characterization/collective-statement/schema.test.cjs b/server/characterization/collective-statement/schema.test.cjs index 9c7459a18..a2367b341 100644 --- a/server/characterization/collective-statement/schema.test.cjs +++ b/server/characterization/collective-statement/schema.test.cjs @@ -272,7 +272,7 @@ test( .readdirSync(dir) .filter((f) => f.endsWith(".sql")) .sort()) - await db.query(fs.readFileSync(path.join(dir, f), "utf8")); + await require("../migrations.cjs").applyMigration(db, path.join(dir, f), appUrl.toString()); const query = (sql, params) => db.query(sql, params); const recorded = await readSchema(query); assert.equal(recorded.relations.votes_latest_unique.kind, "table"); diff --git a/server/characterization/delphi/compose.yml b/server/characterization/delphi/compose.yml index df4ee118f..3c4b65352 100644 --- a/server/characterization/delphi/compose.yml +++ b/server/characterization/delphi/compose.yml @@ -24,13 +24,16 @@ services: command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-inMemory"] ports: ["127.0.0.1:${P2ZERO_DYNAMO_PORT:?set a free DynamoDB port}:8000"] server: - image: node:22-bookworm-slim + build: + context: ../../.. + dockerfile: server/characterization/Dockerfile working_dir: /repo/server volumes: - ../../..:/repo - node_modules:/repo/server/node_modules environment: P2ZERO_PG_ADMIN_URL: postgres://postgres:generatedlocal@postgres:5432/postgres + POLIS_MIGRATE_ALLOW_PLAINTEXT: local DYNAMODB_ENDPOINT: http://dynamodb:8000 TZ: UTC command: diff --git a/server/characterization/delphi/main.cjs b/server/characterization/delphi/main.cjs index 75e27d855..ca782b9d8 100644 --- a/server/characterization/delphi/main.cjs +++ b/server/characterization/delphi/main.cjs @@ -131,7 +131,7 @@ async function setupPostgres() { .filter((f) => f.endsWith(".sql")) .sort(); for (const f of files) - await db.query(fs.readFileSync(path.join(dir, f), "utf8")); + await require("../migrations.cjs").applyMigration(db, path.join(dir, f), pgApp.toString()); await db.query(fs.readFileSync(path.join(FIXTURES, "postgres.sql"), "utf8")); await db.end(); return files.length; diff --git a/server/characterization/migrations.cjs b/server/characterization/migrations.cjs new file mode 100644 index 000000000..b1264ddce --- /dev/null +++ b/server/characterization/migrations.cjs @@ -0,0 +1,33 @@ +"use strict"; +// Historical replays retain all their original files and connection-local +// helpers. Only marked index files delegate to the deployment runner. +const fs = require("node:fs"); +const path = require("node:path"); +const { execFileSync } = require("node:child_process"); +const root = path.resolve(__dirname, "../.."); + +async function applyMigration(db, file, connectionString) { + const source = fs.readFileSync(file, "utf8"); + const header = []; + for (const line of source.split(/\r?\n/)) { + if (line.trim() && !line.trimStart().startsWith("--")) break; + header.push(line.trim()); + } + if (!header.includes("-- polis-migrate: concurrent-indexes")) { + await db.query(source); + return; + } + // The caller must not retain a snapshot or uncommitted DDL while the + // runner builds from another connection. Check the server's transaction. + const { rows } = await db.query("SELECT xact_start = query_start AS idle FROM pg_stat_activity WHERE pid=pg_backend_pid()"); + if (rows[0]?.idle !== true) throw new Error("migration harness requires autocommit"); + const runner = process.env.POLIS_MIGRATE_BIN; + const url = new URL(connectionString); + if (!db.connectionParameters.ssl) url.searchParams.set("sslmode", "disable"); + execFileSync(runner || "cargo", [ + ...(runner ? [] : ["run", "--quiet", "--locked", "-p", "polis-migrate", "--"]), + "prepare-indexes", "--file", path.resolve(file), + ], { cwd: runner ? root : path.join(root, "queue-rs"), stdio: "inherit", + env: { ...process.env, DATABASE_URL: url.toString() } }); +} +module.exports = { applyMigration }; From 202866cb34eaa84b72019ff0700544adb6492a2e Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Wed, 21 Oct 2026 00:09:26 -0700 Subject: [PATCH 17/30] migrations: three indexes for the derived conversation activity reads, built concurrently (#3243) Adds votes(zid, created), comments(zid, created) and comments(zid, modified) under the concurrent-indexes header so the activity time derived at read is an index probe instead of a scan of the conversation's votes. Selected for the next deploy; declared additive; listed in the deploy report and the upgrade notes. Co-authored-by: Claude Fable 5.1 --- coordinator-rs/src/schema/catalog.json | 19 ++++++++++++++++++ docs/migration-upgrade-notes.md | 20 ++++++++++++++++--- docs/migrations.md | 15 ++++++++++++-- queue-rs/polis-migrate/tests/forward.py | 3 ++- server/bin/build-migration-report.py | 14 ++----------- ...0043_add_conversation_activity_indexes.sql | 13 ++++++++++++ server/postgres/migrations/compat.txt | 1 + server/postgres/migrations/release.txt | 1 + .../migrations/report/first-deploy.sql | 15 +++----------- 9 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 server/postgres/migrations/000043_add_conversation_activity_indexes.sql diff --git a/coordinator-rs/src/schema/catalog.json b/coordinator-rs/src/schema/catalog.json index d44919b09..08661fdf4 100644 --- a/coordinator-rs/src/schema/catalog.json +++ b/coordinator-rs/src/schema/catalog.json @@ -619,11 +619,21 @@ "name": "comments_modified_idx", "definition": "CREATE INDEX comments_modified_idx ON public.comments USING btree (modified)" }, + { + "table": "comments", + "name": "comments_zid_created_idx", + "definition": "CREATE INDEX comments_zid_created_idx ON public.comments USING btree (zid, created)" + }, { "table": "comments", "name": "comments_zid_idx", "definition": "CREATE INDEX comments_zid_idx ON public.comments USING btree (zid)" }, + { + "table": "comments", + "name": "comments_zid_modified_idx", + "definition": "CREATE INDEX comments_zid_modified_idx ON public.comments USING btree (zid, modified)" + }, { "table": "comments", "name": "comments_zid_tid_key", @@ -12140,6 +12150,11 @@ "name": "votes_latest_unique_zid_tid_idx", "definition": "CREATE INDEX votes_latest_unique_zid_tid_idx ON public.votes USING btree (zid, tid)" }, + { + "table": "votes", + "name": "votes_zid_created_idx", + "definition": "CREATE INDEX votes_zid_created_idx ON public.votes USING btree (zid, created)" + }, { "table": "votes", "name": "votes_zid_pid_idx", @@ -12795,6 +12810,10 @@ { "path": "server/postgres/migrations/000042_tid_auto_transaction_lock.sql", "sha256": "ae12bd2dcce3a8e055adb54b241c090f36861ad4185771e173a87abd278b53f6" + }, + { + "path": "server/postgres/migrations/000043_add_conversation_activity_indexes.sql", + "sha256": "1c85ef8a67bb0add2bcf6dd7e38fabb977c26fe004994cf78e06fed8eda9b906" } ] } diff --git a/docs/migration-upgrade-notes.md b/docs/migration-upgrade-notes.md index 37be4635b..c0e61f0b8 100644 --- a/docs/migration-upgrade-notes.md +++ b/docs/migration-upgrade-notes.md @@ -57,7 +57,7 @@ operator session, `psql -X -v ON_ERROR_STOP=1 -f ` is equivalent, using the normal secret connection environment without a credential argument. On any query error, ROLLBACK or close that same client before returning it to a pool. -Expected initial-schema results: 20 `WOULD_ADOPT`, four `WOULD_APPLY`, and four +Expected initial-schema results: 20 `WOULD_ADOPT`, thirteen `WOULD_APPLY`, and four `OUTSIDE_RELEASE` entries. The report conservatively flags any existing queue role for migration-session review rather than guessing inherited ADMIN/SET authority. Existing ledgers/queues report review-required; they need the exact @@ -80,8 +80,8 @@ to a runtime login just to satisfy startup; startup needs metadata SELECT. Each ordinary file and its history receipt commit together. If M23 fails after M19 commits, M19 remains applied while all M23 changes and its receipt roll back. -Do not describe that as a rollback of the whole release. M22 is the documented -concurrent-index exception; interrupted valid indexes may persist and be reused. +Do not describe that as a rollback of the whole release. M22 and M43 are the documented +concurrent-index exceptions; interrupted valid indexes may persist and be reused. Check invalid/conflicting index recovery in [migrations.md](migrations.md). Two runners serialize using the database advisory lock; they do not double-apply. Lost commit connections require history inspection, not an assumed rollback. @@ -98,3 +98,17 @@ Keep a per-deployment [reconciliation record](migration-reconciliation.md), including exact source hashes, schema report, actual session authority, observed receipts, supported variants, backup evidence and health result. Do not publish credentials, application records or real conversation/report identifiers. + + +## Derived conversation activity indexes + +Migration 000043 is required by this release and applies at the next deploy. +It adds only `votes(zid, created)`, `comments(zid, created)` and +`comments(zid, modified)`. Earlier application SQL remains compatible. +The concurrent-index header selects one autocommit build per statement under +the migration advisory lock, followed by a catalog-checked history transaction. +Each build has a 5 s lock wait and 5 min statement ceiling. Ordinary participation +reads and writes continue; competing DDL and long snapshots may delay or fail a +build. Successful earlier indexes remain after failure. Inspect any invalid index, +explicitly drop only that expected interrupted index concurrently, and retry; +valid indexes are reused. See [the runner contract](migrations.md#concurrent-index-file-header). diff --git a/docs/migrations.md b/docs/migrations.md index c6ca4fe40..dc683744a 100644 --- a/docs/migrations.md +++ b/docs/migrations.md @@ -146,6 +146,16 @@ drops an index automatically. After all builds, catalog validity is checked agai in the transaction that records APPLIED. A failed history write leaves the valid indexes for the next run. Ordinary files retain atomic SQL/history semantics. +Migration 000043 adds `votes(zid, created)`, `comments(zid, created)` and +`comments(zid, modified)` for derived activity reads. Existing `votes(zid, pid)` +already serves participant vote counts. The three builds take SHARE UPDATE +EXCLUSIVE on their tables, compatible with ordinary INSERT/UPDATE/DELETE and +SELECT; competing schema work and long snapshots can delay a build until its +budget fires. No stored value, function or application SQL changes. It applies +at the next deployment and is additive beside the previous application. +Reversal, if required, is an explicit concurrent drop of those three indexes; +it removes only the read acceleration and never restores or changes data. + ## Release contents and new migrations `server/postgres/migrations/release.txt` explicitly selects every required file. @@ -223,7 +233,7 @@ before. `apply` never runs this release's pending SQL after a tolerated newer migration; that order is refused before any change. The rule only helps releases that contain it: a release built before it refuses every newer row. -Declarations for 000019–000042 (the older code is the release just before each +Declarations for 000019–000043 (the older code is the release just before each migration, as recorded in `release.txt` history): | Migration | Declared | Evidence | @@ -243,9 +253,10 @@ migration, as recorded in `release.txt` history): | 000039 clear conversation download keys | additive | Data-only: `UPDATE public.zinvites SET uuid = NULL WHERE uuid IS NOT NULL`. No object is redefined; the `uuid` column stays nullable (000009). Every reader tolerates NULL — `conversationUuid` mints on demand, `getZidForUuid` returns not-found for a cleared key, and new conversations still receive a fresh uuid at creation — and no reader in server, queue-rs, delphi or math expects a non-NULL uuid, so an earlier release runs correctly beside it. The UPDATE takes ROW EXCLUSIVE and per-row locks only, which do not block the participant path's `SELECT`s on `zinvites` (resolved by zinvite code, never uuid). Reversal is impossible: the keys are not stored; `down/000039_restore_zinvites_uuid.sql` is a documented no-op and owners re-mint through the owner-gated route. | | 000041 Delphi run record | additive | One new read function, `pd_run_record(env, job)`: STABLE, SECURITY DEFINER with a pinned `search_path`, owned by `polis_queue_owner`, EXECUTE granted to `polis_queue_executor` only. No table, row, column or existing function changes and no table grant; nothing in the earlier release calls it, and its one reader (the polis-api run-record route) is off by default and hands back to Node when the function is missing. It takes no table lock. Number 000040 is reserved for another draft. Reversal: `down/000041_drop_delphi_run_record.sql` drops the function (it stores nothing). The runner's `forward.py` tolerates it as additive. | | 000042 statement-number lock to commit | additive | `tid_auto` (BEFORE INSERT on `comments`) takes `pg_advisory_xact_lock` instead of the session lock `pg_advisory_lock`, on the same key, so a conversation's statement-number lock is held until the inserting transaction ends rather than released before it commits; `tid_auto_unlock` and its AFTER INSERT trigger are dropped. Numbering is unchanged (MAX(tid) + 1 per conversation, from 0, no gaps); no table, column, index, constraint or row changes. No code in the earlier release calls `tid_auto_unlock` or takes the lock; every writer lets the trigger assign `tid` and reads it back, so an earlier release inserts and numbers statements as before. Locks: `DROP TRIGGER` takes ACCESS EXCLUSIVE on `comments` until the file commits, waiting at most the 5 s `lock_timeout` for transactions already using `comments`; comment reads and writes queue behind it for that wait, once; on timeout nothing changes and the deploy can be retried. Reversal: `down/000042_restore_tid_auto_session_lock.sql` restores both functions and the trigger exactly as `000000_initial.sql` defines them (SHARE ROW EXCLUSIVE on `comments`, bounded at 5 s), and brings back the race this migration removes. The runner's `forward.py` tolerates it as additive. | +| 000043 activity indexes | additive | Three ordinary btree indexes only; no table, function, row or application SQL changes. Concurrent builds preserve ordinary participation writes. | So a rollback to a release with this rule that lists 000027 starts beside -000028–000031, 000038, 000039, 000041 and 000042; a rollback past 000027 (or 000024) refuses, as it must: the +000028–000031, 000038, 000039, 000041–000043; a rollback past 000027 (or 000024) refuses, as it must: the earlier queue daemon would exit on the newer contract. ## CI and local test stacks diff --git a/queue-rs/polis-migrate/tests/forward.py b/queue-rs/polis-migrate/tests/forward.py index 337acd7d7..a160ebb78 100644 --- a/queue-rs/polis-migrate/tests/forward.py +++ b/queue-rs/polis-migrate/tests/forward.py @@ -41,7 +41,8 @@ def test_01_ledger_declares_every_migration(self): '000028_create_delphi_results.sql', '000029_extend_delphi_graph_stages.sql', '000030_create_delphi_writers.sql', '000031_scope_delphi_result_reads.sql', '000038_create_delphi_comment_embeddings.sql', '000039_clear_zinvites_uuid.sql', - '000041_create_delphi_run_record.sql', '000042_tid_auto_transaction_lock.sql'}) + '000041_create_delphi_run_record.sql', '000042_tid_auto_transaction_lock.sql', + '000043_add_conversation_activity_indexes.sql'}) def test_02_deploy_records_declarations(self): db = self.new('records'); p.runner(db, 'deploy') diff --git a/server/bin/build-migration-report.py b/server/bin/build-migration-report.py index 996e648d7..16fe66d69 100644 --- a/server/bin/build-migration-report.py +++ b/server/bin/build-migration-report.py @@ -85,7 +85,7 @@ def manifest(path): '000029_extend_delphi_graph_stages.sql', '000030_create_delphi_writers.sql', '000031_scope_delphi_result_reads.sql', '000038_create_delphi_comment_embeddings.sql', '000039_clear_zinvites_uuid.sql', '000041_create_delphi_run_record.sql', - '000042_tid_auto_transaction_lock.sql'} + '000042_tid_auto_transaction_lock.sql', '000043_add_conversation_activity_indexes.sql'} assert selected == {p.name for p in files} | pending, 'report scope differs from release selection' assert held == {'000021_create_polis_coordinator.sql'}, 'review changed hold policy' numbered = sorted(MIG.glob('*.sql')) @@ -151,17 +151,7 @@ def manifest(path): CASE WHEN NOT can_reconcile THEN 'BLOCKED_RECONCILIATION' WHEN NOT reconcile_authority OR NOT can_provision THEN 'REVIEW_MIGRATION_SESSION_AUTHORITY' ELSE 'WOULD_APPLY' END - FROM (VALUES ('000019_create_polis_queue.sql'),('000023_create_delphi_foundation.sql'), - ('000024_create_polis_queue_large_class.sql'), - ('000027_create_sealed_job_graphs.sql'), - ('000028_create_delphi_results.sql'), - ('000029_extend_delphi_graph_stages.sql'), - ('000030_create_delphi_writers.sql'), - ('000031_scope_delphi_result_reads.sql'), - ('000038_create_delphi_comment_embeddings.sql'), - ('000039_clear_zinvites_uuid.sql'), - ('000041_create_delphi_run_record.sql'), - ('000042_tid_auto_transaction_lock.sql')) p(migration) CROSS JOIN readiness + FROM (VALUES ''' + ','.join("('" + name + "')" for name in sorted(pending)) + ''') p(migration) CROSS JOIN readiness UNION ALL SELECT migration, NULL::boolean, 'OUTSIDE_RELEASE' FROM (VALUES ('000020'),('000021'),('000025'),('000026')) p(migration) diff --git a/server/postgres/migrations/000043_add_conversation_activity_indexes.sql b/server/postgres/migrations/000043_add_conversation_activity_indexes.sql new file mode 100644 index 000000000..f0de3d5b8 --- /dev/null +++ b/server/postgres/migrations/000043_add_conversation_activity_indexes.sql @@ -0,0 +1,13 @@ +-- 000043_add_conversation_activity_indexes.sql +-- polis-migrate: concurrent-indexes +-- +-- Support derived conversation activity from vote and comment timestamps. +-- Additive: existing readers and writers keep their SQL and stored values. +-- The runner builds each index in autocommit under the migration advisory lock, +-- with a 5 s lock wait and 5 min statement budget per build. Concurrent builds +-- take SHARE UPDATE EXCLUSIVE, compatible with ordinary reads and writes. +-- Valid matching indexes survive retries. An invalid interrupted build refuses +-- before any build: inspect, DROP INDEX CONCURRENTLY the named index, then retry. +CREATE INDEX CONCURRENTLY IF NOT EXISTS votes_zid_created_idx ON votes (zid, created); +CREATE INDEX CONCURRENTLY IF NOT EXISTS comments_zid_created_idx ON comments (zid, created); +CREATE INDEX CONCURRENTLY IF NOT EXISTS comments_zid_modified_idx ON comments (zid, modified); diff --git a/server/postgres/migrations/compat.txt b/server/postgres/migrations/compat.txt index 427d6ae7e..409735de3 100644 --- a/server/postgres/migrations/compat.txt +++ b/server/postgres/migrations/compat.txt @@ -42,3 +42,4 @@ 000039_clear_zinvites_uuid.sql additive 000041_create_delphi_run_record.sql additive 000042_tid_auto_transaction_lock.sql additive +000043_add_conversation_activity_indexes.sql additive diff --git a/server/postgres/migrations/release.txt b/server/postgres/migrations/release.txt index 5a37407c3..67a75fc79 100644 --- a/server/postgres/migrations/release.txt +++ b/server/postgres/migrations/release.txt @@ -32,3 +32,4 @@ 000039_clear_zinvites_uuid.sql 000041_create_delphi_run_record.sql 000042_tid_auto_transaction_lock.sql +000043_add_conversation_activity_indexes.sql diff --git a/server/postgres/migrations/report/first-deploy.sql b/server/postgres/migrations/report/first-deploy.sql index 695c95202..b5891b2cd 100644 --- a/server/postgres/migrations/report/first-deploy.sql +++ b/server/postgres/migrations/report/first-deploy.sql @@ -2,7 +2,7 @@ -- First deployment only: no existing ledger or queue. Other states refuse. -- This is a catalog forecast, not DDL success or deployment-health proof. -- sha256 8fa1066d9fc29c1df528b300199c619a2f9edecf1432926ad6a8146ebc650593 adoption/helpers.sql --- sha256 b6b80d321c37aaaff86f9c290cb75f450334c32619637a57bae52433bea978d0 release.txt +-- sha256 80e69155198a1c4290c8803efe6607f360886f8afee11af8d2536242aa237f69 release.txt -- sha256 8a8b24fa47a25c613a8329aa79f413ac7461a93b12134045ae1cf2457e2ee3b7 held.txt -- sha256 c6b5c71247d129964dd89ba560a4522caef1abbb9379ad1b3445d6ed96be805b adoption/000000_initial.sql -- sha256 28ef33976beb9c7c9248ac800f29aab048f4410c2170ad12e3ade71d72e5ecb5 adoption/000001_update_pwreset_table.sql @@ -57,6 +57,7 @@ -- sha256 48ae309832ed67f280965915f0adc44109c082ef5da62c2bae830b3793bd124f 000039_clear_zinvites_uuid.sql -- sha256 e6d86397e5b53ed3d75d73278a293353512698bd95be2da288c92e94a935dee2 000041_create_delphi_run_record.sql -- sha256 ae12bd2dcce3a8e055adb54b241c090f36861ad4185771e173a87abd278b53f6 000042_tid_auto_transaction_lock.sql +-- sha256 1c85ef8a67bb0add2bcf6dd7e38fabb977c26fe004994cf78e06fed8eda9b906 000043_add_conversation_activity_indexes.sql BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY; SET LOCAL search_path=pg_catalog,public; SET LOCAL statement_timeout='30s'; @@ -1398,17 +1399,7 @@ SELECT (SELECT EXISTS(SELECT 1 FROM pg_index WHERE indexrelid=to_regclass('publi CASE WHEN NOT can_reconcile THEN 'BLOCKED_RECONCILIATION' WHEN NOT reconcile_authority OR NOT can_provision THEN 'REVIEW_MIGRATION_SESSION_AUTHORITY' ELSE 'WOULD_APPLY' END - FROM (VALUES ('000019_create_polis_queue.sql'),('000023_create_delphi_foundation.sql'), - ('000024_create_polis_queue_large_class.sql'), - ('000027_create_sealed_job_graphs.sql'), - ('000028_create_delphi_results.sql'), - ('000029_extend_delphi_graph_stages.sql'), - ('000030_create_delphi_writers.sql'), - ('000031_scope_delphi_result_reads.sql'), - ('000038_create_delphi_comment_embeddings.sql'), - ('000039_clear_zinvites_uuid.sql'), - ('000041_create_delphi_run_record.sql'), - ('000042_tid_auto_transaction_lock.sql')) p(migration) CROSS JOIN readiness + FROM (VALUES ('000019_create_polis_queue.sql'),('000023_create_delphi_foundation.sql'),('000024_create_polis_queue_large_class.sql'),('000027_create_sealed_job_graphs.sql'),('000028_create_delphi_results.sql'),('000029_extend_delphi_graph_stages.sql'),('000030_create_delphi_writers.sql'),('000031_scope_delphi_result_reads.sql'),('000038_create_delphi_comment_embeddings.sql'),('000039_clear_zinvites_uuid.sql'),('000041_create_delphi_run_record.sql'),('000042_tid_auto_transaction_lock.sql'),('000043_add_conversation_activity_indexes.sql')) p(migration) CROSS JOIN readiness UNION ALL SELECT migration, NULL::boolean, 'OUTSIDE_RELEASE' FROM (VALUES ('000020'),('000021'),('000025'),('000026')) p(migration) From 4f50b6f28f30160a9d8a0ca3f3024ef3c03b6ec2 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Wed, 21 Oct 2026 00:51:17 -0700 Subject: [PATCH 18/30] embed: an unknown site id on the implicit route answers 404, not 500 (#3245) The first visit to an embedded page creates its conversation after looking up which account owns the page's site id. When no account does, the route reported a server failure; it now answers 404 with the code the handler already used for that case. Nothing is created in either case and every other path keeps its status. Co-authored-by: Claude Fable 5.1 --- .../integration/implicit-conversation.test.ts | 157 ++++++++++++++++++ server/src/routes/implicitConversation.ts | 12 +- 2 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 server/__tests__/integration/implicit-conversation.test.ts diff --git a/server/__tests__/integration/implicit-conversation.test.ts b/server/__tests__/integration/implicit-conversation.test.ts new file mode 100644 index 000000000..0e0a44ff7 --- /dev/null +++ b/server/__tests__/integration/implicit-conversation.test.ts @@ -0,0 +1,157 @@ +import { + afterAll, + afterEach, + beforeAll, + describe, + expect, + jest, + test, +} from "@jest/globals"; +import { randomUUID } from "crypto"; +import type { Express } from "express"; +import request from "supertest"; +import { getApp } from "../app-loader"; +import { pool } from "../setup/db-test-helpers"; +import pg from "../../src/db/pg-query"; + +describe("implicit embed conversations", () => { + let app: Express; + let owner: number; + let siteId: string; + const parentUrl = `https://example.invalid/embed/${randomUUID()}`; + const unknownSiteId = `polis_site_id_${randomUUID()}`; + + beforeAll(async () => { + app = await getApp(); + const { rows } = await pool.query( + "INSERT INTO users (email, site_owner) VALUES ($1, TRUE) RETURNING uid, site_id", + [`embed-${randomUUID()}@example.invalid`] + ); + owner = rows[0].uid; + siteId = rows[0].site_id; + }); + + afterEach(() => jest.restoreAllMocks()); + + afterAll(async () => { + await pool.query("DELETE FROM page_ids WHERE site_id = ANY($1)", [ + [siteId, unknownSiteId], + ]); + await pool.query( + "DELETE FROM zinvites WHERE zid IN (SELECT zid FROM conversations WHERE parent_url = $1)", + [parentUrl] + ); + await pool.query("DELETE FROM conversations WHERE parent_url = $1", [ + parentUrl, + ]); + await pool.query("DELETE FROM users WHERE uid = $1", [owner]); + }); + + function visit(site: string, page: string) { + return request(app) + .get(`/${site}/${page}`) + .set("Host", "embed.example.invalid") + .set("Accept", "text/plain") + .query({ parent_url: parentUrl }); + } + + async function pageRows(page: string) { + const { rows } = await pool.query( + `SELECT c.zid, c.owner, c.org_id, c.parent_url, p.site_id, p.page_id, z.zinvite + FROM conversations c + JOIN page_ids p ON p.zid = c.zid + JOIN zinvites z ON z.zid = c.zid + WHERE p.site_id = $1 AND p.page_id = $2`, + [siteId, page] + ); + return rows; + } + + function redirectLocation(invite: string, page: string) { + return `http://embed.example.invalid/${invite}?site_id=${siteId}&page_id=${page}&parent_url=${encodeURIComponent( + parentUrl + )}`; + } + + test("an unknown site answers 404 without creating conversation, page or invite rows", async () => { + const writes = jest.spyOn(pg, "query"); + const promiseWrites = jest.spyOn(pg, "queryP"); + const response = await visit(unknownSiteId, "unknown-page"); + + // Scope row checks to this request so other integration suites can run concurrently. + const { rows } = await pool.query( + `SELECT + (SELECT count(*)::int FROM conversations WHERE parent_url = $1) AS conversations, + (SELECT count(*)::int FROM page_ids WHERE site_id = $2) AS pages, + (SELECT count(*)::int FROM zinvites z JOIN conversations c ON c.zid = z.zid + WHERE c.parent_url = $1) AS invites`, + [parentUrl, unknownSiteId] + ); + expect(rows[0]).toEqual({ conversations: 0, pages: 0, invites: 0 }); + expect(writes).not.toHaveBeenCalled(); + expect(promiseWrites).not.toHaveBeenCalled(); + expect(response.status).toBe(404); + expect(response.body).toEqual({ + error: "polis_err_bad_site_id", + message: "polis_err_bad_site_id", + status: 404, + }); + }); + + test("a site owner's first visit creates the rows and preserves the redirect bytes", async () => { + const response = await visit(siteId, "first-page"); + const rows = await pageRows("first-page"); + expect(rows).toHaveLength(1); + expect(rows[0]).toMatchObject({ + owner, + org_id: owner, + parent_url: parentUrl, + site_id: siteId, + page_id: "first-page", + }); + expect(rows[0].zinvite).toMatch(/^[2-9][a-z0-9]{9}$/); + const location = redirectLocation(rows[0].zinvite, "first-page"); + expect(response.status).toBe(302); + expect(response.headers.location).toBe(location); + expect(response.text).toBe(`Found. Redirecting to ${encodeURI(location)}`); + }); + + test("a second visit resolves the existing conversation without creating another", async () => { + const first = await visit(siteId, "repeat-page"); + const before = await pageRows("repeat-page"); + expect(first.status).toBe(302); + expect(before).toHaveLength(1); + const writes = jest.spyOn(pg, "query"); + const promiseWrites = jest.spyOn(pg, "queryP"); + const second = await visit(siteId, "repeat-page"); + expect(second.status).toBe(302); + expect(second.headers.location).toBe( + redirectLocation(before[0].zinvite, "repeat-page") + ); + expect(second.headers.location).toBe(first.headers.location); + expect(second.text).toBe(first.text); + expect(await pageRows("repeat-page")).toEqual(before); + expect(writes).not.toHaveBeenCalled(); + expect( + promiseWrites.mock.calls.every(([sql]) => /^select /i.test(String(sql))) + ).toBe(true); + }); + + test("an owner lookup service error still answers 500 even with the same message", async () => { + const read = pg.queryP_readOnly.bind(pg); + jest.spyOn(pg, "queryP_readOnly").mockImplementation((sql, params) => { + if (String(sql).startsWith("select uid from users")) { + return Promise.reject(new Error("polis_err_bad_site_id")); + } + return read(sql, params); + }); + const response = await visit(unknownSiteId, "lookup-error"); + expect(response.status).toBe(500); + expect(response.body).toEqual({ + error: "polis_err_creating_conv", + message: "polis_err_creating_conv", + status: 500, + }); + }); + +}); diff --git a/server/src/routes/implicitConversation.ts b/server/src/routes/implicitConversation.ts index e9f12caf4..22d82f4a5 100644 --- a/server/src/routes/implicitConversation.ts +++ b/server/src/routes/implicitConversation.ts @@ -47,6 +47,12 @@ function registerPageId(site_id: string, page_id: string, zid: number) { ); } +class MissingSiteOwnerError extends Error { + constructor() { + super("polis_err_bad_site_id"); + } +} + function initializeImplicitConversation( site_id: string, page_id: string, @@ -62,7 +68,7 @@ function initializeImplicitConversation( ) .then(function (rows: string | any[]) { if (!rows || !rows.length) { - throw new Error("polis_err_bad_site_id"); + throw new MissingSiteOwnerError(); } return new Promise(function ( resolve: (arg0: { @@ -310,6 +316,10 @@ function handle_GET_implicit_conversation_generation( res.redirect(url); }) .catch(function (err: any) { + if (err instanceof MissingSiteOwnerError) { + failJson(res, 404, "polis_err_bad_site_id", err); + return; + } failJson(res, 500, "polis_err_creating_conv", err); }); } else { From 30adea7b9dea3ca30e29f9a1e8beb21007a68326 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Wed, 21 Oct 2026 08:37:59 -0700 Subject: [PATCH 19/30] polis-api: typed read routes for GET /api/v3/votes and /api/v3/votes/me, staged off (#3247) * polis-api: typed read routes for GET /api/v3/votes and /api/v3/votes/me, staged off Two contracts and two routes with their own bounded read pool; they serve the demonstrated empty and single-row results byte-exactly against Node's recordings and hand everything else back to Node. Off by default behind the nginx switch; nothing is served until switched on. Co-Authored-By: Claude Fable 5.1 * differential: the routing census carries the two vote read routes; contracts crate formatted The CLI differential's route inventory now lists the votes and votes/me selector with scenarios and exact serving counts, and the contracts crate's lib.rs is rustfmt-clean. Co-Authored-By: Claude Fable 5.1 --------- Co-authored-by: Claude Fable 5.1 --- file-server/nginx/render-rust-api.sh | 9 +- .../rust-api/votesRead.location.conf.template | 59 + polis-cli/tests/differential/README.md | 5 + polis-cli/tests/differential/compose.yml | 2 + polis-cli/tests/differential/harness.py | 8 + polis-cli/tests/differential/routes.json | 26 + polis-cli/tests/differential/run.py | 28 +- polis-cli/tests/differential/test_contract.py | 21 +- queue-rs/polis-api/README.md | 4 + queue-rs/polis-api/VOTES-READ.md | 97 + .../polis-api/conformance/nginx-routing.sh | 24 + .../conformance/votes-read-compose.yml | 10 + .../conformance/votes-read-replay.cjs | 236 ++ .../polis-api/conformance/votes-read-run.sh | 51 + .../polis-api/conformance/votes-read-seed.cjs | 15 + queue-rs/polis-api/src/comments.rs | 4 +- queue-rs/polis-api/src/main.rs | 32 + queue-rs/polis-api/src/route.rs | 76 + queue-rs/polis-api/src/votes_read.rs | 267 ++ queue-rs/polis-api/src/votes_read_tests.rs | 145 + .../src/fixtures/votes-read.json | 2674 +++++++++++++++++ queue-rs/polis-contracts/src/lib.rs | 1 + queue-rs/polis-contracts/src/votes.rs | 13 + queue-rs/polis-contracts/src/votes_read.rs | 318 ++ 24 files changed, 4117 insertions(+), 8 deletions(-) create mode 100644 file-server/nginx/rust-api/votesRead.location.conf.template create mode 100644 queue-rs/polis-api/VOTES-READ.md create mode 100644 queue-rs/polis-api/conformance/votes-read-compose.yml create mode 100644 queue-rs/polis-api/conformance/votes-read-replay.cjs create mode 100755 queue-rs/polis-api/conformance/votes-read-run.sh create mode 100644 queue-rs/polis-api/conformance/votes-read-seed.cjs create mode 100644 queue-rs/polis-api/src/votes_read.rs create mode 100644 queue-rs/polis-api/src/votes_read_tests.rs create mode 100644 queue-rs/polis-contracts/src/fixtures/votes-read.json create mode 100644 queue-rs/polis-contracts/src/votes_read.rs diff --git a/file-server/nginx/render-rust-api.sh b/file-server/nginx/render-rust-api.sh index 8c7e701c9..144e14ba8 100644 --- a/file-server/nginx/render-rust-api.sh +++ b/file-server/nginx/render-rust-api.sh @@ -72,6 +72,13 @@ for route in $(echo "${RUST_API_ROUTES:-}" | tr ',' ' '); do " rust_api_locations="${rust_api_locations} metadataAnswers" ;; + votesRead) + case " $rust_api_locations " in *" votesRead "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/votes ${RUST_API_UPSTREAM}; + /api/v3/votes/me ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} votesRead" + ;; metadataRead) case " $rust_api_locations " in *" metadataRead "*) continue ;; esac RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/metadata ${RUST_API_UPSTREAM}; @@ -343,7 +350,7 @@ for route in $(echo "${RUST_API_ROUTES:-}" | tr ',' ' '); do done export RUST_API_RESOLVER=${RUST_API_RESOLVER:-127.0.0.11} if [ -n "$rust_api_unknown" ]; then - echo "ERROR RUST_API_ROUTES: unknown route(s):${rust_api_unknown} (known: pca2 owner-conversations comments nextComment testConnection testDatabase contexts domainWhitelist metadataQuestions metadataAnswers metadataRead metadataChoices recentStarted recentActivity legacyPca treeviteWaves treeviteInvites treeviteCsv conversationPreload participationRead allConversations reportsRead bidToPid conversationStats statementImportance topicSelections treeviteMyInvites treeviteMe topicPrioritize xidReport opsCatchall opsPage opsWhoami collectiveStatement topicStats delphiLogs delphiRun delphiResult delphiVisualizations delphiReports delphiRead otherConversationsPage integratePage adminPage userLogoutPage settingsPage userLoginPage userCreatePage createPage einvitesRead legacyConversations robots about). Selection rejected." >&2 + echo "ERROR RUST_API_ROUTES: unknown route(s):${rust_api_unknown} (known: pca2 owner-conversations comments nextComment testConnection testDatabase contexts domainWhitelist metadataQuestions metadataAnswers votesRead metadataRead metadataChoices recentStarted recentActivity legacyPca treeviteWaves treeviteInvites treeviteCsv conversationPreload participationRead allConversations reportsRead bidToPid conversationStats statementImportance topicSelections treeviteMyInvites treeviteMe topicPrioritize xidReport opsCatchall opsPage opsWhoami collectiveStatement topicStats delphiLogs delphiRun delphiResult delphiVisualizations delphiReports delphiRead otherConversationsPage integratePage adminPage userLogoutPage settingsPage userLoginPage userCreatePage createPage einvitesRead legacyConversations robots about). Selection rejected." >&2 exit 1 elif [ -n "$RUST_API_MAP_ENTRIES" ] && ! echo "$RUST_API_UPSTREAM" | grep -Eqx '[A-Za-z0-9._-]+:[0-9]{1,5}'; then diff --git a/file-server/nginx/rust-api/votesRead.location.conf.template b/file-server/nginx/rust-api/votesRead.location.conf.template new file mode 100644 index 000000000..7f6445182 --- /dev/null +++ b/file-server/nginx/rust-api/votesRead.location.conf.template @@ -0,0 +1,59 @@ +# GET and HEAD /api/v3/votes without a body go to polis-api +# (RUST_API_ROUTES contains votesRead); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location = /api/v3/votes { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} + +# GET and HEAD /api/v3/votes/me without a body go to polis-api +# (RUST_API_ROUTES contains votesRead); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location = /api/v3/votes/me { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/polis-cli/tests/differential/README.md b/polis-cli/tests/differential/README.md index 0df060978..84a74f979 100644 --- a/polis-cli/tests/differential/README.md +++ b/polis-cli/tests/differential/README.md @@ -94,6 +94,11 @@ The real nginx reload helper receives `RUST_API_ROUTES` empty and then every switch in `routes.json`, retaining the proxy container and its project-owned routing volume. After old workers drain, the harness clears the access log for each phase's independent counts. The route-template census rejects missing entries. +Selectors covering multiple paths also declare `paths` contracts; the runner +checks each path independently as well as the selector total. `votesRead` +exercises `vote list` and `vote mine` with empty and single-row results served +from Rust, then requires a Node handoff for each multi-row read. Vote POSTs +remain Node requests and count separately from the read successes. Each entry requires an exact request count, a minimum number of sole Rust HTTP200 responses, and an exact count of scoped Node handoffs with a reason. These counts cover this generated fixture only. Unexercised routes explicitly diff --git a/polis-cli/tests/differential/compose.yml b/polis-cli/tests/differential/compose.yml index c6bfd154b..78c6f4453 100644 --- a/polis-cli/tests/differential/compose.yml +++ b/polis-cli/tests/differential/compose.yml @@ -30,6 +30,8 @@ services: AUTH_ISSUER: https://oidc-simulator:3000/ AUTH_AUDIENCE: users POLIS_API_PARTICIPANT_READS: "1" + POLIS_API_VOTES_READS: "1" + POLIS_API_VOTES_READ_DATABASE_URL: postgres://postgres@postgres:5432/p027 POLIS_API_PARTICIPANT_PUBLIC_KEY_FILE: /artifacts/participant-public.pem POLIS_JWT_ISSUER: https://pol.is/ POLIS_JWT_AUDIENCE: participants diff --git a/polis-cli/tests/differential/harness.py b/polis-cli/tests/differential/harness.py index 7533b093b..0aa452227 100644 --- a/polis-cli/tests/differential/harness.py +++ b/polis-cli/tests/differential/harness.py @@ -110,6 +110,14 @@ def serving_matches(counts, contract): and counts['requests'] == contract['expected_requests']) +def route_contracts(routes): + """Check each selector's total and each explicitly inventoried path.""" + for route, contract in routes.items(): + yield route, contract + for path in contract.get('paths', []): + yield route + ':' + path['path'], path + + def load_routes(): """The switch set under test; refuses a template census that differs.""" routes=json.loads((HERE/'routes.json').read_text()) diff --git a/polis-cli/tests/differential/routes.json b/polis-cli/tests/differential/routes.json index e48aee955..30047acce 100644 --- a/polis-cli/tests/differential/routes.json +++ b/polis-cli/tests/differential/routes.json @@ -443,6 +443,32 @@ "expected_node_handoffs": 0, "scope": "Rust-only public importance counts. The generated report case precedes all votes: both participant-visible comments must have zero counts. Node-off display retains statements with explicitly unavailable null counts; the named contract check preserves every other field." }, + "votesRead": { + "path": "^/api/v3/votes(/me)?$", + "minimum_rust_successes": 4, + "expected_requests": 8, + "expected_node_handoffs": 2, + "commands": ["vote list", "vote mine", "vote"], + "scope": "Empty and single-row reads serve from Rust. Each path hands its multi-row read to Node because the source query promises no row order. The two vote POSTs bypass Rust.", + "paths": [ + { + "path": "/api/v3/votes", + "minimum_rust_successes": 2, + "expected_requests": 5, + "expected_node_handoffs": 1, + "commands": ["vote list", "vote list single", "vote list multiple", "vote", "vote important"], + "scope": "The original owner read is empty; account-authenticated reads target the PID returned by the participant's vote after one and two votes. Empty and single-row latest reads serve from Rust; the multi-row read hands to Node. Both POSTs stay on Node." + }, + { + "path": "/api/v3/votes/me", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 1, + "commands": ["vote mine empty", "vote mine single", "vote mine"], + "scope": "The owner's empty history and the participant's single-row history serve from Rust. The existing later participant history scenario has two rows and must hand to Node without inventing an order." + } + ] + }, "delphiLogs": { "path": "/api/v3/delphi/logs", "minimum_rust_successes": 0, diff --git a/polis-cli/tests/differential/run.py b/polis-cli/tests/differential/run.py index 64c83225a..194e71a51 100644 --- a/polis-cli/tests/differential/run.py +++ b/polis-cli/tests/differential/run.py @@ -16,7 +16,7 @@ import time from harness import (HERE, RUST_ONLY, Cli, Stack, differences, load_routes, route_lines, # noqa: F401 - routing_counts, run_phases, rust_only_checks, serving_matches) + route_contracts, routing_counts, run_phases, rust_only_checks, serving_matches) from cases import cases @@ -62,6 +62,20 @@ def main(): # The same participant marks a second statement important, after the # participant proof below has counted the first, unmarked vote. rows.insert(next(i for i,r in enumerate(rows) if r['command']=='comment')+1,dict(command='vote',scenario='vote important',args=['vote','2p027generated','--statement','1','--agree','--important'],expected_exit=0,scope='live',actor='participant')) + # The owner has an empty history. Once the participant has voted, + # read its one-row and two-row results; the latter stay on Node. + for anchor, commands, state in [ + ('join', ['vote mine'], 'empty'), + ('vote', ['vote list', 'vote mine'], 'single'), + ('vote important', ['vote list'], 'multiple'), + ]: + index = next(i for i, row in enumerate(rows) if row.get('scenario', row['command']) == anchor) + 1 + rows[index:index] = [dict(command=command, scenario=command+' '+state, + args=command.split()+['--conversation','2p027generated']+(['--account'] if state=='empty' else []), + expected_exit=0,scope='live', + actor='owner' if command=='vote list' or state=='empty' else 'participant', + participant_pid=command=='vote list', + vote_rows={'empty':0,'single':1,'multiple':2}[state]) for command in commands] rows += [dict(command=name,args=name.split(),expected_exit=8,scope='planned',actor='owner') for name,implemented in sorted(nodes.items()) if not implemented] captured={} for phase in run_phases(stack,cli,[('node',''),('rust',','.join(sorted(routes)))]): @@ -89,7 +103,15 @@ def main(): report[phase+'_admin_fixture']=json.loads(stack.dc('exec','-T','server','node','/differential/admin-seed.cjs').stdout) stack.begin(hashlib.sha256(row.get('scenario',row['command']).encode()).hexdigest()[:12],'cli'+str(index)) command_start=time.monotonic() - value=invoke(row) + invocation = dict(row, args=row['args']+['--pid',str(participant_id)]) if row.get('participant_pid') else row + value=invoke(invocation) + if 'vote_rows' in row: + data = value['json'].get('data') or {} + votes = data.get('votes' if row['command']=='vote list' else 'data') + if value['exit'] != 0 or not isinstance(votes, list) or len(votes) != row['vote_rows']: + raise RuntimeError('vote read fixture row count failed: '+row['scenario']) + if votes and any(vote.get('pid') != participant_id for vote in votes): + raise RuntimeError('vote read fixture participant failed: '+row['scenario']) timings.append({'command':row.get('scenario',row['command']),'seconds':round(time.monotonic()-command_start,3)}) print(phase+' '+row['command']+' exit='+str(value['exit']),file=sys.stderr,flush=True) stack.barrier(row['command']) @@ -141,7 +163,7 @@ def main(): log=stack.nginx_log() report[phase+'_routing']={} serving_failures=[] - for route,contract in routes.items(): + for route,contract in route_contracts(routes): matched_lines=route_lines(log,contract) counts=routing_counts(matched_lines) served=counts['rust_200'];fallback=counts['rust_fallbacks'] diff --git a/polis-cli/tests/differential/test_contract.py b/polis-cli/tests/differential/test_contract.py index e39efbaa5..2af31710d 100644 --- a/polis-cli/tests/differential/test_contract.py +++ b/polis-cli/tests/differential/test_contract.py @@ -1,5 +1,5 @@ import unittest -from run import differences, census, check_census, route_lines, routing_counts, rust_only_checks, serving_matches, RUST_ONLY +from run import differences, census, check_census, route_lines, route_contracts, routing_counts, rust_only_checks, serving_matches, RUST_ONLY class ComparatorTests(unittest.TestCase): def test_exact_route_log_matching_does_not_accept_neighbors(self): @@ -39,6 +39,25 @@ def test_parent_command_and_unavailable_leaf_are_included(self): class RoutingContractTests(unittest.TestCase): + def test_selector_total_cannot_hide_failure_of_one_path(self): + path_contracts = [dict(path=path, minimum_rust_successes=1, + expected_requests=2, expected_node_handoffs=1) + for path in ['/api/v3/votes', '/api/v3/votes/me']] + routes = {'votesRead': dict(path='^/api/v3/votes(/me)?$', + minimum_rust_successes=2, expected_requests=4, + expected_node_handoffs=2, paths=path_contracts)} + # The selector total is correct, but both successes came from one path. + log = '\n'.join([ + 'GET /api/v3/votes 127.0.0.1:5100 200', + 'GET /api/v3/votes 127.0.0.1:5100 200', + 'GET /api/v3/votes/me 127.0.0.1:5100 : 127.0.0.1:5000 502 : 200', + 'GET /api/v3/votes/me 127.0.0.1:5100 : 127.0.0.1:5000 502 : 200', + 'GET /api/v3/votes/meSuffix 127.0.0.1:5100 200']) + checks = {name: serving_matches(routing_counts(route_lines(log, contract)), contract) + for name, contract in route_contracts(routes)} + self.assertEqual(checks, {'votesRead': True, 'votesRead:/api/v3/votes': False, + 'votesRead:/api/v3/votes/me': False}) + def test_scoped_handoff_cannot_hide_lost_success_or_an_extra_fallback(self): contract={'minimum_rust_successes':2,'expected_node_handoffs':1,'expected_requests':3} self.assertTrue(serving_matches({'rust_200':2,'rust_fallbacks':1,'requests':3},contract)) diff --git a/queue-rs/polis-api/README.md b/queue-rs/polis-api/README.md index 2b9987331..24e3dc523 100644 --- a/queue-rs/polis-api/README.md +++ b/queue-rs/polis-api/README.md @@ -1474,3 +1474,7 @@ request deadline is 750 ms, with a 200 ms result statement timeout. `conformance/delphi-reports-pg-run.sh` runs the unchanged Postgres baseline plus native publication, timestamp, grouping, filter and bounded-handoff checks. It requires unique compose/port settings and the three local fixture images. + +The staged [vote read routes](VOTES-READ.md) cover latest/history responses under +`votesRead`, off by default. The route note names the identity quirks, bounded +read pools, exact response subset and Node hand-back conditions. diff --git a/queue-rs/polis-api/VOTES-READ.md b/queue-rs/polis-api/VOTES-READ.md new file mode 100644 index 000000000..8ea9dea89 --- /dev/null +++ b/queue-rs/polis-api/VOTES-READ.md @@ -0,0 +1,97 @@ +# Vote reads + +Nothing is served by default. The `votesRead` nginx selector includes only +bodyless GET/HEAD on `/api/v3/votes` and `/api/v3/votes/me`. POST, OPTIONS and +requests with bodies stay on Node. The existing reload command and generation +persistence apply to this selector without changes. + +The Rust process additionally requires `POLIS_API_VOTES_READS=1` and +`POLIS_API_VOTES_READ_DATABASE_URL`. Its auth lookups use that primary DSN; +`READ_ONLY_DATABASE_URL`, when set, supplies the data pool. Participant public +verification keys and the existing read OIDC JWKS configuration are needed to +admit those identities. There is no token minting, user creation or write. + +Each pool owns one connection and its own semaphore/acquisition queue. Acquisition +expires after 15 ms, statements after 50 ms, connections after 300 s. A 75 ms +request deadline sheds read work to Node. Cancelling the waiter does not release +a slot while its blocking query still runs. Neither pool borrows participation +writer slots, connections or acquisition queues. The executor, process and +underlying database CPU/I/O remain shared; this is not a resource-isolation claim +for an overloaded database. Queries materialize at most two candidate rows. + +## Node compatibility + +The contract is `polis-contracts/src/votes_read.rs`. Node registration is +`server/app.ts:868-892`; handlers are `server/src/routes/votes.ts:132-211` at +`4f50b6f28f30160a9d8a0ca3f3024ef3c03b6ec2`. + +| Branch | Node response | Rust admission | +| --- | --- | --- | +| Latest, no resolved PID | 200 `[]` | Yes | +| Latest, selected PID and optional `tid` | 200 latest rows | Zero or one row | +| History, missing member | 500 `polis_err_getting_pid` | Node | +| History, member and participant JWT PID | 200 history rows, including `weight:null` | Zero or one row | +| History, OIDC member without auth PID | 200 `[]` | Yes; preserve the auth-PID lookup mismatch | +| Closed conversation | Same read behavior | Same rules as an open conversation | +| Invalid/missing conversation or malformed `tid` | 400 parameter finalhandler HTML | Node | +| Missing required auth or invalid JWT | 401 auth JSON | Node | +| OIDC mapping failure | 400/429/500 user-error JSON | Node | +| Query/enrichment failure | 500 failJson | Node | +| Conditional freshness / HEAD | 304 / status with no body | Common HTTP renderer | +| Listener parser / HTTPS policy | 400/413/415/500 HTML; HTTPS GET 302, HEAD 400 | Listener or common HTTP policy | + +Both readers call Node's `storageRowToWire`; the wire is agree `-1`, disagree +`+1`, pass `0`. CSV exports use a different convention. Rust uses the shared +`votes::StorageConvention` boundary, including Node's preserved-invalid policy. +Null stays null. No CLI or reader performs sign arithmetic. + +`/votes` preserves a nonzero JWT PID over a query PID. JWT PID zero can be +overridden; the self-lookup sentinel asks for the authenticated UID's membership. +`/me` checks `getPid(uid)` but selects using the PID already assigned by auth. +OIDC has no such PID. `weight` is null because Node divides an absent field, +while `weight_x_32767` remains unchanged. BIGINT times are decimal strings. +Neither route paginates or orders its rows. The latest query reads the latest +table; history can include multiple votes for one statement. + +## Hand-back boundary + +Rust returns the existing pre-response 502 hand-back for: + +- A disabled lane, missing pool, unsupported method, body/framing, or cookie. +- Missing, duplicate, unknown or noncanonical query parameters; noncanonical + integer spelling; extra filters/pagination; invalid conversation IDs. +- Missing required auth; unsupported or invalid JWTs, XID, mixed claim shapes, + foreign conversation scope, missing membership, treevite-gated membership, + missing verifier keys, or an OIDC identity requiring account creation. +- Unknown conversation, ambiguous membership, negative resolved member PID, + or `/me` membership lookup failure. +- More than one selected row (Node supplies no stable ordering), multiple or + noncanonical capability aliases for a populated response, or a changed table + column layout. Empty results require no capability enrichment. +- Connection/acquisition/statement/request deadline, database error or decoding + failure. Node owns its error body and caches. + +The nginx fallback covers failure before response headers; it cannot recover a +truncated response after headers. Requests are reads, so hand-back never replays +a participation write. + +`polis vote list` already resolves the participant when needed, passes `pid`, +and labels the data with the wire convention. `polis vote mine` already calls +`/api/v3/votes/me`. Neither needs a change when these routes are selected. The +existing `/me` OIDC behavior and lack of pagination remain visible to the CLI. + +## Checks + +`conformance/votes-read-run.sh` uses the existing sealed characterization stack, +the unchanged Node listener and direct complete HTTP byte comparison. It saves +both responses and accounts for every served request and hand-back. A Date-only +clock-boundary difference retries the entire exchange; no header/body is removed +from an accepted comparison. The checked-in contract fixture contains decoded +Node response bodies from that run, not hand-written expected successes. + +Set unique `COMPOSE_PROJECT_NAME`, `POLIS_RECOVERY_PG_PORT`, `P027_HTTP_PORT` and +`P027_CONTROL_PORT`, and supply the characterization images as for other read +routes. `X54_POLIS_API_IMAGE` must be built with `FEATURES=fixture-clock`. The +runner tears down only its own project. The normal API db-tests check locked-read +shedding, separate pool availability and write refusal. `nginx-routing.sh` checks +both path selections, deduplication, method/body routing and fallback. diff --git a/queue-rs/polis-api/conformance/nginx-routing.sh b/queue-rs/polis-api/conformance/nginx-routing.sh index 392a09bf4..017fdf4c8 100755 --- a/queue-rs/polis-api/conformance/nginx-routing.sh +++ b/queue-rs/polis-api/conformance/nginx-routing.sh @@ -1340,3 +1340,27 @@ stub "$p-rust" polis-api 5100 502 "handoff" sleep 6 expect /api/v3/delphi/logs node "Logs handoff" echo "ok 62 Logs off/on/deduplicated; method/body guards; 502 hands back to Node" + +# Both vote read paths share a selector; POST remains entirely on Node. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +expect /api/v3/votes node "vote reads off" +expect /api/v3/votes/me node "personal reads off" +start votesRead,votesRead +for path in /api/v3/votes /api/v3/votes/me; do + expect "$path" rust "vote reads on" + expect_upstream polis-api HEAD "$path" + expect_upstream server OPTIONS "$path" + expect_upstream server POST "$path" $'Content-Length: 2\r\n' '{}' + expect_upstream server GET "$path" $'Content-Length: 2\r\n' '{}' +done +[[ $(included | grep -c 'location = /api/v3/votes {') == 1 ]] || fail "vote reads duplicated" +[[ $(included | grep -c 'location = /api/v3/votes/me {') == 1 ]] || fail "personal reads duplicated" +expect /api/v3/nextComment node "vote reads leave participation alone" +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 "handoff" +sleep 6 +expect /api/v3/votes node "vote reads handoff" +expect /api/v3/votes/me node "personal reads handoff" +echo "ok vote read routes: off/on/deduplicated, methods/body, fallback" diff --git a/queue-rs/polis-api/conformance/votes-read-compose.yml b/queue-rs/polis-api/conformance/votes-read-compose.yml new file mode 100644 index 000000000..d4bf21e99 --- /dev/null +++ b/queue-rs/polis-api/conformance/votes-read-compose.yml @@ -0,0 +1,10 @@ +# Test-only opt-in; production defaults stay off. +services: + polis-api: + environment: + POLIS_API_VOTES_READS: "1" + POLIS_API_VOTES_READ_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_READ_JWKS_FILE: /artifacts/read-jwks.json + AUTH_ISSUER: https://oidc-simulator:3000/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ diff --git a/queue-rs/polis-api/conformance/votes-read-replay.cjs b/queue-rs/polis-api/conformance/votes-read-replay.cjs new file mode 100644 index 000000000..c770ee20b --- /dev/null +++ b/queue-rs/polis-api/conformance/votes-read-replay.cjs @@ -0,0 +1,236 @@ +"use strict"; +// Raw HTTP fixture proof; no response normalization. Node source and fixture +// writers are unchanged. Boundary handoffs are counted separately. +const fs = require("node:fs"); +const net = require("node:net"); +const zlib = require("node:zlib"); + +const NODE = { host: "server", port: 5000 }; +const RUST = { host: "polis-api", port: 5100 }; + + +function exchange(target, bytes, headOnly) { + return new Promise((resolve, reject) => { + const socket = net.connect(target.port, target.host); + const chunks = []; + let done = false; + const timer = setTimeout(() => finish(new Error("response deadline")), 10000); + function finish(err, value) { + if (done) return; + done = true; + clearTimeout(timer); + socket.destroy(); + if (err) reject(err); + else resolve(value); + } + socket.on("connect", () => socket.write(bytes)); + socket.on("data", (b) => { + chunks.push(b); + const all = Buffer.concat(chunks); + const end = complete(all, headOnly); + if (end !== null) finish(null, all.subarray(0, end)); + }); + socket.on("end", () => finish(null, Buffer.concat(chunks))); + socket.on("error", (e) => finish(e)); + }); +} + +// Offset just past one complete response in `buf`, or null if more is needed. +function complete(buf, headOnly) { + const headEnd = buf.indexOf("\r\n\r\n"); + if (headEnd < 0) return null; + const head = buf.subarray(0, headEnd).toString("latin1"); + const status = Number(head.split(" ")[1]); + const header = (name) => { + const line = head + .split("\r\n") + .slice(1) + .find((l) => l.toLowerCase().startsWith(name + ":")); + return line === undefined ? undefined : line.slice(name.length + 1).trim(); + }; + let at = headEnd + 4; + if (headOnly || status === 204 || status === 304 || (status >= 100 && status < 200)) return at; + if ((header("transfer-encoding") || "").toLowerCase() === "chunked") { + for (;;) { + const lineEnd = buf.indexOf("\r\n", at); + if (lineEnd < 0) return null; + const size = parseInt(buf.subarray(at, lineEnd).toString("latin1"), 16); + at = lineEnd + 2 + size + 2; + if (at > buf.length) return null; + if (size === 0) return at; + } + } + const length = header("content-length"); + if (length !== undefined) { + const end = at + Number(length); + return end <= buf.length ? end : null; + } + return null; // delimited by close +} + +function requestBytes(method, target, headers, body) { + let text = `${method} ${target} HTTP/1.1\r\n`; + for (const [name, value] of headers) text += `${name}: ${value}\r\n`; + return Buffer.concat([Buffer.from(text + "\r\n", "latin1"), body]); +} + +const dateLine = /\r\nDate: [^\r]*\r\n/; +function sameButDate(a, b) { + const ma = a.toString("latin1").match(dateLine); + const mb = b.toString("latin1").match(dateLine); + if (!ma || !mb || ma[0] === mb[0]) return false; + return a.toString("latin1").replace(dateLine, "\r\n") === b.toString("latin1").replace(dateLine, "\r\n"); +} + +function firstDifference(a, b) { + const n = Math.min(a.length, b.length); + let i = 0; + while (i < n && a[i] === b[i]) i++; + return i; +} + +function show(buf) { + const head = buf.subarray(0, Math.max(0, buf.indexOf("\r\n\r\n"))).toString("latin1"); + return { head: head.split("\r\n"), bodyBytes: buf.length - head.length - 4 }; +} + + +let dateRetries=0; +const records=[]; +async function reset(seed,id) { + const r=await fetch(`http://server:5001/begin?seed=${seed}&case=${encodeURIComponent(id)}`); + if (!r.ok) throw Error("entropy reset failed"); +} +async function compare(c) { + const bytes=requestBytes(c.method||"GET",c.target,c.headers,c.body||Buffer.alloc(0)); + for(let attempt=0;attempt<5;attempt++) { + await reset(c.seed,c.id); + const node=await exchange(NODE,bytes,c.method==="HEAD"); + const rust=await exchange(RUST,bytes,c.method==="HEAD"); + const fallback=rust.toString("latin1",0,16).startsWith("HTTP/1.1 502"); + const status=Number(node.toString("latin1").split(" ")[1]); + const unexpectedFallback=!!c.served&&(fallback||status!==(c.status||200)); + if(!fallback&&!node.equals(rust)&&sameButDate(node,rust)){dateRetries++;continue;} + const equal=node.equals(rust); + records.push({id:c.id,method:c.method||"GET",target:c.target,seed:c.seed,expectedServed:c.served,node:node.toString("base64"),rust:rust.toString("base64"),fallback,equal,unexpectedFallback}); + return {id:c.id,fallback,equal,unexpectedFallback,...(!fallback&&!equal?{node:node.toString(),rust:rust.toString()}:{}),...(!c.served&&!fallback?{unexpectedServe:true}:{})}; + } + throw Error(`${c.id}: Date differed five times`); +} +async function main(){ + const tokens=await fetch("http://server:5001/participant-read-tokens").then(r=>r.json()); + const oidc=await fetch("http://server:5001/tokens").then(r=>r.json()); + const {fixtures}=require("/app/characterization/comments-cases.cjs"); + const {seedVote}=require("/app/characterization/seed-vote.cjs"); + const {Pool}=require("/app/node_modules/pg"); + const pool=new Pool({connectionString:process.env.DATABASE_URL}); + if(new URL(process.env.DATABASE_URL).pathname!=="/p027")throw Error("disposable fixture database required"); + const zero=fixtures.find(f=>f.shape==="content-edges"); + const nonzero=fixtures.find(f=>f.participantPid>0); + const chosen=[zero,nonzero]; + const cases=[],results=[]; + function add(id,fixture,mine,auth,tail="",served=true,method="GET",extra=[],body="") { + const c={id,seed:"7ac001000001",method,target:`/api/v3/votes${mine?"/me":""}?conversation_id=${fixture.capability}${tail}`,served, + headers:[["Host","localhost"],["Connection","close"],...(auth?[["Authorization",auth]]:[]),...extra],body:Buffer.from(body)}; + cases.push(c);return c; + } + async function run(...args){const c=add(...args);results.push(await compare(c));} + for(const f of chosen) { + await pool.query("DELETE FROM votes WHERE zid=$1",[f.zid]); + await pool.query("DELETE FROM votes_latest_unique WHERE zid=$1",[f.zid]); + // Make each OIDC identity an existing member, while leaving its token without + // a PID. /me must preserve the difference between lookup and auth parameters. + let next=40; + for(const uid of [1,2,200001,200004]) { + await pool.query("INSERT INTO participants(zid,pid,uid) SELECT $1,$2,$3 WHERE NOT EXISTS(SELECT 1 FROM participants WHERE zid=$1 AND uid=$3)",[f.zid,next++,uid]); + } + } + for(const phase of ["empty","single","multiple"]) { + if(phase!=="empty") for(const f of chosen) { + const tid=phase==="single"?700:701; + const meaning=phase==="single"?"agree":"disagree"; + await pool.query("INSERT INTO votes(zid,pid,tid,vote,weight_x_32767,created,high_priority) VALUES($1,$2,$3,$4,$5,$6,$7)",[f.zid,f.participantPid,tid,seedVote(meaning),123,"1700000000123",true]); + } + for(const f of chosen) for(const mine of [false,true]) { + const label=`${phase}/${f===zero?"pid-zero":"pid-nonzero"}/${mine?"mine":"list"}`; + const memberServed=phase!=="multiple"; + await run(label+"/unauthenticated",f,mine,null,"",!mine); + for(const kind of ["anonymous","standard"]) { + const auth=`Bearer ${tokens[`${kind}-${f.zid}`]}`; + await run(label+`/${kind}`,f,mine,auth,"",memberServed); + await run(label+`/${kind}/head`,f,mine,auth,"",memberServed,"HEAD"); + await run(label+`/${kind}/pid-override`,f,mine,auth,"&pid=999",!mine&&(f.participantPid===0||memberServed)); + } + for(const role of ["owner","admin","comments-owner-1","comments-moderator"]) { + const auth=`Bearer ${oidc[role]}`; + await run(label+`/oidc-${role}`,f,mine,auth,"",true); + if(!mine) await run(label+`/oidc-${role}/self`,f,false,auth,"&pid=-1",true); + } + await run(label+"/xid",f,mine,`Bearer ${tokens[`xid-${f.zid}`]}`,"",false); + if(!mine) { + await run(label+"/public-pid",f,false,null,`&pid=${f.participantPid}`,memberServed); + await run(label+"/public-filter",f,false,null,`&pid=${f.participantPid}&tid=700`,true); + await run(label+"/public-missing-filter",f,false,null,`&pid=${f.participantPid}&tid=999`,true); + await run(label+"/pid-self-no-auth",f,false,null,"&pid=-1",true); + } + for(const suffix of ["&limit=1","&offset=1","&page=2","&tid=bad","&tid=700suffix","&pid=0&pid=1","&conversation_id=other"]) await run(label+"/parameter/"+suffix,f,mine,null,suffix,false); + } + } + // Admission boundaries under a populated conversation; malformed auth never + // becomes anonymous. Node remains the authority for these statuses and bytes. + for(const mine of [false,true]) { + const label=`boundary/${mine?"mine":"list"}`; + for(const name of ["missing","wrongPid","expired","future","wrongIssuer","wrongAudience","tampered"]) await run(label+"/"+name,zero,mine,`Bearer ${tokens[name]}`,"",false); + await run(label+"/foreign-conversation",zero,mine,`Bearer ${tokens[`anonymous-${nonzero.zid}`]}`,"",false); + await run(label+"/bad-token",zero,mine,"Bearer invalid","",false); + await run(label+"/cookie",zero,mine,null,"",false,"GET",[["Cookie","fixture=1"]]); + await run(label+"/body",zero,mine,null,"",false,"GET",[["Content-Type","application/json"],["Content-Length","2"]],"{}"); + await run(label+"/unknown-conversation",{...zero,capability:"absentfixture"},mine,null,"",false); + const c=add(label+"/missing-conversation",zero,mine,null,"",false);c.target=`/api/v3/votes${mine?"/me":""}`;results.push(await compare(c)); + } + for(const mine of [false,true]) { + const auth=`Bearer ${oidc["comments-moderator"]}`; + const label=`authenticated-boundary/${mine?"mine":"list"}`; + await run(label+"/unknown-conversation",{...zero,capability:"absentfixture"},mine,auth,"",false); + const c=add(label+"/missing-conversation",zero,mine,auth,"",false);c.target=`/api/v3/votes${mine?"/me":""}`;results.push(await compare(c)); + const unjoined=fixtures.find(f=>!chosen.includes(f)); + const claims=JSON.parse(Buffer.from(oidc.owner.split(".")[1],"base64url")); + const memberships=await pool.query("SELECT p.pid FROM participants p JOIN oidc_user_mappings m ON m.uid=p.uid WHERE p.zid=$1 AND m.oidc_sub=$2",[unjoined.zid,claims.sub]); + if(memberships.rowCount!==0)throw Error("no-membership control must have no membership"); + await run(label+"/no-membership",unjoined,mine,`Bearer ${oidc.owner}`,"",!mine); + } + // Deliberately invalid storage values exercise Node's preserved-invalid policy. + // Valid intentions above and below always pass through the fixture convention. + async function corruptVoteFixture(f) { + await pool.query("UPDATE votes SET vote=$1 WHERE zid=$2",[7,f.zid]); + await pool.query("UPDATE votes_latest_unique SET vote=$1 WHERE zid=$2",[7,f.zid]); + } + // Single-row values use the same fixture writer and Node's real conversion. + await pool.query("DELETE FROM votes WHERE zid=$1",[zero.zid]); + await pool.query("DELETE FROM votes_latest_unique WHERE zid=$1",[zero.zid]); + for(const meaning of ["agree","disagree","pass",null,"invalid"]) { + await pool.query("DELETE FROM votes WHERE zid=$1",[zero.zid]); + await pool.query("DELETE FROM votes_latest_unique WHERE zid=$1",[zero.zid]); + await pool.query("INSERT INTO votes(zid,pid,tid,vote,weight_x_32767,created) VALUES($1,$2,700,$3,NULL,$4)",[zero.zid,zero.participantPid,meaning===null||meaning==="invalid"?null:seedVote(meaning),"9223372036854775807"]); + if(meaning==="invalid")await corruptVoteFixture(zero); + for(const mine of [false,true]) await run(`values/${meaning}/${mine?"mine":"list"}`,zero,mine,`Bearer ${tokens[`anonymous-${zero.zid}`]}`); + } + for(const mine of [false,true]) { + const auth=`Bearer ${tokens[`anonymous-${zero.zid}`]}`; + for(const encoding of ["gzip","deflate","identity","gzip, deflate","*"]) await run(`encoding/${mine}/${encoding}`,zero,mine,auth,"",true,"GET",[["Accept-Encoding",encoding]]); + const c=add(`fresh/${mine}`,zero,mine,auth,"",true,"GET",[["If-None-Match","*"]]);c.status=304;results.push(await compare(c)); + await run(`head/${mine}`,zero,mine,auth,"",true,"HEAD"); + } + await pool.query("UPDATE conversations SET is_active=false WHERE zid=$1",[zero.zid]); + for(const mine of [false,true]) await run(`closed/${mine}`,zero,mine,`Bearer ${tokens[`anonymous-${zero.zid}`]}`); + await pool.end(); + fs.writeFileSync("/artifacts/votes-read-recordings.json",JSON.stringify({format:1,source:"direct unchanged Node listener; generated fixtures; complete HTTP bytes",records},null,2)); + if(new Set(records.map(r=>r.id)).size!==records.length)throw Error("recording names must be unique"); + const differences=results.filter(r=>r.unexpectedFallback||r.unexpectedServe||(!r.fallback&&!r.equal)); + const counters=await fetch("http://polis-api:5100/health").then(r=>r.json()); + const summary={recorded:cases.length,servedByRust:results.filter(r=>r.equal).length,handedToNode:results.filter(r=>r.fallback&&!r.unexpectedFallback).length,dateRetries,differences,counters}; + if(counters.votesReadServed!==summary.servedByRust+dateRetries||counters.votesReadFallback!==summary.handedToNode)summary.counterMismatch=true; + console.log(JSON.stringify(summary,null,2)); + if(differences.length||summary.counterMismatch||!summary.servedByRust)process.exitCode=1; +} +main().catch(e=>{console.error(e.stack);process.exitCode=2;}); diff --git a/queue-rs/polis-api/conformance/votes-read-run.sh b/queue-rs/polis-api/conformance/votes-read-run.sh new file mode 100755 index 000000000..cd9a78bec --- /dev/null +++ b/queue-rs/polis-api/conformance/votes-read-run.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Record vote reads under anonymous, participant and OIDC auth and +# compare complete Node/Rust HTTP bytes. Uses only the isolated generated stack. +# Usage: votes-read-run.sh [result.json], with unique project and P027 ports. +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:-/dev/stdout} +here="$root/server/characterization" +# Require an explicitly named disposable project and three distinct loopback ports. +python3 - <<'CHECK' +import os,re +project=os.environ.get("COMPOSE_PROJECT_NAME", "") +assert re.fullmatch(r"[a-z][a-z0-9_-]{5,63}",project), "unique project required" +ports=[int(os.environ[k]) for k in ["POLIS_RECOVERY_PG_PORT","P027_HTTP_PORT","P027_CONTROL_PORT"]] +assert len(set(ports))==3 and all(55432<=p<=65535 for p in ports) +CHECK +export P027_POSTGRES_IMAGE=${P027_POSTGRES_IMAGE:-x54pca2-postgres:local} +compose=(docker compose -f "$here/compose.yml" -f "$root/queue-rs/polis-api/conformance/compose.yml" -f "$root/queue-rs/polis-api/conformance/participant-compose.yml" -f "$root/queue-rs/polis-api/conformance/votes-read-compose.yml") +if [[ -n $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]]; then + echo "project $COMPOSE_PROJECT_NAME already has containers" >&2 + exit 1 +fi +cleanup() { "${compose[@]}" logs --no-color server polis-api >"${out%.json}-services.log" 2>&1 || true; "${compose[@]}" --profile seed down -v --remove-orphans >/dev/null 2>&1 || true; } +trap cleanup EXIT INT TERM +ready() { + for _ in $(seq 60); do + if "${compose[@]}" exec -T server node -e "fetch('http://localhost:5001/ready',{signal:AbortSignal.timeout(3000)}).then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))" >/dev/null 2>&1; then + return 0 + fi + sleep 1 + done + echo "Node readiness deadline" >&2 + return 1 +} +"${compose[@]}" up -d --pull never postgres dynamodb file-server oidc-simulator server driver +"${compose[@]}" restart server +ready +"${compose[@]}" exec -T driver node characterization/cli.cjs seed +"${compose[@]}" exec -T driver node /conformance/votes-read-seed.cjs +"${compose[@]}" exec -T driver node characterization/cli.cjs seed-comments +# Fresh caches on both sides before the first replayed request. +"${compose[@]}" restart server dynamodb +ready +"${compose[@]}" exec -T driver node -e 'fetch("http://server:5001/public-key").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/participant-public.pem",v.publicKey))' +"${compose[@]}" exec -T driver node -e 'fetch("https://oidc-simulator:3000/.well-known/jwks.json").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/read-jwks.json",JSON.stringify(v)))' +"${compose[@]}" up -d --pull never polis-api +for _ in $(seq 60); do + if "${compose[@]}" exec -T driver node -e 'fetch("http://polis-api:5100/health").then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))'; then break; fi + sleep 1 +done +"${compose[@]}" exec -T driver node /conformance/votes-read-replay.cjs >"$out" diff --git a/queue-rs/polis-api/conformance/votes-read-seed.cjs b/queue-rs/polis-api/conformance/votes-read-seed.cjs new file mode 100644 index 000000000..36ea04a35 --- /dev/null +++ b/queue-rs/polis-api/conformance/votes-read-seed.cjs @@ -0,0 +1,15 @@ +"use strict"; +// The comments recorder's foreign actor needs an owned conversation. Vote +// reads do not need the separate math-seed campaign's tables or PCA outputs. +const {Pool}=require("/app/node_modules/pg"); +const {actors}=require("/app/characterization/comments-cases.cjs"); +async function main() { + if(new URL(process.env.DATABASE_URL).pathname!=="/p027")throw Error("disposable fixture database required"); + const pool=new Pool({connectionString:process.env.DATABASE_URL}); + const actor=actors.find(a=>a.ref==="comments-foreign"); + try { + await pool.query("INSERT INTO users(uid,hname,email,is_owner,site_id,created) VALUES($1,'Generated foreign owner','foreign@example.invalid',true,$2,1700000000000)",[actor.uid,actor.site]); + await pool.query("INSERT INTO conversations(zid,owner,topic,is_active,is_draft,is_public,created,modified) VALUES(900,$1,'Foreign fixture',true,false,true,1700000000000,1700000000000)",[actor.uid]); + } finally {await pool.end();} +} +main().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/queue-rs/polis-api/src/comments.rs b/queue-rs/polis-api/src/comments.rs index 787f10e11..c5f5eb5cb 100644 --- a/queue-rs/polis-api/src/comments.rs +++ b/queue-rs/polis-api/src/comments.rs @@ -10,9 +10,7 @@ use crate::{ use anyhow::Result; use postgres::Client; -#[allow(dead_code)] -#[path = "../../polis-contracts/src/votes.rs"] -mod votes; +use crate::votes; pub const PATH: &str = "/api/v3/comments"; #[derive(Clone, Debug)] diff --git a/queue-rs/polis-api/src/main.rs b/queue-rs/polis-api/src/main.rs index 7a6d274d7..a9347274c 100644 --- a/queue-rs/polis-api/src/main.rs +++ b/queue-rs/polis-api/src/main.rs @@ -51,6 +51,10 @@ mod legacy_conversations; mod legacy_pca; mod lru; mod metadata_answers; +#[allow(dead_code)] +#[rustfmt::skip] +#[path = "../../polis-contracts/src/votes.rs"] +mod votes; mod metadata_choices; mod metadata_questions; mod metadata_read; @@ -69,6 +73,7 @@ mod recent_started; mod reports_read; mod robots; mod route; +mod votes_read; #[allow(dead_code)] #[rustfmt::skip] #[path = "../../polis-contracts/src/schema.rs"] @@ -265,6 +270,14 @@ async fn health(app: &route::App) -> Outgoing { "metadataAnswersFallback", js::Js::Num(app.metadata_answers_fallback.load(Ordering::Relaxed) as f64), ); + body.set( + "votesReadServed", + js::Js::Num(app.votes_read_served.load(Ordering::Relaxed) as f64), + ); + body.set( + "votesReadFallback", + js::Js::Num(app.votes_read_fallback.load(Ordering::Relaxed) as f64), + ); body.set( "metadataReadServed", js::Js::Num(app.metadata_read_served.load(Ordering::Relaxed) as f64), @@ -597,6 +610,8 @@ async fn dispatch_at_clock( | all_conversations::PATH | recent_activity::PATH | metadata_read::PATH + | votes_read::PATH + | votes_read::ME_PATH | metadata_answers::PATH => route::handle(app, req).await, path if delphi_result_read::matches(path) => route::handle(app, req).await, path if ops_page::matches(path) => route::handle(app, req).await, @@ -1022,6 +1037,23 @@ async fn main() -> Result<()> { )); state.read_oidc = hybrid_read::Oidc::from_env()?; } + if std::env::var("POLIS_API_VOTES_READS").ok().as_deref() == Some("1") { + let dsn = std::env::var("POLIS_API_VOTES_READ_DATABASE_URL") + .context("POLIS_API_VOTES_READ_DATABASE_URL required")?; + let read_dsn = std::env::var("READ_ONLY_DATABASE_URL") + .ok() + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| dsn.clone()); + state.votes_read_db = Some(db::Pool::new( + config::connector_for_dsn(&read_dsn, "polis-api-votes-read/1")?, + votes_read::pool_limits(), + )); + state.votes_read_auth_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-votes-read-auth/1")?, + votes_read::pool_limits(), + )); + state.read_oidc = hybrid_read::Oidc::from_env()?; + } if std::env::var("POLIS_API_METADATA_READS").ok().as_deref() == Some("1") { let dsn = std::env::var("POLIS_API_METADATA_DATABASE_URL") .context("POLIS_API_METADATA_DATABASE_URL required")?; diff --git a/queue-rs/polis-api/src/route.rs b/queue-rs/polis-api/src/route.rs index b1d3b0bc1..9eb7b3bbb 100644 --- a/queue-rs/polis-api/src/route.rs +++ b/queue-rs/polis-api/src/route.rs @@ -48,6 +48,10 @@ pub struct App { pub metadata_questions_auth_db: Option>, pub metadata_questions_served: AtomicU64, pub metadata_questions_fallback: AtomicU64, + pub votes_read_db: Option>, + pub votes_read_auth_db: Option>, + pub votes_read_served: AtomicU64, + pub votes_read_fallback: AtomicU64, pub metadata_answers_db: Option>, pub metadata_answers_auth_db: Option>, pub metadata_answers_served: AtomicU64, @@ -254,6 +258,10 @@ impl App { metadata_questions_auth_db: None, metadata_questions_served: AtomicU64::new(0), metadata_questions_fallback: AtomicU64::new(0), + votes_read_db: None, + votes_read_auth_db: None, + votes_read_served: AtomicU64::new(0), + votes_read_fallback: AtomicU64::new(0), metadata_answers_db: None, metadata_answers_auth_db: None, metadata_answers_served: AtomicU64::new(0), @@ -1033,6 +1041,13 @@ pub async fn handle(app: Arc, req: Request) -> Outgoing { app.metadata_answers_served.fetch_add(1, Ordering::Relaxed); } } + if crate::votes_read::matches(req.path()) { + if out.status == 502 { + app.votes_read_fallback.fetch_add(1, Ordering::Relaxed); + } else { + app.votes_read_served.fetch_add(1, Ordering::Relaxed); + } + } if req.path() == crate::metadata_read::PATH { if out.status == 502 { app.metadata_read_fallback.fetch_add(1, Ordering::Relaxed); @@ -1568,6 +1583,9 @@ async fn serve(app: &App, req: &Request) -> Outgoing { { return bad_gateway(); } + if crate::votes_read::matches(req.path()) && crate::votes_read::parse(app, req).is_none() { + return bad_gateway(); + } if req.path() == crate::metadata_questions::PATH && crate::metadata_questions::parse(app, req).is_none() { @@ -1860,6 +1878,9 @@ async fn serve(app: &App, req: &Request) -> Outgoing { if req.path() == crate::metadata_answers::PATH { return crate::metadata_answers::handle(app, req, res).await; } + if crate::votes_read::matches(req.path()) { + return crate::votes_read::handle(app, req, res).await; + } if req.path() == crate::metadata_questions::PATH { return crate::metadata_questions::handle(app, req, res).await; } @@ -3926,6 +3947,28 @@ mod tests { assert_eq!(redirect.status, 302); // Ordinary HTTPS middleware, unlike testConnection. } + #[tokio::test] + async fn votes_read_is_off_and_unreachable_database_is_a_handoff() { + let mut state = app(true); + let probe = || { + let mut req = request("GET", &[("host", "localhost")]); + req.target = format!("{}?conversation_id=fixture", crate::votes_read::PATH); + req + }; + assert!(state.votes_read_db.is_none()); + assert_eq!(handle(state.clone(), probe()).await.status, 502); + let pool = state.db.clone(); // This test's existing pool points at refused port 1. + Arc::get_mut(&mut state).unwrap().votes_read_db = Some(pool); + assert_eq!(handle(state.clone(), probe()).await.status, 502); + assert_eq!(state.votes_read_served.load(Ordering::Relaxed), 0); + assert_eq!(state.votes_read_fallback.load(Ordering::Relaxed), 2); + let mut secure = app(false); + let pool = secure.db.clone(); + Arc::get_mut(&mut secure).unwrap().votes_read_db = Some(pool); + let redirect = handle(secure, probe()).await; + assert_eq!(redirect.status, 302); // Ordinary HTTPS middleware, unlike testConnection. + } + #[tokio::test] async fn metadata_answers_boundaries_are_counted_node_handoffs() { let mut state = app(true); @@ -3959,6 +4002,39 @@ mod tests { assert_eq!(state.metadata_answers_fallback.load(Ordering::Relaxed), 6); } + #[tokio::test] + async fn votes_read_boundaries_are_counted_node_handoffs() { + let mut state = app(true); + let pool = state.db.clone(); + Arc::get_mut(&mut state).unwrap().votes_read_db = Some(pool); + for (method, target, headers) in [ + ("POST", crate::votes_read::PATH, vec![]), + ("OPTIONS", crate::votes_read::PATH, vec![]), + ("GET", "/api/v3/votes?unknown=1", vec![]), + ( + "GET", + crate::votes_read::PATH, + vec![("authorization", "Bearer fixture")], + ), + ( + "GET", + crate::votes_read::PATH, + vec![("cookie", "fixture=1")], + ), + ( + "GET", + crate::votes_read::PATH, + vec![("content-length", "1")], + ), + ] { + let mut req = request(method, &headers); + req.target = target.into(); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + assert_eq!(state.votes_read_served.load(Ordering::Relaxed), 0); + assert_eq!(state.votes_read_fallback.load(Ordering::Relaxed), 6); + } + #[tokio::test] async fn connection_probe_is_off_by_default_and_needs_no_database() { let mut state = app(false); diff --git a/queue-rs/polis-api/src/votes_read.rs b/queue-rs/polis-api/src/votes_read.rs new file mode 100644 index 000000000..feedeb138 --- /dev/null +++ b/queue-rs/polis-api/src/votes_read.rs @@ -0,0 +1,267 @@ +//! Latest/history reads. Unsupported identities, ambiguity and resource pressure +//! hand back before any response; the two read-only pools never use writer slots. +use crate::{ + http::{Outgoing, Request}, + js::{Js, Obj}, + route::{self, App, Res}, +}; +// Legacy participant lookup sentinel used by resolve_pidThing. +const SELF_PID: i32 = -1; + +#[allow(dead_code)] +#[rustfmt::skip] +#[path = "../../polis-contracts/src/votes_read.rs"] +mod contract; +pub use contract::{ME_PATH, PATH}; +pub fn matches(path: &str) -> bool { + path == PATH || path == ME_PATH +} +pub fn parse(app: &App, req: &Request) -> Option { + if app.votes_read_db.is_none() + || !matches(req.path()) + || !matches!(req.method.as_str(), "GET" | "HEAD") + || !req.body.is_empty() + || req.headers.get("transfer-encoding").is_some() + || req.headers.get("content-length").is_some_and(|s| s != "0") + || req.headers.get("cookie").is_some() + { + return None; + } + let mine = req.path() == ME_PATH; + if mine && req.headers.get("authorization").is_none() { + return None; + } + let raw = req.query()?; + if raw.len() > 4096 { + return None; + } + let (mut cid, mut pid, mut tid) = (None, None, None); + for (k, v) in url::form_urlencoded::parse(raw.as_bytes()) { + match k.as_ref() { + "conversation_id" if cid.is_none() => cid = Some(v.into_owned()), + "pid" if !mine && pid.is_none() => { + let n = v.parse::().ok()?; + if n.to_string() != v { + return None; + } + pid = Some(n); + } + "tid" if !mine && tid.is_none() => { + let n = v.parse::().ok()?; + if n.to_string() != v { + return None; + } + tid = Some(n); + } + _ => return None, + } + } + let cid = cid?; + if cid.is_empty() || cid.len() > 100 || !cid.bytes().all(|b| b.is_ascii_alphanumeric()) { + return None; + } + Some(contract::Request { + conversation_id: cid, + pid, + tid, + mine, + }) +} +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 1, + acquire_timeout: std::time::Duration::from_millis(15), + statement_timeout: std::time::Duration::from_millis(50), + max_lifetime: std::time::Duration::from_secs(300), + } +} +pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { + let Some(query) = parse(app, req) else { + return route::bad_gateway(); + }; + let (Some(pool), Some(auth_pool)) = (&app.votes_read_db, &app.votes_read_auth_db) else { + return route::bad_gateway(); + }; + let result = tokio::time::timeout(std::time::Duration::from_millis(75), async { + let identity = crate::hybrid_read::resolve_scoped( + req.headers.get("authorization"), + app.participant_verifier.as_deref(), + app.read_oidc.as_deref(), + auth_pool, + Some(&query.conversation_id), + ) + .await?; + let verified = req.headers.get("authorization").and_then(|raw| { + app.participant_verifier.as_deref()?.verify( + raw, + &query.conversation_id, + (crate::clock::now_ms() / 1000.0) as u64, + ) + }); + let cid = query.conversation_id.clone(); + let (zid, member_pid) = pool + .with(move |c| { + let Some(zid) = crate::db::zid_for_conversation_id(c, &cid)? else { + return Ok(None); + }; + if zid <= 0 { + return Ok(None); + } + let pid = if let Some(ref v) = verified { + let Some(pid) = polis_auth::participant::resolve(c, polis_auth::Zid(zid), v)? + else { + return Ok(None); + }; + Some(pid.0 as i32) + } else { + None + }; + Ok(Some((zid, pid))) + }) + .await + .ok() + .flatten()?; + let pid = if query.mine { + // Node checks getPid(uid), but still queries req.p.pid. Existing + // OIDC membership therefore produces [], not that member's history. + let uid = identity.uid()?; + let found = pool + .with(move |c| { + Ok(c.query( + "SELECT pid FROM participants WHERE zid=$1 AND uid=$2 LIMIT 2", + &[&zid, &uid.0], + )?) + }) + .await + .ok()?; + if found.len() != 1 || found[0].try_get::<_, i32>(0).ok()? < 0 { + return None; + } + member_pid + } else if member_pid.is_some_and(|p| p > 0) { + member_pid + } else if query.pid == Some(SELF_PID) { + if let Some(uid) = identity.uid() { + let rows = pool + .with(move |c| { + Ok(c.query( + "SELECT pid FROM participants WHERE zid=$1 AND uid=$2 LIMIT 2", + &[&zid, &uid.0], + )?) + }) + .await + .ok()?; + if rows.len() > 1 { + return None; + } + match rows.first() { + Some(row) => { + let p = row.try_get::<_, i32>(0).ok()?; + if p < 0 { + return None; + } + Some(p) + } + None => member_pid, + } + } else { + member_pid + } + } else { + query.pid.or(member_pid) + }; + // No PID is an unconditional empty latest response; SQL pid=NULL is + // likewise empty for the OIDC /me branch after getPid succeeded. + let Some(pid) = pid else { + return Some(Js::Arr(vec![])); + }; + pool.with(move |c| read(c, zid, pid, query.tid, query.mine, &query.conversation_id)) + .await + .ok() + .flatten() + }) + .await; + match result { + Ok(Some(value)) => route::json(req, res, &value), + _ => route::bad_gateway(), + } +} +/// No order is promised by either Node query. More than one row is therefore +/// handed back, as are noncanonical capability aliases and schema extensions. +/// A LIMIT bounds materialization without inventing a page or a sort order. +pub fn read( + c: &mut postgres::Client, + zid: i32, + pid: i32, + tid: Option, + mine: bool, + cid: &str, +) -> anyhow::Result> { + let rows = if mine { + c.query( + "SELECT * FROM votes WHERE zid=$1 AND pid=$2 LIMIT 2", + &[&zid, &pid], + )? + } else { + c.query("SELECT * FROM votes_latest_unique WHERE zid=$1 AND pid=$2 AND ($3::integer IS NULL OR tid=$3) LIMIT 2",&[&zid,&pid,&tid])? + }; + if rows.len() > 1 { + return Ok(None); + } + if rows.is_empty() { + return Ok(Some(Js::Arr(vec![]))); + } + let codes = c.query("SELECT zinvite FROM zinvites WHERE zid=$1 LIMIT 2", &[&zid])?; + if codes.len() != 1 || codes[0].try_get::<_, String>(0)? != cid { + return Ok(None); + } + let row = &rows[0]; + let expected = if mine { + vec![ + "zid", + "pid", + "tid", + "vote", + "weight_x_32767", + "created", + "high_priority", + ] + } else { + vec!["zid", "pid", "tid", "vote", "weight_x_32767", "modified"] + }; + if row.columns().iter().map(|c| c.name()).collect::>() != expected { + return Ok(None); + } + let mut out = Obj::new(); + out.set("pid", Js::Num(f64::from(row.try_get::<_, i32>("pid")?))); + out.set("tid", Js::Num(f64::from(row.try_get::<_, i32>("tid")?))); + let raw = row.try_get::<_, Option>("vote")?; + let wire = crate::votes::StorageConvention::CURRENT.wire_preserving_invalid(raw); + out.set( + "vote", + wire.map(|v| Js::Num(f64::from(v))).unwrap_or(Js::Null), + ); + out.set( + "weight_x_32767", + row.try_get::<_, Option>("weight_x_32767")? + .map(|v| Js::Num(f64::from(v))) + .unwrap_or(Js::Null), + ); + let time = if mine { "created" } else { "modified" }; + out.set( + time, + row.try_get::<_, Option>(time)? + .map(|v| Js::Str(v.to_string())) + .unwrap_or(Js::Null), + ); + if mine { + out.set("high_priority", Js::Bool(row.try_get("high_priority")?)); + out.set("weight", Js::Null); + } + out.set("conversation_id", Js::Str(cid.into())); + Ok(Some(Js::Arr(vec![Js::Obj(out)]))) +} + +#[cfg(all(test, feature = "db-tests"))] +#[path = "votes_read_tests.rs"] +mod tests; diff --git a/queue-rs/polis-api/src/votes_read_tests.rs b/queue-rs/polis-api/src/votes_read_tests.rs new file mode 100644 index 000000000..413992761 --- /dev/null +++ b/queue-rs/polis-api/src/votes_read_tests.rs @@ -0,0 +1,145 @@ +use super::*; +#[tokio::test] +async fn database_rows_convention_null_history_bounds_and_isolated_pressure() { + let url = std::env::var("POLIS_API_TEST_DATABASE_URL").unwrap(); + let schema = format!("vote_reads_test_{}", std::process::id()); + let setup_url = url.clone(); + let setup_schema = schema.clone(); + tokio::task::spawn_blocking(move|| { + let mut c=postgres::Client::connect(&setup_url,postgres::NoTls).unwrap(); + c.batch_execute(&format!("CREATE SCHEMA {setup_schema};SET search_path={setup_schema};CREATE TABLE zinvites(zid integer,zinvite text);CREATE TABLE votes_latest_unique(zid integer,pid integer,tid integer,vote smallint,weight_x_32767 smallint,modified bigint);CREATE TABLE votes(zid integer,pid integer,tid integer,vote smallint,weight_x_32767 smallint,created bigint,high_priority boolean);INSERT INTO zinvites VALUES(1,'fixture');")).unwrap(); + let stored=crate::votes::StorageConvention::CURRENT.encode(crate::votes::VoteChoice::Agree) as i16; + c.execute("INSERT INTO votes_latest_unique VALUES(1,0,0,$1,23,9223372036854775807)",&[&stored]).unwrap(); + c.execute("INSERT INTO votes VALUES(1,0,0,$1,23,9223372036854775807,true)",&[&stored]).unwrap(); + }).await.unwrap(); + let make_pool = || { + let mut c: postgres::Config = url.parse().unwrap(); + c.options(&format!("-c search_path={schema}")); + crate::db::Pool::new( + polis_queue_adapter::jobs::transport::Connector::Plain(Box::new(c)), + pool_limits(), + ) + }; + let pool = make_pool(); + let participation = make_pool(); + let row = pool + .with(|c| read(c, 1, 0, None, false, "fixture")) + .await + .unwrap() + .unwrap(); + let contract::Response::Latest(rows) = contract::Response::decode( + false, + false, + 200, + "application/json", + crate::js::stringify(&row).as_bytes(), + ) + .unwrap() else { + panic!("latest response") + }; + assert_eq!(rows[0].vote.0, Some(i16::from(crate::votes::WIRE_AGREE))); + assert_eq!(rows[0].modified.as_deref(), Some("9223372036854775807")); + let row = pool + .with(|c| read(c, 1, 0, None, true, "fixture")) + .await + .unwrap() + .unwrap(); + assert!(matches!( + contract::Response::decode( + true, + false, + 200, + "application/json", + crate::js::stringify(&row).as_bytes() + ) + .unwrap(), + contract::Response::History(_) + )); + assert_eq!( + pool.with(|c| read(c, 1, 0, Some(1), false, "fixture")) + .await + .unwrap(), + Some(Js::Arr(vec![])) + ); + assert!( + pool.with(|c| read(c, 1, 0, None, false, "alias")) + .await + .unwrap() + .is_none() + ); + let write_url = url.clone(); + let write_schema = schema.clone(); + tokio::task::spawn_blocking(move|| {let mut c=postgres::Client::connect(&write_url,postgres::NoTls).unwrap();c.batch_execute(&format!("SET search_path={write_schema};UPDATE votes_latest_unique SET vote=NULL,weight_x_32767=NULL,modified=NULL;")).unwrap();}).await.unwrap(); + let row = pool + .with(|c| read(c, 1, 0, None, false, "fixture")) + .await + .unwrap() + .unwrap(); + let contract::Response::Latest(rows) = contract::Response::decode( + false, + false, + 200, + "application/json", + crate::js::stringify(&row).as_bytes(), + ) + .unwrap() else { + panic!("latest response") + }; + assert_eq!(rows[0].vote.0, None); + let (ready_tx, ready_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = std::sync::mpsc::channel(); + let lock_url = url.clone(); + let lock_schema = schema.clone(); + let locked = tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&lock_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!( + "BEGIN;LOCK TABLE {lock_schema}.votes_latest_unique IN ACCESS EXCLUSIVE MODE" + )) + .unwrap(); + ready_tx.send(()).unwrap(); + release_rx + .recv_timeout(std::time::Duration::from_secs(5)) + .unwrap(); + c.batch_execute("ROLLBACK").unwrap(); + }); + ready_rx.await.unwrap(); + let stalled = pool.clone(); + let task = tokio::spawn(async move { + stalled + .with(|c| read(c, 1, 0, None, false, "fixture")) + .await + }); + assert!(participation.ping().await); + assert!(task.await.unwrap().is_err()); + release_tx.send(()).unwrap(); + locked.await.unwrap(); + let error = pool + .with(|c| Ok(c.batch_execute("DELETE FROM votes")?)) + .await + .unwrap_err(); + assert!(format!("{error:#}").contains("read-only")); + let write_url = url.clone(); + let write_schema = schema.clone(); + tokio::task::spawn_blocking(move|| {let mut c=postgres::Client::connect(&write_url,postgres::NoTls).unwrap();c.batch_execute(&format!("SET search_path={write_schema};INSERT INTO votes_latest_unique(zid,pid,tid) VALUES(1,0,1);INSERT INTO votes(zid,pid,tid) VALUES(1,0,1);")).unwrap();}).await.unwrap(); + assert!( + pool.with(|c| read(c, 1, 0, None, false, "fixture")) + .await + .unwrap() + .is_none() + ); + assert!( + pool.with(|c| read(c, 1, 0, None, true, "fixture")) + .await + .unwrap() + .is_none() + ); + tokio::task::spawn_blocking(move || { + drop(pool); + drop(participation); + let mut c = postgres::Client::connect(&url, postgres::NoTls).unwrap(); + c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) + .unwrap(); + }) + .await + .unwrap(); +} diff --git a/queue-rs/polis-contracts/src/fixtures/votes-read.json b/queue-rs/polis-contracts/src/fixtures/votes-read.json new file mode 100644 index 000000000..69cdd3fc3 --- /dev/null +++ b/queue-rs/polis-contracts/src/fixtures/votes-read.json @@ -0,0 +1,2674 @@ +[ + { + "id": "empty/pid-zero/list/unauthenticated", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/anonymous", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/anonymous/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "empty/pid-zero/list/anonymous/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/standard", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/standard/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "empty/pid-zero/list/standard/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/oidc-owner", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/oidc-owner/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/oidc-admin", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/oidc-admin/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/oidc-comments-owner-1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/oidc-comments-owner-1/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/oidc-comments-moderator", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/oidc-comments-moderator/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/xid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/public-pid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/public-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/public-missing-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/pid-self-no-auth", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/parameter/&limit=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/parameter/&offset=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/parameter/&page=2", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/parameter/&tid=bad", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "empty/pid-zero/list/parameter/&tid=700suffix", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/parameter/&pid=0&pid=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/list/parameter/&conversation_id=other", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "empty/pid-zero/mine/unauthenticated", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-zero/mine/anonymous", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/anonymous/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "empty/pid-zero/mine/anonymous/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/standard", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/standard/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "empty/pid-zero/mine/standard/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/oidc-owner", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/oidc-admin", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/oidc-comments-owner-1", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/oidc-comments-moderator", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/xid", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-zero/mine/parameter/&limit=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-zero/mine/parameter/&offset=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-zero/mine/parameter/&page=2", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-zero/mine/parameter/&tid=bad", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-zero/mine/parameter/&tid=700suffix", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-zero/mine/parameter/&pid=0&pid=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-zero/mine/parameter/&conversation_id=other", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-nonzero/list/unauthenticated", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/anonymous", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/anonymous/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "empty/pid-nonzero/list/anonymous/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/standard", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/standard/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "empty/pid-nonzero/list/standard/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/oidc-owner", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/oidc-owner/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/oidc-admin", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/oidc-admin/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/oidc-comments-owner-1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/oidc-comments-owner-1/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/oidc-comments-moderator", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/oidc-comments-moderator/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/xid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/public-pid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/public-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/public-missing-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/pid-self-no-auth", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/parameter/&limit=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/parameter/&offset=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/parameter/&page=2", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/parameter/&tid=bad", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "empty/pid-nonzero/list/parameter/&tid=700suffix", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/parameter/&pid=0&pid=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/list/parameter/&conversation_id=other", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "empty/pid-nonzero/mine/unauthenticated", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-nonzero/mine/anonymous", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/anonymous/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "empty/pid-nonzero/mine/anonymous/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/standard", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/standard/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "empty/pid-nonzero/mine/standard/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/oidc-owner", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/oidc-admin", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/oidc-comments-owner-1", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/oidc-comments-moderator", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/xid", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "empty/pid-nonzero/mine/parameter/&limit=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-nonzero/mine/parameter/&offset=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-nonzero/mine/parameter/&page=2", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-nonzero/mine/parameter/&tid=bad", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-nonzero/mine/parameter/&tid=700suffix", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-nonzero/mine/parameter/&pid=0&pid=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "empty/pid-nonzero/mine/parameter/&conversation_id=other", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-zero/list/unauthenticated", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/anonymous", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/list/anonymous/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "single/pid-zero/list/anonymous/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/standard", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/list/standard/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "single/pid-zero/list/standard/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/oidc-owner", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/oidc-owner/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/oidc-admin", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/oidc-admin/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/oidc-comments-owner-1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/oidc-comments-owner-1/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/oidc-comments-moderator", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/oidc-comments-moderator/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/xid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/list/public-pid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/list/public-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/list/public-missing-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/pid-self-no-auth", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/parameter/&limit=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/parameter/&offset=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/parameter/&page=2", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/parameter/&tid=bad", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "single/pid-zero/list/parameter/&tid=700suffix", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/parameter/&pid=0&pid=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/list/parameter/&conversation_id=other", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "single/pid-zero/mine/unauthenticated", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-zero/mine/anonymous", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/mine/anonymous/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "single/pid-zero/mine/anonymous/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/mine/standard", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/mine/standard/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "single/pid-zero/mine/standard/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/mine/oidc-owner", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/mine/oidc-admin", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/mine/oidc-comments-owner-1", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/mine/oidc-comments-moderator", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-zero/mine/xid", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "single/pid-zero/mine/parameter/&limit=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-zero/mine/parameter/&offset=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-zero/mine/parameter/&page=2", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-zero/mine/parameter/&tid=bad", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-zero/mine/parameter/&tid=700suffix", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-zero/mine/parameter/&pid=0&pid=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-zero/mine/parameter/&conversation_id=other", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-nonzero/list/unauthenticated", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/anonymous", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/list/anonymous/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "single/pid-nonzero/list/anonymous/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/list/standard", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/list/standard/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "single/pid-nonzero/list/standard/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/list/oidc-owner", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/oidc-owner/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/oidc-admin", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/oidc-admin/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/oidc-comments-owner-1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/oidc-comments-owner-1/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/oidc-comments-moderator", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/oidc-comments-moderator/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/xid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/list/public-pid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/list/public-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/list/public-missing-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/pid-self-no-auth", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/parameter/&limit=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/parameter/&offset=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/parameter/&page=2", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/parameter/&tid=bad", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "single/pid-nonzero/list/parameter/&tid=700suffix", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/parameter/&pid=0&pid=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/list/parameter/&conversation_id=other", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "single/pid-nonzero/mine/unauthenticated", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-nonzero/mine/anonymous", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/mine/anonymous/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "single/pid-nonzero/mine/anonymous/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/mine/standard", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/mine/standard/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "single/pid-nonzero/mine/standard/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/mine/oidc-owner", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/mine/oidc-admin", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/mine/oidc-comments-owner-1", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/mine/oidc-comments-moderator", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "single/pid-nonzero/mine/xid", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "single/pid-nonzero/mine/parameter/&limit=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-nonzero/mine/parameter/&offset=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-nonzero/mine/parameter/&page=2", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-nonzero/mine/parameter/&tid=bad", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-nonzero/mine/parameter/&tid=700suffix", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-nonzero/mine/parameter/&pid=0&pid=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "single/pid-nonzero/mine/parameter/&conversation_id=other", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-zero/list/unauthenticated", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/anonymous", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/list/anonymous/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "multiple/pid-zero/list/anonymous/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/standard", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/list/standard/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "multiple/pid-zero/list/standard/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/oidc-owner", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/oidc-owner/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/oidc-admin", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/oidc-admin/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/oidc-comments-owner-1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/oidc-comments-owner-1/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/oidc-comments-moderator", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/oidc-comments-moderator/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/xid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/list/public-pid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/list/public-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/list/public-missing-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/pid-self-no-auth", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/parameter/&limit=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/parameter/&offset=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/parameter/&page=2", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/parameter/&tid=bad", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "multiple/pid-zero/list/parameter/&tid=700suffix", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/parameter/&pid=0&pid=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/list/parameter/&conversation_id=other", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "multiple/pid-zero/mine/unauthenticated", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-zero/mine/anonymous", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/mine/anonymous/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "multiple/pid-zero/mine/anonymous/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/mine/standard", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/mine/standard/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "multiple/pid-zero/mine/standard/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/mine/oidc-owner", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/mine/oidc-admin", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/mine/oidc-comments-owner-1", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/mine/oidc-comments-moderator", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-zero/mine/xid", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "multiple/pid-zero/mine/parameter/&limit=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-zero/mine/parameter/&offset=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-zero/mine/parameter/&page=2", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-zero/mine/parameter/&tid=bad", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-zero/mine/parameter/&tid=700suffix", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-zero/mine/parameter/&pid=0&pid=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-zero/mine/parameter/&conversation_id=other", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-nonzero/list/unauthenticated", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/anonymous", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/list/anonymous/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "multiple/pid-nonzero/list/anonymous/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/list/standard", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/list/standard/head", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "multiple/pid-nonzero/list/standard/pid-override", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/list/oidc-owner", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/oidc-owner/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/oidc-admin", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/oidc-admin/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/oidc-comments-owner-1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/oidc-comments-owner-1/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/oidc-comments-moderator", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/oidc-comments-moderator/self", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/xid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/list/public-pid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/list/public-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/list/public-missing-filter", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/pid-self-no-auth", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/parameter/&limit=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/parameter/&offset=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/parameter/&page=2", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/parameter/&tid=bad", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "multiple/pid-nonzero/list/parameter/&tid=700suffix", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/parameter/&pid=0&pid=1", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/list/parameter/&conversation_id=other", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "multiple/pid-nonzero/mine/unauthenticated", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-nonzero/mine/anonymous", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/mine/anonymous/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "multiple/pid-nonzero/mine/anonymous/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/mine/standard", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/mine/standard/head", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "multiple/pid-nonzero/mine/standard/pid-override", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/mine/oidc-owner", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/mine/oidc-admin", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/mine/oidc-comments-owner-1", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/mine/oidc-comments-moderator", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "multiple/pid-nonzero/mine/xid", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":1,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"},{\"pid\":1,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"created\":\"1700000000123\",\"high_priority\":true,\"weight\":null,\"conversation_id\":\"2p027r61003\"}]" + }, + { + "id": "multiple/pid-nonzero/mine/parameter/&limit=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-nonzero/mine/parameter/&offset=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-nonzero/mine/parameter/&page=2", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-nonzero/mine/parameter/&tid=bad", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-nonzero/mine/parameter/&tid=700suffix", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-nonzero/mine/parameter/&pid=0&pid=1", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "multiple/pid-nonzero/mine/parameter/&conversation_id=other", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "boundary/list/missing", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"},{\"pid\":0,\"tid\":701,\"vote\":1,\"weight_x_32767\":123,\"modified\":\"1700000000123\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "boundary/list/wrongPid", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "boundary/list/expired", + "mine": false, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}" + }, + { + "id": "boundary/list/future", + "mine": false, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt not active\"}" + }, + { + "id": "boundary/list/wrongIssuer", + "mine": false, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt issuer invalid. expected: https://pol.is/\"}" + }, + { + "id": "boundary/list/wrongAudience", + "mine": false, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt audience invalid. expected: participants\"}" + }, + { + "id": "boundary/list/tampered", + "mine": false, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}" + }, + { + "id": "boundary/list/foreign-conversation", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "boundary/list/bad-token", + "mine": false, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid token format\",\"details\":\"Token does not match any supported JWT type\"}" + }, + { + "id": "boundary/list/cookie", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "boundary/list/body", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "boundary/list/unknown-conversation", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "boundary/list/missing-conversation", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "boundary/mine/missing", + "mine": true, + "head": false, + "status": 500, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"polis_err_getting_pid\",\"message\":\"polis_err_getting_pid\",\"status\":500}" + }, + { + "id": "boundary/mine/wrongPid", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "boundary/mine/expired", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}" + }, + { + "id": "boundary/mine/future", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt not active\"}" + }, + { + "id": "boundary/mine/wrongIssuer", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt issuer invalid. expected: https://pol.is/\"}" + }, + { + "id": "boundary/mine/wrongAudience", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt audience invalid. expected: participants\"}" + }, + { + "id": "boundary/mine/tampered", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}" + }, + { + "id": "boundary/mine/foreign-conversation", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "boundary/mine/bad-token", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"Invalid token format\",\"details\":\"Token does not match any supported JWT type\"}" + }, + { + "id": "boundary/mine/cookie", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "boundary/mine/body", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "boundary/mine/unknown-conversation", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "boundary/mine/missing-conversation", + "mine": true, + "head": false, + "status": 401, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"No authentication token found\"}" + }, + { + "id": "authenticated-boundary/list/unknown-conversation", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "authenticated-boundary/list/missing-conversation", + "mine": false, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "authenticated-boundary/list/no-membership", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[]" + }, + { + "id": "authenticated-boundary/mine/unknown-conversation", + "mine": true, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "authenticated-boundary/mine/missing-conversation", + "mine": true, + "head": false, + "status": 400, + "content_type": "text/html; charset=utf-8", + "body": "Bad Request\n" + }, + { + "id": "authenticated-boundary/mine/no-membership", + "mine": true, + "head": false, + "status": 500, + "content_type": "application/json; charset=utf-8", + "body": "{\"error\":\"polis_err_getting_pid\",\"message\":\"polis_err_getting_pid\",\"status\":500}" + }, + { + "id": "values/agree/list", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/agree/mine", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":-1,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/disagree/list", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":1,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/disagree/mine", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":1,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/pass/list", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":0,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/pass/mine", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":0,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/null/list", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":null,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/null/mine", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":null,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/invalid/list", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "values/invalid/mine", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/false/gzip", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/false/deflate", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/false/identity", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/false/gzip, deflate", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/false/*", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "fresh/false", + "mine": false, + "head": false, + "status": 304, + "content_type": "", + "body": "" + }, + { + "id": "head/false", + "mine": false, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "encoding/true/gzip", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/true/deflate", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/true/identity", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/true/gzip, deflate", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "encoding/true/*", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "fresh/true", + "mine": true, + "head": false, + "status": 304, + "content_type": "", + "body": "" + }, + { + "id": "head/true", + "mine": true, + "head": true, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "" + }, + { + "id": "closed/false", + "mine": false, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"modified\":\"9223372036854775807\",\"conversation_id\":\"2p027r61033\"}]" + }, + { + "id": "closed/true", + "mine": true, + "head": false, + "status": 200, + "content_type": "application/json; charset=utf-8", + "body": "[{\"pid\":0,\"tid\":700,\"vote\":7,\"weight_x_32767\":null,\"created\":\"9223372036854775807\",\"high_priority\":false,\"weight\":null,\"conversation_id\":\"2p027r61033\"}]" + } +] diff --git a/queue-rs/polis-contracts/src/lib.rs b/queue-rs/polis-contracts/src/lib.rs index dfb101430..ca852abf5 100644 --- a/queue-rs/polis-contracts/src/lib.rs +++ b/queue-rs/polis-contracts/src/lib.rs @@ -52,6 +52,7 @@ pub mod treevite_waves; pub mod user_create_page; pub mod user_login_page; pub mod user_logout_page; +pub mod votes_read; /// Byte-stable JSON shared by the Delphi contracts. pub mod wire; pub mod xid_report; diff --git a/queue-rs/polis-contracts/src/votes.rs b/queue-rs/polis-contracts/src/votes.rs index 089f8296a..26598abf0 100644 --- a/queue-rs/polis-contracts/src/votes.rs +++ b/queue-rs/polis-contracts/src/votes.rs @@ -89,6 +89,15 @@ impl StorageConvention { _ => None, } } + /// Read routes use Node's onInvalid=keep policy: null stays null and an + /// invalid legacy integer is returned unchanged, never interpreted as pass. + pub fn wire_preserving_invalid(self, raw: Option) -> Option { + raw.map(|n| { + self.decode(Some(i32::from(n))) + .map(|v| i16::from(v.wire())) + .unwrap_or(n) + }) + } pub fn encode(self, vote: VoteChoice) -> i32 { match vote { VoteChoice::Agree => self.agree, @@ -106,6 +115,10 @@ mod storage_tests { let convention = StorageConvention { agree }; for vote in [VoteChoice::Agree, VoteChoice::Disagree, VoteChoice::Pass] { assert_eq!(convention.decode(Some(convention.encode(vote))), Some(vote)); + assert_eq!( + convention.wire_preserving_invalid(Some(convention.encode(vote) as i16)), + Some(i16::from(vote.wire())) + ); } for raw in [None, Some(2), Some(-2)] { assert_eq!(convention.decode(raw), None); diff --git a/queue-rs/polis-contracts/src/votes_read.rs b/queue-rs/polis-contracts/src/votes_read.rs new file mode 100644 index 000000000..aadf7fa85 --- /dev/null +++ b/queue-rs/polis-contracts/src/votes_read.rs @@ -0,0 +1,318 @@ +//! GET vote contracts at 4f50b6f28f30160a9d8a0ca3f3024ef3c03b6ec2. +//! Registration/auth/parameters: server/app.ts:868-892. Latest rows: +//! server/src/routes/votes.ts:132-172,204-211. History: :175-202. +//! Both call storageRowToWire (:168,:197), preserving null/invalid integers; +//! wire signs belong to votes.rs, independently of storage and CSV exports. +//! finishArray removes zid and appends conversation_id (server-helpers.ts:174-192,241-272). +//! Neither handler sorts or paginates. /me additionally appends weight:null: +//! the selected table has weight_x_32767, so undefined / 32767 is NaN. +use serde::{Deserialize, Serialize}; + +pub const PATH: &str = "/api/v3/votes"; +pub const ME_PATH: &str = "/api/v3/votes/me"; +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Request { + pub conversation_id: String, + pub pid: Option, + pub tid: Option, + pub mine: bool, +} +/// Includes null and legacy invalid integers, which Node preserves verbatim. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(transparent)] +pub struct WireVote(pub Option); +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct LatestVote { + pub pid: i32, + pub tid: i32, + pub vote: WireVote, + pub weight_x_32767: Option, + /// pg's default int8 parser returns decimal text, including unsafe integers. + pub modified: Option, + pub conversation_id: String, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct HistoryVote { + pub pid: i32, + pub tid: i32, + pub vote: WireVote, + pub weight_x_32767: Option, + pub created: Option, + pub high_priority: bool, + pub weight: (), + pub conversation_id: String, +} +pub type LatestResponse = Vec; +pub type HistoryResponse = Vec; +/// failJson: utils/fail.ts:12-24. Route error names are listed below. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Failure { + pub error: String, + pub message: String, + pub status: u16, +} +/// hybrid-jwt.ts:86-88,223-226,237-240 (details absent for missing auth). +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct AuthFailure { + pub error: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub details: Option, +} +/// jwt-middleware.ts:106-164; existing-user resolution can also create users in +/// Node. Rust never takes those branches. Debug details are dev-mode only. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct UserFailure { + pub error: String, + pub message: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub retry_after: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub details: Option, +} +/// All response families of the Node listener, not a claim of Rust admission. +/// The listener can reject framing/parser/HTTPS policy before either handler. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum Response { + Latest(LatestResponse), + History(HistoryResponse), + Failure(Failure), + Auth(AuthFailure), + User(UserFailure), + /// 302 HTTPS redirect; 400/413/415 production finalhandler HTML; + /// 500 unhandled errors. Preserve bytes (dev mode may include a stack). + Listener { + status: u16, + body: Vec, + }, + /// HEAD and conditional GET/HEAD (304) have no body. + Empty { + status: u16, + }, +} +pub const ROUTE_ERRORS: &[&str] = &[ + "polis_err_getting_pid", + "polis_err_get_votes_by_me", + "polis_err_votes_get", + "polis_err_mypid_resolve_error", + "polis_err_this_middleware_should_be_after_auth_and_zid", + "polis_err_finishing_response2A", + "polis_err_finishing_response2", + "polis_err_misc", +]; +impl Response { + pub fn decode( + mine: bool, + head: bool, + status: u16, + content_type: &str, + body: &[u8], + ) -> Result { + if (head || status == 304) && body.is_empty() { + return Ok(Self::Empty { status }); + } + let parse = |e: serde_json::Error| e.to_string(); + if status == 200 { + return if mine { + serde_json::from_slice(body) + .map(Self::History) + .map_err(parse) + } else { + serde_json::from_slice(body) + .map(Self::Latest) + .map_err(parse) + }; + } + if !content_type.starts_with("application/json") + && [302, 400, 413, 415, 500].contains(&status) + { + return Ok(Self::Listener { + status, + body: body.to_vec(), + }); + } + if status == 401 { + return serde_json::from_slice(body).map(Self::Auth).map_err(parse); + } + match serde_json::from_slice::(body) { + Ok(f) + if [400, 500].contains(&status) + && f.status == status + && f.error == f.message + && ROUTE_ERRORS.contains(&f.error.as_str()) => + { + return Ok(Self::Failure(f)) + } + _ => (), + } + if [400, 429, 500].contains(&status) { + let f: UserFailure = serde_json::from_slice(body).map_err(parse)?; + if matches!( + (status, f.error.as_str()), + (400, "invalid_user_data") + | (429, "too_many_requests" | "authentication_conflict") + | (500, "user_creation_failed" | "authentication_error") + ) { + return Ok(Self::User(f)); + } + } + Err("uncovered response".into()) + } +} +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn direct_node_recordings_decode_and_successes_roundtrip() { + #[derive(Deserialize)] + struct Case { + id: String, + mine: bool, + head: bool, + status: u16, + content_type: String, + body: String, + } + let cases: Vec = + serde_json::from_str(include_str!("fixtures/votes-read.json")).unwrap(); + for c in cases { + let response = + Response::decode(c.mine, c.head, c.status, &c.content_type, c.body.as_bytes()) + .unwrap_or_else(|e| panic!("{}: {e}", c.id)); + let encoded = match response { + Response::Latest(rows) => Some(serde_json::to_string(&rows).unwrap()), + Response::History(rows) => Some(serde_json::to_string(&rows).unwrap()), + _ => None, + }; + if let Some(encoded) = encoded { + assert_eq!(encoded, c.body, "{}", c.id); + } + } + } + #[test] + fn latest_codec_preserves_null_and_bigint_text() { + for raw in [ + None, + Some(i16::from(crate::votes::WIRE_AGREE)), + Some(i16::from(crate::votes::WIRE_DISAGREE)), + Some(i16::from(crate::votes::WIRE_PASS)), + Some(7), + ] { + let row = LatestVote { + pid: 0, + tid: 2, + vote: WireVote(raw), + weight_x_32767: None, + modified: Some("9223372036854775807".into()), + conversation_id: "fixture".into(), + }; + let body = serde_json::to_vec(&vec![row.clone()]).unwrap(); + assert_eq!( + Response::decode(false, false, 200, "application/json", &body).unwrap(), + Response::Latest(vec![row]) + ); + } + } + #[test] + fn history_codec_keeps_null_weight_and_all_events() { + let row = HistoryVote { + pid: 0, + tid: 2, + vote: WireVote(None), + weight_x_32767: Some(12), + created: None, + high_priority: false, + weight: (), + conversation_id: "fixture".into(), + }; + let body = serde_json::to_vec(&vec![row.clone(), row.clone()]).unwrap(); + assert!(String::from_utf8(body.clone()) + .unwrap() + .contains("\"weight\":null")); + assert_eq!( + Response::decode(true, false, 200, "application/json", &body).unwrap(), + Response::History(vec![row.clone(), row]) + ); + assert!(Response::decode(false, false, 200, "application/json", &body).is_err()); + } + #[test] + fn error_and_listener_families_remain_distinct() { + for error in ROUTE_ERRORS { + let status = if *error == "polis_err_misc" { 400 } else { 500 }; + let row = Failure { + error: (*error).into(), + message: (*error).into(), + status, + }; + assert_eq!( + Response::decode( + false, + false, + status, + "application/json", + &serde_json::to_vec(&row).unwrap() + ) + .unwrap(), + Response::Failure(row) + ); + } + for details in [None, Some("jwt expired".into())] { + let row = AuthFailure { + error: "Invalid authentication token".into(), + details, + }; + assert_eq!( + Response::decode( + true, + false, + 401, + "application/json", + &serde_json::to_vec(&row).unwrap() + ) + .unwrap(), + Response::Auth(row) + ); + } + for (status, error) in [ + (400, "invalid_user_data"), + (429, "too_many_requests"), + (429, "authentication_conflict"), + (500, "user_creation_failed"), + (500, "authentication_error"), + ] { + let row = UserFailure { + error: error.into(), + message: "fixture".into(), + retry_after: if status == 429 { Some(1) } else { None }, + details: None, + }; + assert_eq!( + Response::decode( + true, + false, + status, + "application/json", + &serde_json::to_vec(&row).unwrap() + ) + .unwrap(), + Response::User(row) + ); + } + for status in [302, 400, 413, 415, 500] { + assert!(matches!( + Response::decode(false, false, status, "text/html", b"fixture"), + Ok(Response::Listener { .. }) + )); + } + assert_eq!( + Response::decode(false, false, 304, "", b"").unwrap(), + Response::Empty { status: 304 } + ); + assert!(Response::decode(false, false, 200, "application/json", b"{}").is_err()); + assert!(Response::decode(false, false, 502, "text/plain", b"handoff").is_err()); + } +} From 1b931d1c0febabd2618eb5753817e44d61105803 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Wed, 21 Oct 2026 11:31:19 -0700 Subject: [PATCH 20/30] version: one Polis version, embedded with the commit and the distance from stable in every build (#3246) * version: one Polis version, embedded with the commit and the distance from stable in every build The root VERSION file holds the Polis version; the server, the three browser clients and the CLI embed it with the full build commit and, off a tagged stable build, the distance from the last stable, rendering 2.x.y+dev.N.. polis --version, a server version route and the admin's About page report the same string; a source run without the generated build file falls back to the VERSION file. No tag, release or workflow change; the updater keeps its contract. Co-Authored-By: Claude Fable 5.1 * version: the bootstrap number is 2.41.0 under the effective-selection rule Co-Authored-By: Claude Fable 5.1 --------- Co-authored-by: Claude Fable 5.1 --- .dockerignore | 13 ++ .gitignore | 7 ++ Makefile | 6 +- VERSION | 2 +- VERSION_STABLE_COMMIT | 1 + ci/p027_rerecord_build.sh | 2 +- client-admin/Dockerfile | 17 ++- client-admin/build-identity.test.js | 21 ++++ client-admin/src/app.js | 2 + client-admin/src/components/About.js | 35 ++++++ client-admin/src/components/About.test.js | 30 +++++ client-admin/src/components/MainLayout.js | 3 + client-admin/webpack.config.js | 5 + client-participation-alpha/Dockerfile | 15 ++- client-participation-alpha/astro.config.mjs | 3 + client-participation-alpha/jest.setup.js | 28 +++-- .../src/__tests__/build-info.test.ts | 16 +++ .../src/pages/build-info.json.ts | 7 ++ client-participation/Dockerfile | 17 ++- client-participation/build-identity.test.js | 23 ++++ client-participation/webpack.config.js | 7 +- client-report/Dockerfile | 22 ++-- client-report/build-identity.test.js | 21 ++++ client-report/webpack.common.js | 6 +- delphi/tests/test_build_images.py | 6 +- deploy/build-images.sh | 4 +- deploy/build-on-box.sh | 9 ++ docker-compose.test.yml | 27 ++-- docker-compose.yml | 33 +++-- docs/configuration.md | 4 +- docs/deployment-configuration.md | 2 +- file-server/Dockerfile | 32 ++++- polis-cli/crates/polis/build.rs | 83 ++++++++---- polis-cli/crates/polis/src/commands.rs | 2 +- polis-cli/crates/polis/tests/update.rs | 5 +- polis-cli/crates/polis/tests/version.rs | 5 +- polis-cli/tests/differential/README.md | 2 +- scripts/after_install.sh | 2 +- scripts/build-identity-test.cjs | 21 ++++ scripts/build-identity.cjs | 28 +++++ scripts/build-polis-cli-release.py | 12 +- scripts/build_identity.py | 118 ++++++++++++++++++ scripts/prepare-polis-cli-differential.sh | 2 +- scripts/prove-dynamo-report.sh | 2 +- scripts/test-dynamo-removal.sh | 2 +- scripts/test-dynamo-writers.sh | 2 +- .../tests/test_polis_cli_release_identity.py | 101 +++++++++++++++ server/Dockerfile | 27 +++- server/Dockerfile.dockerignore | 23 ++++ server/__tests__/unit/version.test.ts | 77 ++++++++++++ server/app.ts | 2 + .../collective-statement/mutations.cjs | 1 + server/package.json | 7 +- server/src/routes/version.ts | 50 ++++++++ 54 files changed, 894 insertions(+), 106 deletions(-) create mode 100644 VERSION_STABLE_COMMIT create mode 100644 client-admin/build-identity.test.js create mode 100644 client-admin/src/components/About.js create mode 100644 client-admin/src/components/About.test.js create mode 100644 client-participation-alpha/src/__tests__/build-info.test.ts create mode 100644 client-participation-alpha/src/pages/build-info.json.ts create mode 100644 client-participation/build-identity.test.js create mode 100644 client-report/build-identity.test.js create mode 100644 scripts/build-identity-test.cjs create mode 100644 scripts/build-identity.cjs create mode 100644 scripts/build_identity.py create mode 100644 scripts/tests/test_polis_cli_release_identity.py create mode 100644 server/Dockerfile.dockerignore create mode 100644 server/__tests__/unit/version.test.ts create mode 100644 server/src/routes/version.ts diff --git a/.dockerignore b/.dockerignore index 6cec0a207..75c2dac8a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -94,3 +94,16 @@ client-participation/node_modules client-report/dist client-report/node_modules + +# Private configuration and local review artifacts never enter images. +**/.env +**/*.env +**/.env.* +**/.google_creds_temp +**/.venv +**/node_modules +**/dist +releases/ + +# Public templates are runtime inputs of the importer source-binding check. +!delphi/example.env diff --git a/.gitignore b/.gitignore index fa4439bb7..0b65c9a58 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,10 @@ scripts/deploy-revision.txt # Results of ci/local/ check runs .ci-out/ + +# Generated build identity +server/src/generated/build-info.ts + +# Deploy transport and instance bookkeeping must not dirty source identity. +/build-source.tar.gz +/build-box-instances.txt diff --git a/Makefile b/Makefile index 23ff6b565..7c988347a 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,11 @@ export ENV_FILE = .env # Lazy evaluation of expensive environment parsing - only when needed define get_env_vars $(eval export TAG = $(call parse_env_value,TAG)) - $(eval export GIT_HASH = $(shell git rev-parse --short HEAD)) + $(eval export GIT_HASH = $(shell git rev-parse HEAD)) + $(eval POLIS_BUILD_IDENTITY := $(shell python3 scripts/build_identity.py --format env)) + $(eval export POLIS_BUILD_DISTANCE = $(patsubst distance=%,%,$(filter distance=%,$(POLIS_BUILD_IDENTITY)))) + $(eval export POLIS_BUILD_SOURCE = $(patsubst source=%,%,$(filter source=%,$(POLIS_BUILD_IDENTITY)))) + $(eval export POLIS_BUILD_TAG = $(if $(filter channel=stable,$(POLIS_BUILD_IDENTITY)),v$(patsubst version_base=%,%,$(filter version_base=%,$(POLIS_BUILD_IDENTITY))),)) $(eval POSTGRES_DOCKER_RAW = $(shell echo $(call parse_env_value,POSTGRES_DOCKER) | tr '[:upper:]' '[:lower:]')) $(eval export POSTGRES_DOCKER = $(call parse_env_bool,$(POSTGRES_DOCKER_RAW))) $(eval LOCAL_SERVICES_DOCKER_RAW = $(shell echo $(call parse_env_value,LOCAL_SERVICES_DOCKER) | tr '[:upper:]' '[:lower:]')) diff --git a/VERSION b/VERSION index d3827e75a..2d4c52ede 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0 +2.41.0 diff --git a/VERSION_STABLE_COMMIT b/VERSION_STABLE_COMMIT new file mode 100644 index 000000000..8783c98e3 --- /dev/null +++ b/VERSION_STABLE_COMMIT @@ -0,0 +1 @@ +d2da302d0f94fb29fa0e7fde27299509c6f5f28b diff --git a/ci/p027_rerecord_build.sh b/ci/p027_rerecord_build.sh index 1c4394ca6..170dec3eb 100644 --- a/ci/p027_rerecord_build.sh +++ b/ci/p027_rerecord_build.sh @@ -5,7 +5,7 @@ set -euo pipefail export DOCKER_BUILDKIT=1 # Sequential builds bound peak memory; inspect disk receipts when sizing the runner. df -h . -docker build --target prod --build-arg NODE_ENV=production -t p027-server -f server/Dockerfile server +docker build --target prod --build-arg NODE_ENV=production -t p027-server -f server/Dockerfile . docker build --build-context queue-rs=queue-rs -t p027-postgres -f server/Dockerfile-db server docker build -t p027-oidc-simulator oidc-simulator docker build -t p027-file-server --build-arg NODE_ENV=production \ diff --git a/client-admin/Dockerfile b/client-admin/Dockerfile index 537afec3b..99ebf3bb3 100644 --- a/client-admin/Dockerfile +++ b/client-admin/Dockerfile @@ -3,6 +3,7 @@ # Instead, the file-server Dockerfile builds and serves these assets. # But this file is still useful for development or deployments that do not use # the docker compose configuration. +# Build from the repository root: docker build -f client-admin/Dockerfile . FROM docker.io/node:24-alpine @@ -10,16 +11,20 @@ FROM docker.io/node:24-alpine ARG NODE_ENV ENV NODE_ENV=${NODE_ENV:-production} -WORKDIR /app +RUN apk add --no-cache python3 -COPY package*.json ./ +WORKDIR /app/client-admin + +COPY client-admin/package*.json ./ RUN npm config set fetch-retries 5 && \ npm config set fetch-retry-mintimeout 20000 && \ npm config set fetch-retry-maxtimeout 120000 RUN --mount=type=cache,target=/root/.npm npm ci --production=false -COPY . . +COPY VERSION VERSION_STABLE_COMMIT /app/ +COPY scripts/build_identity.py scripts/build-identity.cjs /app/scripts/ +COPY client-admin/ . ARG ADMIN_UIDS ARG AUTH_AUDIENCE @@ -33,4 +38,10 @@ ENV AUTH_ISSUER=${AUTH_ISSUER} ENV AUTH_NAMESPACE=${AUTH_NAMESPACE} +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=${GIT_HASH} POLIS_BUILD_DISTANCE=${POLIS_BUILD_DISTANCE} POLIS_BUILD_TAG=${POLIS_BUILD_TAG} POLIS_BUILD_SOURCE=${POLIS_BUILD_SOURCE} + CMD ["npm", "run", "build:prod"] diff --git a/client-admin/build-identity.test.js b/client-admin/build-identity.test.js new file mode 100644 index 000000000..8e991bcb3 --- /dev/null +++ b/client-admin/build-identity.test.js @@ -0,0 +1,21 @@ +const { cases, fixture } = require('../scripts/build-identity-test.cjs') +const { BuildInfoPlugin } = require('../scripts/build-identity.cjs') +const webpack = require('webpack') + +test.each(cases)('%s build metadata', (_name, metadata, expected) => { + const info = fixture(metadata) + const assets = {} + const compilation = { + hooks: { processAssets: { tap: (_options, emit) => emit() } }, + emitAsset: (name, asset) => { assets[name] = asset.source() } + } + const compiler = { + webpack, + hooks: { thisCompilation: { tap: (_name, compile) => compile(compilation) } } + } + new BuildInfoPlugin(info, 'client').apply(compiler) + const emitted = JSON.parse(assets['client/build-info.json']) + expect(emitted.version_display).toBe(expected) + expect(emitted.commit).toBe(metadata.GIT_HASH || 'unknown') + expect(emitted.distance).toBe(metadata.POLIS_BUILD_DISTANCE === undefined ? null : Number(metadata.POLIS_BUILD_DISTANCE)) +}) diff --git a/client-admin/src/app.js b/client-admin/src/app.js index 6c5dc122c..fd839a25d 100644 --- a/client-admin/src/app.js +++ b/client-admin/src/app.js @@ -31,6 +31,7 @@ import Account from './components/conversations-and-account/Account' import Integrate from './components/conversations-and-account/Integrate' import MainLayout from './components/MainLayout' +import About from './components/About' import Ops from './components/ops/Ops' const AUTH_LOADING_TIMEOUT = 3000 @@ -152,6 +153,7 @@ const App = () => { } /> } /> } /> + } /> } /> } /> diff --git a/client-admin/src/components/About.js b/client-admin/src/components/About.js new file mode 100644 index 000000000..aacef9cf9 --- /dev/null +++ b/client-admin/src/components/About.js @@ -0,0 +1,35 @@ +import { useEffect, useState } from 'react' + +const client = process.env.POLIS_BUILD_INFO + +export default function About() { + const [server, setServer] = useState(null) + const [unavailable, setUnavailable] = useState(false) + useEffect(() => { + const controller = new AbortController() + fetch('/api/v3/version', { signal: controller.signal }) + .then((response) => { + if (!response.ok) throw new Error('Version unavailable') + return response.json() + }) + .then(setServer) + .catch(() => { if (!controller.signal.aborted) setUnavailable(true) }) + return () => controller.abort() + }, []) + return ( +
+

About Polis

+

Admin: {client.version_display}

+

Commit: {client.commit}

+

Commits ahead of stable: {client.distance ?? 'unknown'}

+ {server && <> +

Server: {server.version_display}

+

Commit: {server.commit}

+

Commits ahead of stable: {server.distance ?? 'unknown'}

+

{server.commit === client.commit && server.version_display === client.version_display + ? 'Client and server builds match.' : 'Client and server builds differ.'}

+ } + {unavailable &&

Server version unavailable.

} +
+ ) +} diff --git a/client-admin/src/components/About.test.js b/client-admin/src/components/About.test.js new file mode 100644 index 000000000..3d8088ece --- /dev/null +++ b/client-admin/src/components/About.test.js @@ -0,0 +1,30 @@ +import { render, screen } from '@testing-library/react' +const { cases, fixture } = require('../../../scripts/build-identity-test.cjs') + +const original = process.env +let About +beforeAll(() => { + process.env = { ...original, POLIS_BUILD_INFO: fixture(cases[1][1]) } + About = require('./About').default +}) +afterAll(() => { process.env = original }) +afterEach(() => { delete global.fetch }) + +test.each(cases)('shows %s server identity', async (_name, metadata, expected) => { + global.fetch = jest.fn().mockResolvedValue({ ok: true, json: async () => fixture(metadata) }) + render() + expect(screen.getByText('Admin: 2.40.0+dev.16.aaaaaaaaaaaa')).toBeInTheDocument() + expect(await screen.findByText(`Server: ${expected}`)).toBeInTheDocument() + expect(screen.getByText(expected === '2.40.0+dev.16.aaaaaaaaaaaa' + ? 'Client and server builds match.' : 'Client and server builds differ.')).toBeInTheDocument() +}) +test('shows matching builds', async () => { + global.fetch = jest.fn().mockResolvedValue({ ok: true, json: async () => fixture(cases[1][1]) }) + render() + expect(await screen.findByText('Client and server builds match.')).toBeInTheDocument() +}) +test('shows unavailable server', async () => { + global.fetch = jest.fn().mockRejectedValue(new Error('unavailable')) + render() + expect(await screen.findByText('Server version unavailable.')).toBeInTheDocument() +}) diff --git a/client-admin/src/components/MainLayout.js b/client-admin/src/components/MainLayout.js index 1fe59a73a..619bbce7c 100644 --- a/client-admin/src/components/MainLayout.js +++ b/client-admin/src/components/MainLayout.js @@ -48,6 +48,9 @@ const MainLayout = () => { Account + + About + {ops ? ( diff --git a/client-admin/webpack.config.js b/client-admin/webpack.config.js index 646a6cd03..47fa37008 100644 --- a/client-admin/webpack.config.js +++ b/client-admin/webpack.config.js @@ -1,3 +1,6 @@ +import identityTools from '../scripts/build-identity.cjs' +const { buildIdentity, BuildInfoPlugin } = identityTools +const buildInfo = buildIdentity() import { config } from 'dotenv' config() import path from 'path' @@ -126,7 +129,9 @@ export default (env, argv) => { } ] }), + new BuildInfoPlugin(buildInfo, 'admin'), new webpack.DefinePlugin({ + 'process.env.POLIS_BUILD_INFO': JSON.stringify(buildInfo), 'process.env.ADMIN_UIDS': JSON.stringify(process.env.ADMIN_UIDS), 'process.env.AUTH_AUDIENCE': JSON.stringify(process.env.AUTH_AUDIENCE), 'process.env.AUTH_CLIENT_ID': JSON.stringify(process.env.AUTH_CLIENT_ID), diff --git a/client-participation-alpha/Dockerfile b/client-participation-alpha/Dockerfile index 6f18fd58b..6ef433c98 100644 --- a/client-participation-alpha/Dockerfile +++ b/client-participation-alpha/Dockerfile @@ -14,14 +14,23 @@ ENV PUBLIC_OIDC_CACHE_KEY_PREFIX=$OIDC_CACHE_KEY_PREFIX ENV PUBLIC_OIDC_CACHE_KEY_ID_TOKEN_SUFFIX=$OIDC_CACHE_KEY_ID_TOKEN_SUFFIX ENV PUBLIC_AUTH_NAMESPACE=$PUBLIC_AUTH_NAMESPACE -COPY package*.json ./ +COPY client-participation-alpha/package*.json ./ +RUN apk add --no-cache python3 RUN npm config set fetch-retries 5 && \ npm config set fetch-retry-mintimeout 20000 && \ npm config set fetch-retry-maxtimeout 120000 RUN --mount=type=cache,target=/root/.npm npm ci -COPY . . +COPY client-participation-alpha/. . + +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=$GIT_HASH POLIS_BUILD_DISTANCE=$POLIS_BUILD_DISTANCE POLIS_BUILD_TAG=$POLIS_BUILD_TAG POLIS_BUILD_SOURCE=$POLIS_BUILD_SOURCE +COPY VERSION VERSION_STABLE_COMMIT / +COPY scripts/build_identity.py scripts/build-identity.cjs /scripts/ RUN npm run build EXPOSE 4321 -CMD ["node", "dist/server/entry.mjs"] \ No newline at end of file +CMD ["node", "dist/server/entry.mjs"] diff --git a/client-participation-alpha/astro.config.mjs b/client-participation-alpha/astro.config.mjs index 368c5388b..70bcee2b3 100644 --- a/client-participation-alpha/astro.config.mjs +++ b/client-participation-alpha/astro.config.mjs @@ -1,4 +1,6 @@ // @ts-check +import identityTools from '../scripts/build-identity.cjs' +const buildInfo = identityTools.buildIdentity() import { defineConfig } from 'astro/config' import react from '@astrojs/react' @@ -8,6 +10,7 @@ import node from '@astrojs/node' // https://astro.build/config export default defineConfig({ output: 'server', + vite: { define: { 'process.env.POLIS_BUILD_INFO': JSON.stringify(buildInfo) } }, adapter: node({ mode: 'standalone' }), diff --git a/client-participation-alpha/jest.setup.js b/client-participation-alpha/jest.setup.js index 06a31c7bc..8e15043fb 100644 --- a/client-participation-alpha/jest.setup.js +++ b/client-participation-alpha/jest.setup.js @@ -2,19 +2,21 @@ const matchers = require('@testing-library/jest-dom/matchers') expect.extend(matchers) // Mock window.matchMedia which is used by some components -Object.defineProperty(window, 'matchMedia', { - writable: true, - value: jest.fn().mockImplementation((query) => ({ - matches: false, - media: query, - onchange: null, - addListener: jest.fn(), // deprecated - removeListener: jest.fn(), // deprecated - addEventListener: jest.fn(), - removeEventListener: jest.fn(), - dispatchEvent: jest.fn() - })) -}) +if (typeof window !== 'undefined') { + Object.defineProperty(window, 'matchMedia', { + writable: true, + value: jest.fn().mockImplementation((query) => ({ + matches: false, + media: query, + onchange: null, + addListener: jest.fn(), // deprecated + removeListener: jest.fn(), // deprecated + addEventListener: jest.fn(), + removeEventListener: jest.fn(), + dispatchEvent: jest.fn() + })) + }) +} // Mock IntersectionObserver global.IntersectionObserver = jest.fn().mockImplementation(() => ({ diff --git a/client-participation-alpha/src/__tests__/build-info.test.ts b/client-participation-alpha/src/__tests__/build-info.test.ts new file mode 100644 index 000000000..967d02d0e --- /dev/null +++ b/client-participation-alpha/src/__tests__/build-info.test.ts @@ -0,0 +1,16 @@ +/** @jest-environment node */ +import { GET } from '../pages/build-info.json' +const { cases, fixture } = require('../../../scripts/build-identity-test.cjs') + +test.each(cases)('%s build resource', async (_name, metadata, expected) => { + const info = fixture(metadata) + const original = process.env + try { + process.env = { ...original, POLIS_BUILD_INFO: info } + const response = GET() + expect(await response.json()).toEqual(info) + expect(info.version_display).toBe(expected) + } finally { + process.env = original + } +}) diff --git a/client-participation-alpha/src/pages/build-info.json.ts b/client-participation-alpha/src/pages/build-info.json.ts new file mode 100644 index 000000000..8af6d52c4 --- /dev/null +++ b/client-participation-alpha/src/pages/build-info.json.ts @@ -0,0 +1,7 @@ +export const prerender = true + +export function GET() { + return new Response(JSON.stringify(process.env.POLIS_BUILD_INFO), { + headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache' } + }) +} diff --git a/client-participation/Dockerfile b/client-participation/Dockerfile index 4caebf8e6..7b04336ce 100644 --- a/client-participation/Dockerfile +++ b/client-participation/Dockerfile @@ -3,6 +3,7 @@ # Instead, the file-server Dockerfile builds and serves these assets. # But this file is still useful for development or deployments that do not use # the docker compose configuration. +# Build from the repository root: docker build -f client-participation/Dockerfile . FROM docker.io/node:24-alpine @@ -21,15 +22,25 @@ ENV AUTH_NAMESPACE=${AUTH_NAMESPACE} ARG NODE_ENV ENV NODE_ENV=${NODE_ENV:-production} -WORKDIR /app +RUN apk add --no-cache python3 -COPY package*.json ./ +WORKDIR /app/client-participation + +COPY client-participation/package*.json ./ RUN npm config set fetch-retries 5 && \ npm config set fetch-retry-mintimeout 20000 && \ npm config set fetch-retry-maxtimeout 120000 RUN --mount=type=cache,target=/root/.npm npm ci --production=false -COPY . . +COPY VERSION VERSION_STABLE_COMMIT /app/ +COPY scripts/build_identity.py scripts/build-identity.cjs /app/scripts/ +COPY client-participation/ . + +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=${GIT_HASH} POLIS_BUILD_DISTANCE=${POLIS_BUILD_DISTANCE} POLIS_BUILD_TAG=${POLIS_BUILD_TAG} POLIS_BUILD_SOURCE=${POLIS_BUILD_SOURCE} CMD npm run build:prod diff --git a/client-participation/build-identity.test.js b/client-participation/build-identity.test.js new file mode 100644 index 000000000..0ae62ec1e --- /dev/null +++ b/client-participation/build-identity.test.js @@ -0,0 +1,23 @@ +const test = require('node:test') +const assert = require('node:assert/strict') +const { cases, fixture } = require('../scripts/build-identity-test.cjs') +const { BuildInfoPlugin } = require('../scripts/build-identity.cjs') +const webpack = require('webpack') + +for (const [name, metadata, expected] of cases) test(`${name} build metadata`, () => { + const info = fixture(metadata) + const assets = {} + const compilation = { + hooks: { processAssets: { tap: (_options, emit) => emit() } }, + emitAsset: (name, asset) => { assets[name] = asset.source() } + } + const compiler = { + webpack, + hooks: { thisCompilation: { tap: (_name, compile) => compile(compilation) } } + } + new BuildInfoPlugin(info, 'client').apply(compiler) + const emitted = JSON.parse(assets['client/build-info.json']) + assert.equal(emitted.version_display, expected) + assert.equal(emitted.commit, metadata.GIT_HASH || 'unknown') + assert.equal(emitted.distance, metadata.POLIS_BUILD_DISTANCE === undefined ? null : Number(metadata.POLIS_BUILD_DISTANCE)) +}) diff --git a/client-participation/webpack.config.js b/client-participation/webpack.config.js index 2b0070f54..a3a035891 100644 --- a/client-participation/webpack.config.js +++ b/client-participation/webpack.config.js @@ -1,3 +1,5 @@ +const { buildIdentity, BuildInfoPlugin } = require('../scripts/build-identity.cjs'); +const buildInfo = buildIdentity(); const path = require("path"); const webpack = require("webpack"); const CopyPlugin = require("copy-webpack-plugin"); @@ -7,7 +9,6 @@ const EventHooksPlugin = require("event-hooks-webpack-plugin"); const lodashTemplate = require("lodash/template"); const glob = require("glob"); const fs = require("fs"); -const pkg = require("./package.json"); const TerserPlugin = require("terser-webpack-plugin"); const Dotenv = require("dotenv-webpack"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); @@ -237,7 +238,7 @@ module.exports = (env, options) => { template: path.resolve(__dirname, "public/index.ejs"), filename: "index.html", templateParameters: { - versionString: pkg.version, + versionString: buildInfo.version_display, jwtDecodeSrc: `/${jwtDecodeScript}`, gaTrackingId: gaTrackingId, oidcCacheKeyPrefix: oidcCacheKeyPrefix, @@ -265,7 +266,9 @@ module.exports = (env, options) => { } }), + new BuildInfoPlugin(buildInfo, 'participation'), new webpack.DefinePlugin({ + 'process.env.POLIS_BUILD_INFO': JSON.stringify(buildInfo), "process.env.GA_TRACKING_ID": JSON.stringify(gaTrackingId), "process.env.OIDC_CACHE_KEY_PREFIX": JSON.stringify(oidcCacheKeyPrefix), "process.env.OIDC_CACHE_KEY_ID_TOKEN_SUFFIX": JSON.stringify(oidcCacheKeyIdTokenSuffix), diff --git a/client-report/Dockerfile b/client-report/Dockerfile index 0c2eefd6f..57da5f035 100644 --- a/client-report/Dockerfile +++ b/client-report/Dockerfile @@ -3,6 +3,7 @@ # Instead, the file-server Dockerfile builds and serves these assets. # But this file is still useful for development or deployments that do not use # the docker compose configuration. +# Build from the repository root: docker build -f client-report/Dockerfile . FROM docker.io/node:24-alpine @@ -10,23 +11,22 @@ FROM docker.io/node:24-alpine ARG NODE_ENV ENV NODE_ENV=${NODE_ENV:-production} -WORKDIR /app +RUN apk add --no-cache python3 + +WORKDIR /app/client-report RUN apk add git -COPY package*.json ./ +COPY client-report/package*.json ./ RUN npm config set fetch-retries 5 && \ npm config set fetch-retry-mintimeout 20000 && \ npm config set fetch-retry-maxtimeout 120000 RUN --mount=type=cache,target=/root/.npm npm ci --production=false -COPY . . - -# GIT_HASH is optional and will be set properly when running `make` (see Makefile). -# Or may be passed in at build time with --build-arg GIT_HASH=$(git rev-parse --short HEAD) -ARG GIT_HASH -ENV GIT_HASH=${GIT_HASH:-placeholder} +COPY VERSION VERSION_STABLE_COMMIT /app/ +COPY scripts/build_identity.py scripts/build-identity.cjs /app/scripts/ +COPY client-report/ . ARG AUTH_AUDIENCE ARG AUTH_NAMESPACE @@ -45,4 +45,10 @@ ENV DD_CLIENT_TOKEN=${DD_CLIENT_TOKEN} ENV DD_SITE=${DD_SITE} ENV SERVICE_URL=${SERVICE_URL} +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=${GIT_HASH} POLIS_BUILD_DISTANCE=${POLIS_BUILD_DISTANCE} POLIS_BUILD_TAG=${POLIS_BUILD_TAG} POLIS_BUILD_SOURCE=${POLIS_BUILD_SOURCE} + CMD npm run build:prod diff --git a/client-report/build-identity.test.js b/client-report/build-identity.test.js new file mode 100644 index 000000000..8e991bcb3 --- /dev/null +++ b/client-report/build-identity.test.js @@ -0,0 +1,21 @@ +const { cases, fixture } = require('../scripts/build-identity-test.cjs') +const { BuildInfoPlugin } = require('../scripts/build-identity.cjs') +const webpack = require('webpack') + +test.each(cases)('%s build metadata', (_name, metadata, expected) => { + const info = fixture(metadata) + const assets = {} + const compilation = { + hooks: { processAssets: { tap: (_options, emit) => emit() } }, + emitAsset: (name, asset) => { assets[name] = asset.source() } + } + const compiler = { + webpack, + hooks: { thisCompilation: { tap: (_name, compile) => compile(compilation) } } + } + new BuildInfoPlugin(info, 'client').apply(compiler) + const emitted = JSON.parse(assets['client/build-info.json']) + expect(emitted.version_display).toBe(expected) + expect(emitted.commit).toBe(metadata.GIT_HASH || 'unknown') + expect(emitted.distance).toBe(metadata.POLIS_BUILD_DISTANCE === undefined ? null : Number(metadata.POLIS_BUILD_DISTANCE)) +}) diff --git a/client-report/webpack.common.js b/client-report/webpack.common.js index c22d995d5..a1dce764e 100644 --- a/client-report/webpack.common.js +++ b/client-report/webpack.common.js @@ -1,3 +1,5 @@ +const { buildIdentity, BuildInfoPlugin } = require('../scripts/build-identity.cjs'); +const buildInfo = buildIdentity(); // Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . require('dotenv').config(); @@ -62,7 +64,9 @@ module.exports = { filename: "index_report.html", vendorScripts: vendorGlobals.map(({ to }) => `/${to}`), }), - new webpack.DefinePlugin({ + new BuildInfoPlugin(buildInfo, 'report'), + new webpack.DefinePlugin({ + 'process.env.POLIS_BUILD_INFO': JSON.stringify(buildInfo), 'process.env.AUTH_AUDIENCE': JSON.stringify(process.env.AUTH_AUDIENCE), 'process.env.AUTH_NAMESPACE': JSON.stringify(process.env.AUTH_NAMESPACE), 'process.env.AUTH_CLIENT_ID': JSON.stringify(process.env.AUTH_CLIENT_ID), diff --git a/delphi/tests/test_build_images.py b/delphi/tests/test_build_images.py index 67c01d963..a26b1b35c 100644 --- a/delphi/tests/test_build_images.py +++ b/delphi/tests/test_build_images.py @@ -3,7 +3,7 @@ prints. Runs the real scripts with every external command faked on PATH: aws, docker, -docker-compose, jq, flock and sleep only record their arguments (aws answers +docker-compose, python3, jq, flock and sleep only record their arguments (aws answers the few reads the scripts make; docker login reads its password from stdin). The build box's absolute paths (/run/polis-build, /var/log/polis-build) are rewritten into a temporary root. @@ -65,6 +65,7 @@ def _find(rel): RECORD = '#!/bin/bash\necho "$(basename "$0") $*" >> "$FAKE_LOG"\n' FAKES = { + "python3": RECORD + 'echo "{}"\n', "flock": RECORD, "sleep": RECORD, "jq": RECORD + "echo value\n", @@ -145,6 +146,8 @@ def test_polis_api_is_built_pushed_and_named_in_the_manifest(tmp_path): # One build of every service; polis-api's profile is named. builds = [c for c in _calls(tmp_path, "docker-compose") if " build " in f" {c} "] assert builds == ["-f docker-compose.yml -f docker-compose.build.yml --profile rust-api build " + f"--build-arg GIT_HASH={REVISION} --build-arg POLIS_BUILD_DISTANCE=unknown " + "--build-arg POLIS_BUILD_TAG= --build-arg POLIS_BUILD_SOURCE=unverified-archive " "server nginx-proxy client-participation-alpha delphi migrate polis-api"] pushes = [c.split()[1] for c in _calls(tmp_path, "docker") if c.startswith("push ")] assert pushes == [*REFS.values(), f"{REGISTRY}/polis/server:latest"] @@ -187,6 +190,7 @@ def test_the_deploy_workflow_accepts_the_manifest_the_build_prints(tmp_path): box_dir.mkdir() box, output = _on_box(box_dir, proc.stdout) assert box.returncode == 0, box.stdout + box.stderr + assert _calls(box_dir, "python3") == ["scripts/build_identity.py"] manifest = _manifest(proc.stdout) body = "".join(f"{k}={v}\n" for k, v in manifest.items()) assert output == f"manifest<>"$LOG" 2>&1 || fail "ECR login" -"${COMPOSE[@]}" --profile rust-api build "${SERVICES[@]}" >>"$LOG" 2>&1 || fail "build" +"${COMPOSE[@]}" --profile rust-api build --build-arg "GIT_HASH=$REVISION" --build-arg "POLIS_BUILD_DISTANCE=${POLIS_BUILD_DISTANCE:-unknown}" --build-arg "POLIS_BUILD_TAG=${POLIS_BUILD_TAG:-}" --build-arg "POLIS_BUILD_SOURCE=${POLIS_BUILD_SOURCE:-unverified-archive}" "${SERVICES[@]}" >>"$LOG" 2>&1 || fail "build" for service in "${SERVICES[@]}"; do docker push "$(ref_of "$service")" >>"$LOG" 2>&1 || fail "push $service" done diff --git a/deploy/build-on-box.sh b/deploy/build-on-box.sh index cb6947c66..934279652 100644 --- a/deploy/build-on-box.sh +++ b/deploy/build-on-box.sh @@ -59,9 +59,17 @@ launch() { return 1 } +# Calculate identity before crossing the source-archive boundary. A shallow +# checkout reports an unknown distance until the caller supplies full history. +BUILD_IDENTITY=$(python3 scripts/build_identity.py) +BUILD_DISTANCE=$(printf '%s' "$BUILD_IDENTITY" | jq -r '.distance // "unknown"') +BUILD_TAG=$(printf '%s' "$BUILD_IDENTITY" | jq -r 'if .channel == "stable" then "v" + .version_base else "" end') +BUILD_SOURCE=$(printf '%s' "$BUILD_IDENTITY" | jq -r '.source') + # The build, as AWS-RunShellScript commands. Waits for the box's bootstrap, # fetches this commit's source, checks the archive is that commit, builds. jq -n --arg sha "$GITHUB_SHA" --arg bucket "$DEPLOY_BUCKET" --arg timeout "$BUILD_TIMEOUT_SECONDS" \ + --arg distance "$BUILD_DISTANCE" --arg tag "$BUILD_TAG" --arg source "$BUILD_SOURCE" \ --arg psu "${PUBLIC_SERVICE_URL:-}" --arg an "${AUTH_NAMESPACE:-}" \ --arg ocp "${OIDC_CACHE_KEY_PREFIX:-}" --arg ocs "${OIDC_CACHE_KEY_ID_TOKEN_SUFFIX:-}" '{ executionTimeout: [$timeout], @@ -75,6 +83,7 @@ jq -n --arg sha "$GITHUB_SHA" --arg bucket "$DEPLOY_BUCKET" --arg timeout "$BUIL "mkdir \"$W/src\" && tar -xzf \"$W/source.tar.gz\" -C \"$W/src\"", ("PUBLIC_SERVICE_URL=" + ($psu|@sh) + " AUTH_NAMESPACE=" + ($an|@sh) + " OIDC_CACHE_KEY_PREFIX=" + ($ocp|@sh) + " OIDC_CACHE_KEY_ID_TOKEN_SUFFIX=" + ($ocs|@sh) + + " POLIS_BUILD_DISTANCE=" + ($distance|@sh) + " POLIS_BUILD_TAG=" + ($tag|@sh) + " POLIS_BUILD_SOURCE=" + ($source|@sh) + " HOME=/root bash \"$W/src/deploy/build-images.sh\" " + $sha) ]}' > build-command.json diff --git a/docker-compose.test.yml b/docker-compose.test.yml index f02113ac2..490ad4341 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -40,12 +40,16 @@ services: client-participation-alpha: build: - context: ./client-participation-alpha - dockerfile: Dockerfile + context: . + dockerfile: client-participation-alpha/Dockerfile args: - - OIDC_CACHE_KEY_ID_TOKEN_SUFFIX=${OIDC_CACHE_KEY_ID_TOKEN_SUFFIX} - - OIDC_CACHE_KEY_PREFIX=${OIDC_CACHE_KEY_PREFIX} - - PUBLIC_SERVICE_URL=${PUBLIC_SERVICE_URL} + GIT_HASH: "${GIT_HASH:-${GITHUB_SHA:-unknown}}" + POLIS_BUILD_DISTANCE: "${POLIS_BUILD_DISTANCE:-unknown}" + POLIS_BUILD_TAG: "${POLIS_BUILD_TAG:-}" + POLIS_BUILD_SOURCE: "${POLIS_BUILD_SOURCE:-unverified-archive}" + OIDC_CACHE_KEY_ID_TOKEN_SUFFIX: "${OIDC_CACHE_KEY_ID_TOKEN_SUFFIX}" + OIDC_CACHE_KEY_PREFIX: "${OIDC_CACHE_KEY_PREFIX}" + PUBLIC_SERVICE_URL: "${PUBLIC_SERVICE_URL}" depends_on: - "server" environment: @@ -68,10 +72,14 @@ services: env_file: - test.env build: - context: ./server - dockerfile: Dockerfile + context: . + dockerfile: server/Dockerfile target: prod args: + GIT_HASH: "${GIT_HASH:-${GITHUB_SHA:-unknown}}" + POLIS_BUILD_DISTANCE: "${POLIS_BUILD_DISTANCE:-unknown}" + POLIS_BUILD_TAG: "${POLIS_BUILD_TAG:-}" + POLIS_BUILD_SOURCE: "${POLIS_BUILD_SOURCE:-unverified-archive}" NODE_ENV: production labels: polis_tag: test @@ -223,13 +231,16 @@ services: context: ./ dockerfile: file-server/Dockerfile args: + GIT_HASH: "${GIT_HASH:-${GITHUB_SHA:-unknown}}" + POLIS_BUILD_DISTANCE: "${POLIS_BUILD_DISTANCE:-unknown}" + POLIS_BUILD_TAG: "${POLIS_BUILD_TAG:-}" + POLIS_BUILD_SOURCE: "${POLIS_BUILD_SOURCE:-unverified-archive}" ADMIN_UIDS: ${ADMIN_UIDS} AUTH_AUDIENCE: users AUTH_CLIENT_ID: dev-client-id AUTH_ISSUER: https://localhost:3000/ AUTH_NAMESPACE: https://pol.is/ EMBED_SERVICE_HOSTNAME: localhost - GIT_HASH: test NODE_ENV: production OIDC_CACHE_KEY_ID_TOKEN_SUFFIX: ${OIDC_CACHE_KEY_ID_TOKEN_SUFFIX} OIDC_CACHE_KEY_PREFIX: ${OIDC_CACHE_KEY_PREFIX} diff --git a/docker-compose.yml b/docker-compose.yml index 34bc42142..af2c19277 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -60,13 +60,17 @@ services: client-participation-alpha: build: - context: ./client-participation-alpha - dockerfile: Dockerfile + context: . + dockerfile: client-participation-alpha/Dockerfile args: - - PUBLIC_SERVICE_URL=${PUBLIC_SERVICE_URL} - - PUBLIC_AUTH_NAMESPACE=${AUTH_NAMESPACE} - - OIDC_CACHE_KEY_PREFIX=${OIDC_CACHE_KEY_PREFIX} - - OIDC_CACHE_KEY_ID_TOKEN_SUFFIX=${OIDC_CACHE_KEY_ID_TOKEN_SUFFIX} + GIT_HASH: "${GIT_HASH:-${GITHUB_SHA:-unknown}}" + POLIS_BUILD_DISTANCE: "${POLIS_BUILD_DISTANCE:-unknown}" + POLIS_BUILD_TAG: "${POLIS_BUILD_TAG:-}" + POLIS_BUILD_SOURCE: "${POLIS_BUILD_SOURCE:-unverified-archive}" + PUBLIC_SERVICE_URL: "${PUBLIC_SERVICE_URL}" + PUBLIC_AUTH_NAMESPACE: "${AUTH_NAMESPACE}" + OIDC_CACHE_KEY_PREFIX: "${OIDC_CACHE_KEY_PREFIX}" + OIDC_CACHE_KEY_ID_TOKEN_SUFFIX: "${OIDC_CACHE_KEY_ID_TOKEN_SUFFIX}" container_name: client-participation-alpha restart: unless-stopped networks: @@ -100,10 +104,14 @@ services: - ${SERVER_ENV_FILE:-.env} image: 050917022930.dkr.ecr.us-east-1.amazonaws.com/polis/server:latest build: - context: ./server - dockerfile: Dockerfile + context: . + dockerfile: server/Dockerfile target: prod args: + GIT_HASH: "${GIT_HASH:-${GITHUB_SHA:-unknown}}" + POLIS_BUILD_DISTANCE: "${POLIS_BUILD_DISTANCE:-unknown}" + POLIS_BUILD_TAG: "${POLIS_BUILD_TAG:-}" + POLIS_BUILD_SOURCE: "${POLIS_BUILD_SOURCE:-unverified-archive}" NODE_ENV: production labels: polis_tag: ${TAG:-dev} @@ -488,6 +496,10 @@ services: context: ./ dockerfile: file-server/Dockerfile args: + GIT_HASH: "${GIT_HASH:-${GITHUB_SHA:-unknown}}" + POLIS_BUILD_DISTANCE: "${POLIS_BUILD_DISTANCE:-unknown}" + POLIS_BUILD_TAG: "${POLIS_BUILD_TAG:-}" + POLIS_BUILD_SOURCE: "${POLIS_BUILD_SOURCE:-unverified-archive}" ADMIN_UIDS: ${ADMIN_UIDS} AUTH_AUDIENCE: ${AUTH_AUDIENCE} AUTH_CLIENT_ID: ${AUTH_CLIENT_ID} @@ -498,7 +510,6 @@ services: DD_SITE: ${DD_SITE} EMBED_SERVICE_HOSTNAME: ${EMBED_SERVICE_HOSTNAME} GA_TRACKING_ID: ${GA_TRACKING_ID} - GIT_HASH: "${GIT_HASH:-placeholder}" NODE_ENV: production OIDC_CACHE_KEY_ID_TOKEN_SUFFIX: ${OIDC_CACHE_KEY_ID_TOKEN_SUFFIX} OIDC_CACHE_KEY_PREFIX: ${OIDC_CACHE_KEY_PREFIX} @@ -561,8 +572,8 @@ services: import-worker: build: - context: ./server - dockerfile: Dockerfile + context: . + dockerfile: server/Dockerfile target: dev image: polis-server:dev container_name: polis-import-worker diff --git a/docs/configuration.md b/docs/configuration.md index 4702e48e0..c83f71feb 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -60,7 +60,7 @@ If you are deploying to a custom domain (not `pol.is`) then you need to update b - **`ADMIN_UIDS`** an array of user UIDs for site admins. These users will have moderator capabilities on all conversations hosted on the site. - **`EMAIL_TRANSPORT_TYPES`** comma-separated list of email services to use (see [Email Transports](#email-transports) below) -- **`GIT_HASH`** Set programmatically using `git rev-parse HEAD` (e.g. in `Makefile`) to tag docker container versions and other release assets. Can be left blank. +- **`GIT_HASH`** Full lowercase source commit from `git rev-parse HEAD` (e.g. in `Makefile`), embedded with root `VERSION` at build time. The existing CI labels `test` and `characterization` are also accepted, explicitly reported with source `test-label`, unknown distance and development channel; they cannot assert stable provenance. Archive builds also accept `POLIS_BUILD_DISTANCE` for the first-parent distance from stable; omitted metadata is reported as `unknown`. - **`MATH_ENV`** The math namespace the readers serve: `python` (the Python engine's rows, served in production), `prod` (rows the retired Clojure engine left behind; no longer updated), `dev`, `preprod` or an explicitly isolated namespace. The API reads it without a fallback ([config:128](../server/src/config.ts#L128)); Compose passes it to Delphi with fallback `prod` ([Compose:128](../docker-compose.yml#L128)); production sets it explicitly. It does not set the writer's label in `docker-compose.yml`: the `math-python` service writes `MATH_PYTHON_ENV` with fallback `python` ([Compose:191](../docker-compose.yml#L191)), so moving `MATH_ENV` moves only the readers. The standalone Python poller defaults to `dev` ([poller:234](../delphi/polismath/poller/service.py#L234)). The dev overlay runs `math-python` without a profile and has it write `MATH_ENV` unless `MATH_PYTHON_ENV` is set ([dev overlay:39](../docker-compose.dev.yml#L39)). - **`SERVER_ENV_FILE`** The name of an environment file to be passed into the API Server container by docker compose. Defaults to `.env` if left blank. Used especially for building a `test` version of the project for end-to-end testing. - **`SERVER_LOG_LEVEL`** Used by Winston.js in the API server. Common values are `debug`, `info`, `warn`, and `error`. The config module reads the raw value ([config:116](../server/src/config.ts#L116)); the logger then falls back to `warn` ([logger.ts:9](../server/src/utils/logger.ts#L9)). @@ -361,3 +361,5 @@ translate strings can be found in: `client-participation/js/strings/en_us.js` ## Email Transports The current sender uses AWS SES ([senders.ts:1](../server/src/email/senders.ts#L1)). `EMAIL_TRANSPORT_TYPES` and Mailgun names still have config reads, but that alone does not mean the current sender selects a Mailgun transport. Follow the sender implementation and the [service inventory](deployment-configuration.md). + +Source-only server entry points that skip the build use the root `VERSION` read once at startup. Without generated metadata, `/api/v3/version` reports `+dev.unknown.unknown`, commit `unknown`, distance `null`, channel `development`, and source `unverified-archive`. Normal build, watch, and npm test entry points still generate and embed the build identity first. diff --git a/docs/deployment-configuration.md b/docs/deployment-configuration.md index 6feb1b1ab..cb021adae 100644 --- a/docs/deployment-configuration.md +++ b/docs/deployment-configuration.md @@ -26,7 +26,7 @@ No name in the old `docs/configuration.md` was proven to have no reader anywhere | `SERVER_ENV_FILE` | [Compose:58](../docker-compose.yml#L58) server env-file path | `.env`; file contents can be secret. | | `HTTP_PORT`, `HTTPS_PORT` | [Compose:256](../docker-compose.yml#L256), [Compose:257](../docker-compose.yml#L257) host mappings | `80`, `443`. Not secret. | | `POSTGRES_HOST` | [Compose:136](../docker-compose.yml#L136) maps to Delphi `DATABASE_HOST` | No fallback at this interpolation; can be a private host identifier. | -| `GIT_HASH` | [Makefile:25](../Makefile#L25), [file-server Dockerfile:97](../file-server/Dockerfile#L97) | Generated by Make; Dockerfile fallback `placeholder`. Not secret. | +| `GIT_HASH` | [Makefile:25](../Makefile#L25), [file-server Dockerfile:97](../file-server/Dockerfile#L97) | Full source commit supplied by Make or a build argument; Dockerfile fallback `unknown`. CI labels `test` and `characterization` report source `test-label`, never stable provenance. Not secret. | | `SERVICE_URL` | [report URL helper:23](../client-report/src/util/url.js#L23), [report webpack:40](../client-report/webpack.config.js#L40) | Build mode dependent; production webpack injects `null`. Not a server setting. URL may identify private infrastructure. | | `EMBED_SERVICE_HOSTNAME`, `GA_TRACKING_ID` | [legacy participation webpack:86](../client-participation/webpack.config.js#L86) | Host fallback `pol.is`; tracking value has no fallback. Public client configuration. | | `OIDC_CACHE_KEY_PREFIX`, `OIDC_CACHE_KEY_ID_TOKEN_SUFFIX` | [legacy participation webpack:88](../client-participation/webpack.config.js#L88), [Compose:47](../docker-compose.yml#L47) | `oidc.user` / `@@user@@` in legacy webpack; Compose maps names to Alpha `PUBLIC_*`. Cache key labels, not tokens. | diff --git a/file-server/Dockerfile b/file-server/Dockerfile index 6f0a621cb..a924b5bd1 100644 --- a/file-server/Dockerfile +++ b/file-server/Dockerfile @@ -16,6 +16,8 @@ ARG NODE_ENV ENV NODE_ENV=${NODE_ENV:-production} WORKDIR /app +RUN apk add --no-cache python3 + COPY client-admin/package*.json ./ @@ -26,6 +28,14 @@ RUN --mount=type=cache,target=/root/.npm npm ci --production=false COPY client-admin/. . +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=$GIT_HASH POLIS_BUILD_DISTANCE=$POLIS_BUILD_DISTANCE POLIS_BUILD_TAG=$POLIS_BUILD_TAG POLIS_BUILD_SOURCE=$POLIS_BUILD_SOURCE +COPY VERSION VERSION_STABLE_COMMIT / +COPY scripts/build_identity.py scripts/build-identity.cjs /scripts/ + ARG ADMIN_UIDS ARG AUTH_AUDIENCE ARG AUTH_CLIENT_ID @@ -58,6 +68,8 @@ ARG NODE_ENV ENV NODE_ENV=${NODE_ENV:-production} WORKDIR /app +RUN apk add --no-cache python3 + COPY client-participation/package*.json ./ @@ -68,6 +80,14 @@ RUN --mount=type=cache,target=/root/.npm npm ci --production=false COPY client-participation/. . +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=$GIT_HASH POLIS_BUILD_DISTANCE=$POLIS_BUILD_DISTANCE POLIS_BUILD_TAG=$POLIS_BUILD_TAG POLIS_BUILD_SOURCE=$POLIS_BUILD_SOURCE +COPY VERSION VERSION_STABLE_COMMIT / +COPY scripts/build_identity.py scripts/build-identity.cjs /scripts/ + RUN npm run build:prod @@ -81,6 +101,8 @@ ARG NODE_ENV ENV NODE_ENV=${NODE_ENV:-production} WORKDIR /app +RUN apk add --no-cache python3 + RUN apk add git @@ -93,9 +115,13 @@ RUN --mount=type=cache,target=/root/.npm npm ci --production=false COPY client-report/. . -# GIT_HASH will be set properly when running `make` (see Makefile). -ARG GIT_HASH -ENV GIT_HASH=${GIT_HASH:-placeholder} +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=$GIT_HASH POLIS_BUILD_DISTANCE=$POLIS_BUILD_DISTANCE POLIS_BUILD_TAG=$POLIS_BUILD_TAG POLIS_BUILD_SOURCE=$POLIS_BUILD_SOURCE +COPY VERSION VERSION_STABLE_COMMIT / +COPY scripts/build_identity.py scripts/build-identity.cjs /scripts/ ARG AUTH_AUDIENCE ARG AUTH_NAMESPACE diff --git a/polis-cli/crates/polis/build.rs b/polis-cli/crates/polis/build.rs index 3cdb0e7a4..74376dabb 100644 --- a/polis-cli/crates/polis/build.rs +++ b/polis-cli/crates/polis/build.rs @@ -1,29 +1,64 @@ -use std::env; +use std::{env, path::Path, process::Command}; fn main() { - println!("cargo:rerun-if-env-changed=POLIS_BUILD_COMMIT"); - println!("cargo:rerun-if-env-changed=POLIS_BUILD_SOURCE"); - let commit = env::var("POLIS_BUILD_COMMIT").unwrap_or_else(|_| "unknown".into()); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../..") + .canonicalize() + .expect("repository root"); + for name in [ + "VERSION", + "VERSION_STABLE_COMMIT", + "scripts/build_identity.py", + ] { + println!("cargo:rerun-if-changed={}", root.join(name).display()); + } + for name in [ + "POLIS_BUILD_COMMIT", + "GIT_HASH", + "POLIS_BUILD_SOURCE", + "POLIS_BUILD_DISTANCE", + "POLIS_BUILD_TAG", + ] { + println!("cargo:rerun-if-env-changed={name}"); + } + // Resolve paths through Git so linked worktrees track their own HEAD and + // the common refs/tags/packed-refs as well as ordinary checkouts. + for name in ["HEAD", "refs", "packed-refs", "index", "shallow"] { + if let Ok(result) = Command::new("git") + .current_dir(&root) + .args(["rev-parse", "--git-path", name]) + .output() + { + if result.status.success() { + let value = String::from_utf8(result.stdout).expect("Git path"); + println!( + "cargo:rerun-if-changed={}", + root.join(value.trim()).display() + ); + } + } + } + let result = Command::new("python3") + .arg(root.join("scripts/build_identity.py")) + .args(["--format", "env"]) + .output() + .expect("Python 3 is required to generate the shared Polis build identity"); assert!( - commit == "unknown" - || (commit.len() == 40 - && commit - .bytes() - .all(|b| b.is_ascii_hexdigit() && !b.is_ascii_uppercase())), - "POLIS_BUILD_COMMIT must be a full lowercase Git commit or unknown" + result.status.success(), + "{}", + String::from_utf8_lossy(&result.stderr) ); - let source = env::var("POLIS_BUILD_SOURCE").unwrap_or_else(|_| "development".into()); - assert!( - matches!( - source.as_str(), - "development" | "clean-checkout" | "unverified-archive" - ), - "invalid POLIS_BUILD_SOURCE" - ); - assert!( - source != "clean-checkout" || commit != "unknown", - "clean-checkout requires a commit" - ); - println!("cargo:rustc-env=POLIS_BUILD_COMMIT={commit}"); - println!("cargo:rustc-env=POLIS_BUILD_SOURCE={source}"); + let text = String::from_utf8(result.stdout).expect("build identity"); + for line in text.lines() { + let (key, value) = line.split_once('=').expect("identity field"); + let name = match key { + "version_base" => "POLIS_VERSION_BASE", + "version_display" => "POLIS_VERSION_DISPLAY", + "commit" => "POLIS_BUILD_COMMIT", + "distance" => "POLIS_BUILD_DISTANCE", + "source" => "POLIS_BUILD_SOURCE", + _ => continue, + }; + println!("cargo:rustc-env={name}={value}"); + } } diff --git a/polis-cli/crates/polis/src/commands.rs b/polis-cli/crates/polis/src/commands.rs index d6fd83f4c..d1744d957 100644 --- a/polis-cli/crates/polis/src/commands.rs +++ b/polis-cli/crates/polis/src/commands.rs @@ -411,7 +411,7 @@ fn purpose(path: &str) -> String { .unwrap_or_else(|| format!("provide {rest} operations for {group}")) } pub fn command() -> Command { - let mut root=Command::new("polis").version(concat!(env!("CARGO_PKG_VERSION"), " (commit ", env!("POLIS_BUILD_COMMIT"), "; ", env!("POLIS_BUILD_SOURCE"), ")")) + let mut root=Command::new("polis").version(concat!(env!("POLIS_VERSION_DISPLAY"), " (commit ", env!("POLIS_BUILD_COMMIT"), "; distance ", env!("POLIS_BUILD_DISTANCE"), "; ", env!("POLIS_BUILD_SOURCE"), ")")) .about("Listen at scale. Bring Polis to your terminal.") .long_about("Listen at scale. Bring Polis to your terminal.\n\nConversations, comments, and shared understanding — for people and agents.\nWorking now: auth, conversations, seeds, moderation, participant/vote reads, report exports, stored Delphi results, and raw API.\nThe full product surface is discoverable below; planned commands return exit 8.") diff --git a/polis-cli/crates/polis/tests/update.rs b/polis-cli/crates/polis/tests/update.rs index 60b9806a3..35fa74c8b 100644 --- a/polis-cli/crates/polis/tests/update.rs +++ b/polis-cli/crates/polis/tests/update.rs @@ -380,9 +380,10 @@ fn version_plain_and_json_make_no_release_or_proxy_requests() { assert!(out.stderr.is_empty()); let stdout = String::from_utf8(out.stdout).unwrap(); let expected = format!( - "polis {} (commit {}; {})", - env!("CARGO_PKG_VERSION"), + "polis {} (commit {}; distance {}; {})", + env!("POLIS_VERSION_DISPLAY"), env!("POLIS_BUILD_COMMIT"), + env!("POLIS_BUILD_DISTANCE"), env!("POLIS_BUILD_SOURCE") ); if args.contains(&"--json") { diff --git a/polis-cli/crates/polis/tests/version.rs b/polis-cli/crates/polis/tests/version.rs index 317756b94..66f8e2e88 100644 --- a/polis-cli/crates/polis/tests/version.rs +++ b/polis-cli/crates/polis/tests/version.rs @@ -16,8 +16,9 @@ fn version_identifies_source_without_credentials_or_network() { assert_eq!( String::from_utf8(out.stdout).unwrap().trim(), format!( - "polis {} (commit {commit}; {source})", - env!("CARGO_PKG_VERSION") + "polis {} (commit {commit}; distance {}; {source})", + env!("POLIS_VERSION_DISPLAY"), + env!("POLIS_BUILD_DISTANCE") ) ); assert!(out.stderr.is_empty()); diff --git a/polis-cli/tests/differential/README.md b/polis-cli/tests/differential/README.md index 84a74f979..0c3786a8f 100644 --- a/polis-cli/tests/differential/README.md +++ b/polis-cli/tests/differential/README.md @@ -9,7 +9,7 @@ Build the CLI and five local images from the source being tested: ```sh (cd polis-cli && cargo build --locked -p polis --features fixture-ids) -docker build --target prod --build-arg NODE_ENV=production -t cli-diff-node -f server/Dockerfile server +docker build --target prod --build-arg NODE_ENV=production -t cli-diff-node -f server/Dockerfile . docker build --build-context queue-rs=queue-rs -t cli-diff-postgres -f server/Dockerfile-db server docker build -t cli-diff-oidc oidc-simulator docker build --build-arg FEATURES=fixture-clock -t cli-diff-rust -f queue-rs/polis-api/Dockerfile queue-rs diff --git a/scripts/after_install.sh b/scripts/after_install.sh index a6e8b7d99..10c182427 100644 --- a/scripts/after_install.sh +++ b/scripts/after_install.sh @@ -180,7 +180,7 @@ poller_identity() { # from the workflow, not from this box's env document, so refuse an image built # with other values than this box would have built it with. if [ "$SERVICE_FROM_FILE" == "server" ]; then - WEB_ARGS_SHA256=$(sudo /usr/local/bin/docker-compose config --format json | jq -cS '.services["client-participation-alpha"].build.args' | sha256sum | cut -d' ' -f1) + WEB_ARGS_SHA256=$(sudo /usr/local/bin/docker-compose config --format json | jq -cS '.services["client-participation-alpha"].build.args | del(.GIT_HASH, .POLIS_BUILD_DISTANCE, .POLIS_BUILD_TAG, .POLIS_BUILD_SOURCE)' | sha256sum | cut -d' ' -f1) if [ "$WEB_ARGS_SHA256" != "$(image_ref web-build-args-sha256)" ]; then echo "Error: client-participation-alpha was built with other public settings (PUBLIC_SERVICE_URL, AUTH_NAMESPACE, OIDC_CACHE_KEY_PREFIX, OIDC_CACHE_KEY_ID_TOKEN_SUFFIX) than this box's env document gives it; refusing to deploy" exit 1 diff --git a/scripts/build-identity-test.cjs b/scripts/build-identity-test.cjs new file mode 100644 index 000000000..c4050560d --- /dev/null +++ b/scripts/build-identity-test.cjs @@ -0,0 +1,21 @@ +const { execFileSync } = require('node:child_process'); +const { mkdtempSync, writeFileSync, rmSync } = require('node:fs'); +const { tmpdir } = require('node:os'); +const path = require('node:path'); +const cases = [ + ['tagged', { GIT_HASH: 'a'.repeat(40), POLIS_BUILD_DISTANCE: '0', POLIS_BUILD_TAG: 'v2.40.0', POLIS_BUILD_SOURCE: 'clean-checkout' }, '2.40.0'], + ['untagged', { GIT_HASH: 'a'.repeat(40), POLIS_BUILD_DISTANCE: '16' }, '2.40.0+dev.16.aaaaaaaaaaaa'], + ['no-git', {}, '2.40.0+dev.unknown.unknown'] +]; +function fixture(metadata) { + const root = mkdtempSync(path.join(tmpdir(), 'polis-build-')); + try { + writeFileSync(path.join(root, 'VERSION'), '2.40.0\n'); + const env = { ...process.env }; + for (const name of ['GIT_HASH', 'POLIS_BUILD_COMMIT', 'POLIS_BUILD_DISTANCE', 'POLIS_BUILD_TAG', 'POLIS_BUILD_SOURCE']) delete env[name]; + return JSON.parse(execFileSync('python3', [path.join(__dirname, 'build_identity.py'), '--root', root], { + env: { ...env, ...metadata }, encoding: 'utf8' + })); + } finally { rmSync(root, { recursive: true, force: true }); } +} +module.exports = { cases, fixture }; diff --git a/scripts/build-identity.cjs b/scripts/build-identity.cjs new file mode 100644 index 000000000..d773b58f1 --- /dev/null +++ b/scripts/build-identity.cjs @@ -0,0 +1,28 @@ +const { execFileSync } = require('node:child_process'); +const path = require('node:path'); + +function buildIdentity(env = process.env) { + return JSON.parse(execFileSync('python3', [path.join(__dirname, 'build_identity.py')], { + env, encoding: 'utf8' + })); +} + +class BuildInfoPlugin { + constructor(info, surface) { + this.info = info; + this.surface = surface; + } + apply(compiler) { + compiler.hooks.thisCompilation.tap('BuildInfo', (compilation) => { + compilation.hooks.processAssets.tap({ + name: 'BuildInfo', stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL + }, () => { + const name = `${this.surface}/build-info.json`; + compilation.emitAsset(name, new compiler.webpack.sources.RawSource(JSON.stringify(this.info) + '\n')); + compilation.emitAsset(`${name}.headersJson`, new compiler.webpack.sources.RawSource( + JSON.stringify({ 'Content-Type': 'application/json', 'Cache-Control': 'no-cache' }))); + }); + }); + } +} +module.exports = { buildIdentity, BuildInfoPlugin }; diff --git a/scripts/build-polis-cli-release.py b/scripts/build-polis-cli-release.py index dcc5cd3da..a056c0b54 100644 --- a/scripts/build-polis-cli-release.py +++ b/scripts/build-polis-cli-release.py @@ -11,12 +11,18 @@ import subprocess import tarfile import tomllib +import importlib.util + +_IDENTITY_SPEC = importlib.util.spec_from_file_location("build_identity", Path(__file__).with_name("build_identity.py")) +_IDENTITY = importlib.util.module_from_spec(_IDENTITY_SPEC) +_IDENTITY_SPEC.loader.exec_module(_IDENTITY) +identity = _IDENTITY.identity ROOT = Path(__file__).resolve().parents[1] TARGETS = ("aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu") INPUTS = ("polis-cli", "queue-rs/polis-contracts", "scripts/build-polis-cli-release.py", - "scripts/test-polis-cli.sh", "LICENSE") + "scripts/test-polis-cli.sh", "scripts/build_identity.py", "VERSION", "VERSION_STABLE_COMMIT", "LICENSE") def output(argv, cwd=ROOT, env=None): @@ -125,7 +131,9 @@ def main(): metadata = json.loads(output(["cargo", "metadata", "--locked", "--no-deps", "--format-version", "1"], workspace, env)) subprocess.run(["cargo", "build", "--locked", "--release", "--package", "polis", "--bin", "polis", "--target", args.target], cwd=workspace, env=env, check=True) binary = Path(metadata["target_directory"]) / args.target / "release" / "polis" - expected = f"polis {version} (commit {commit}; {source})" + info = identity(ROOT, env) + distance = info["distance"] if info["distance"] is not None else "unknown" + expected = f'polis {info["version_display"]} (commit {commit}; distance {distance}; {source})' if output([str(binary), "--version"], workspace, env) != expected: raise ValueError("Built binary version does not match source metadata.") # Version/help must work without a profile, sign-in, or server request. diff --git a/scripts/build_identity.py b/scripts/build_identity.py new file mode 100644 index 000000000..8c4e12d5c --- /dev/null +++ b/scripts/build_identity.py @@ -0,0 +1,118 @@ +"""Build-time Polis identity, shared by the server, browsers and CLI.""" +import argparse +import json +import os +from pathlib import Path +import re +import subprocess + +ROOT = Path(__file__).resolve().parents[1] +SEMVER = r'(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)' +SHA = r'[0-9a-f]{40}' + + +def git(root, *args): + try: + return subprocess.check_output(['git', '-C', str(root), *args], + stderr=subprocess.DEVNULL, text=True).strip() + except (OSError, subprocess.CalledProcessError): + return None + + +def identity(root=ROOT, env=None): + env = os.environ if env is None else env + raw_version = (root / 'VERSION').read_text() + version = raw_version.removesuffix('\n') + if not re.fullmatch(SEMVER + r'\n', raw_version): + raise ValueError('VERSION must contain MAJOR.MINOR.PATCH') + # Do not accidentally identify an archive by an enclosing checkout. + top = git(root, 'rev-parse', '--show-toplevel') + head = git(root, 'rev-parse', 'HEAD') if top and Path(top).resolve() == root.resolve() else None + declared = env.get('POLIS_BUILD_COMMIT') or env.get('GIT_HASH') + commit = declared or head or 'unknown' + # Existing CI images deliberately use these labels instead of source hashes. + # Keep them explicit and never let them claim stable provenance or distance. + test_label = commit in ('test', 'characterization') + if test_label: + if env.get('POLIS_BUILD_TAG') or env.get('POLIS_BUILD_SOURCE') == 'clean-checkout': + raise ValueError('Test commit labels cannot assert stable provenance') + head = None + if commit != 'unknown' and not test_label and not re.fullmatch(SHA, commit): + raise ValueError('Build commit must be a full lowercase Git hash or unknown') + if head and declared and head != declared: + raise ValueError('Build commit does not match checkout HEAD') + source = env.get('POLIS_BUILD_SOURCE') or ('development' if head else 'unverified-archive') + if source not in ('development', 'clean-checkout', 'unverified-archive'): + raise ValueError('Invalid build source') + if source == 'clean-checkout' and commit == 'unknown': + raise ValueError('clean-checkout requires a commit') + if test_label: + source = 'test-label' + distance = None if test_label else env.get('POLIS_BUILD_DISTANCE') + tag = env.get('POLIS_BUILD_TAG') or '' + stable = False + if head: + exact_tag = git(root, 'for-each-ref', '--points-at', head, '--format=%(refname:short)', 'refs/tags') or '' + stable_chain = (git(root, 'rev-list', '--first-parent', 'origin/stable') or '').splitlines() + on_stable = head in stable_chain + clean = git(root, 'status', '--porcelain', '--untracked-files=normal') == '' + stable = bool(on_stable and clean and source != 'unverified-archive' + and f'v{version}' in exact_tag.splitlines()) + if tag and (tag != f'v{version}' or not stable): + raise ValueError('Declared stable tag does not match a clean stable checkout') + # First-parent set difference counts edge commits even when a stable + # promotion merge itself is absent from edge's first-parent chain. + baseline = (root / 'VERSION_STABLE_COMMIT').read_text().strip() + if not re.fullmatch(SHA, baseline): + raise ValueError('Invalid stable baseline commit') + tagged_base = git(root, 'rev-parse', '--verify', f'refs/tags/v{version}^{{commit}}') + if tagged_base and tagged_base in stable_chain: + baseline = tagged_base + calculated = None + if git(root, 'rev-parse', '--is-shallow-repository') == 'false': + calculated = git(root, 'rev-list', '--first-parent', '--count', f'{baseline}..{head}') + if distance not in (None, '', 'unknown') and calculated is not None and distance != calculated: + raise ValueError('Build distance does not match checkout history') + distance = calculated if calculated is not None else distance + elif tag: + # Archive callers must provide all metadata from a verified stable tag. + if tag != f'v{version}' or commit == 'unknown' or distance != '0' or source != 'clean-checkout': + raise ValueError('Stable archive requires matching tag, commit, zero distance and verified source') + stable = True + if stable: + distance = '0' + if not env.get('POLIS_BUILD_SOURCE'): + source = 'clean-checkout' + if distance in (None, '', 'unknown'): + distance = None + elif not re.fullmatch(r'0|[1-9][0-9]*', str(distance)): + raise ValueError('Build distance must be a nonnegative integer or unknown') + else: + distance = int(distance) + display = version if stable else f'{version}+dev.{distance if distance is not None else "unknown"}.{commit[:12]}' + return dict(version_base=version, version_display=display, commit=commit, + distance=distance, channel='stable' if stable else 'development', source=source) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--root', type=Path, default=ROOT) + parser.add_argument('--format', choices=['json', 'env', 'typescript'], default='json') + parser.add_argument('--output', type=Path) + args = parser.parse_args() + info = identity(args.root) + if args.format == 'env': + text = '\n'.join(f'{key}={value if value is not None else "unknown"}' for key, value in info.items()) + '\n' + elif args.format == 'typescript': + text = 'export const buildInfo = Object.freeze(' + json.dumps(info, indent=2) + ');\n' + else: + text = json.dumps(info, indent=2) + '\n' + if args.output: + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(text) + else: + print(text, end='') + + +if __name__ == '__main__': + main() diff --git a/scripts/prepare-polis-cli-differential.sh b/scripts/prepare-polis-cli-differential.sh index 5c3adda02..7ae8b975a 100644 --- a/scripts/prepare-polis-cli-differential.sh +++ b/scripts/prepare-polis-cli-differential.sh @@ -4,7 +4,7 @@ set -euo pipefail cd "$(dirname "$0")/.." : "${CLI_DIFF_NODE_IMAGE:?}" "${CLI_DIFF_POSTGRES_IMAGE:?}" "${CLI_DIFF_OIDC_IMAGE:?}" "${CLI_DIFF_RUST_IMAGE:?}" (cd polis-cli && cargo build --locked -p polis --features fixture-ids) -docker build --target prod --build-arg NODE_ENV=production -t "$CLI_DIFF_NODE_IMAGE" -f server/Dockerfile server +docker build --target prod --build-arg NODE_ENV=production -t "$CLI_DIFF_NODE_IMAGE" -f server/Dockerfile . docker build --build-context queue-rs=queue-rs -t "$CLI_DIFF_POSTGRES_IMAGE" -f server/Dockerfile-db server docker build -t "$CLI_DIFF_OIDC_IMAGE" oidc-simulator docker build --build-arg FEATURES=fixture-clock -t "$CLI_DIFF_RUST_IMAGE" -f queue-rs/polis-api/Dockerfile queue-rs diff --git a/scripts/prove-dynamo-report.sh b/scripts/prove-dynamo-report.sh index c99cf96ac..6672f14c0 100755 --- a/scripts/prove-dynamo-report.sh +++ b/scripts/prove-dynamo-report.sh @@ -35,7 +35,7 @@ cleanup() { trap cleanup EXIT # Optional dependency caches are read-only inputs. Hosted CI can start empty. if [[ -z "${DYNAMO_PROOF_SERVER_IMAGE:-}" ]]; then - docker build --target dev -t "$proof_image" server > "$DYNAMO_PROOF_OUTPUT/server-image-build.log" 2>&1 + docker build --target dev -t "$proof_image" -f server/Dockerfile . > "$DYNAMO_PROOF_OUTPUT/server-image-build.log" 2>&1 fi if [[ ! -d client-report/node_modules ]]; then (cd client-report && npm ci --no-audit --no-fund) > "$DYNAMO_PROOF_OUTPUT/report-dependencies.log" 2>&1 diff --git a/scripts/test-dynamo-removal.sh b/scripts/test-dynamo-removal.sh index c6081520c..5b0e85a2c 100755 --- a/scripts/test-dynamo-removal.sh +++ b/scripts/test-dynamo-removal.sh @@ -70,7 +70,7 @@ docker run --rm --network none "$image" python -m pytest --noconftest -o addopts # The same server tests and SQL boundary campaign run in hosted CI and on mm5. server_image=${DYNAMO_PROOF_SERVER_IMAGE:-${COMPOSE_PROJECT_NAME}:server} if [[ -z "${DYNAMO_PROOF_SERVER_IMAGE:-}" ]]; then - docker build --target dev -t "$server_image" server > "$proof/server-image-build.log" 2>&1 + docker build --target dev -t "$server_image" -f server/Dockerfile . > "$proof/server-image-build.log" 2>&1 fi export DYNAMO_PROOF_SERVER_IMAGE="$server_image" docker run --rm --network none -v "$repo/server:/candidate:ro" -v "$repo/delphi:/delphi:ro" \ diff --git a/scripts/test-dynamo-writers.sh b/scripts/test-dynamo-writers.sh index 7f6c86b95..71e39ae75 100644 --- a/scripts/test-dynamo-writers.sh +++ b/scripts/test-dynamo-writers.sh @@ -35,7 +35,7 @@ cp "$proof/linux-target/debug/polis-jobs" "$proof/binary/" docker build -f delphi/tests/dynamo_removal/Dockerfile --build-arg "DELPHI_BASE=$base" \ --build-context "queue-binary=$proof/binary" -t "$image" . > "$proof/worker-build.log" 2>&1 if [[ -z "${WRITER_PROOF_SERVER_IMAGE:-}" ]]; then - docker build --target dev -t "$server_image" server > "$proof/server-build.log" 2>&1 + docker build --target dev -t "$server_image" -f server/Dockerfile . > "$proof/server-build.log" 2>&1 fi docker run --rm --network none -v "$repo/server:/candidate:ro" -v "$repo/delphi:/delphi:ro" \ -e DATABASE_URL=postgresql://postgres@127.0.0.1:1/generated --entrypoint sh "$server_image" \ diff --git a/scripts/tests/test_polis_cli_release_identity.py b/scripts/tests/test_polis_cli_release_identity.py new file mode 100644 index 000000000..768e9ed60 --- /dev/null +++ b/scripts/tests/test_polis_cli_release_identity.py @@ -0,0 +1,101 @@ +"""The same build identity is consumed by CLI, server and browser builds.""" +import importlib.util +from pathlib import Path +import tempfile +import unittest +from unittest.mock import patch + +spec = importlib.util.spec_from_file_location('build_identity', Path(__file__).parents[1] / 'build_identity.py') +module = importlib.util.module_from_spec(spec) +spec.loader.exec_module(module) +SHA = 'a' * 40 +BASE = 'b' * 40 + + +class BuildIdentityTest(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + (self.root / 'VERSION').write_text('2.40.0\n') + (self.root / 'VERSION_STABLE_COMMIT').write_text(BASE + '\n') + + def archive(self, **env): + with patch.object(module, 'git', return_value=None): + return module.identity(self.root, env) + + def test_tagged_archive(self): + info = self.archive(GIT_HASH=SHA, POLIS_BUILD_DISTANCE='0', + POLIS_BUILD_TAG='v2.40.0', POLIS_BUILD_SOURCE='clean-checkout') + self.assertEqual(info['version_display'], '2.40.0') + self.assertEqual(info['distance'], 0) + self.assertEqual(info['commit'], SHA) + + def test_untagged_archive(self): + self.assertEqual(self.archive(GIT_HASH=SHA, POLIS_BUILD_DISTANCE='16')['version_display'], + '2.40.0+dev.16.aaaaaaaaaaaa') + + def test_no_git_or_metadata(self): + info = self.archive() + self.assertEqual(info['version_display'], '2.40.0+dev.unknown.unknown') + self.assertIsNone(info['distance']) + + def test_existing_ci_labels_are_explicit(self): + for label in ('test', 'characterization'): + with self.subTest(label=label): + info = self.archive(GIT_HASH=label, POLIS_BUILD_DISTANCE='16') + self.assertEqual(info['commit'], label) + self.assertEqual(info['source'], 'test-label') + self.assertEqual(info['channel'], 'development') + self.assertIsNone(info['distance']) + self.assertEqual(info['version_display'], f'2.40.0+dev.unknown.{label[:12]}') + + def test_ci_label_cannot_claim_stable(self): + for metadata in ({'POLIS_BUILD_TAG': 'v2.40.0'}, {'POLIS_BUILD_SOURCE': 'clean-checkout'}): + with self.subTest(metadata=metadata), self.assertRaises(ValueError): + self.archive(GIT_HASH='test', **metadata) + + def test_invalid_metadata(self): + for env in [dict(GIT_HASH='short'), dict(POLIS_BUILD_DISTANCE='-1'), + dict(POLIS_BUILD_TAG='v2.40.0'), dict(POLIS_BUILD_SOURCE='invalid'), + dict(GIT_HASH=SHA, POLIS_BUILD_DISTANCE='0', POLIS_BUILD_TAG='v2.40.0', POLIS_BUILD_SOURCE='development')]: + with self.subTest(env=env), self.assertRaises(ValueError): + self.archive(**env) + + def test_invalid_version(self): + for value in ['02.40.0\n', '2.40.0', ' 2.40.0\n', '2.40.0\n\n', '2.40.0 # version\n']: + (self.root / 'VERSION').write_text(value) + with self.subTest(value=value), self.assertRaises(ValueError): + self.archive() + + def checkout(self, *, clean=True, on_stable=True, tags='v2.40.0', shallow=False, env=None): + def fake_git(root, *args): + return { + ('rev-parse', '--show-toplevel'): str(self.root), + ('rev-parse', 'HEAD'): SHA, + ('for-each-ref', '--points-at', SHA, '--format=%(refname:short)', 'refs/tags'): tags, + ('rev-list', '--first-parent', 'origin/stable'): SHA + '\n' + BASE if on_stable else BASE, + ('status', '--porcelain', '--untracked-files=normal'): '' if clean else ' M VERSION', + ('rev-parse', '--is-shallow-repository'): 'true' if shallow else 'false', + ('rev-list', '--first-parent', '--count', BASE + '..' + SHA): '16', + }.get(args) + with patch.object(module, 'git', side_effect=fake_git): + return module.identity(self.root, env or {}) + + def test_clean_tag_on_stable(self): + self.assertEqual(self.checkout()['version_display'], '2.40.0') + + def test_edge_tag_cannot_assert_stable(self): + self.assertEqual(self.checkout(on_stable=False)['version_display'], '2.40.0+dev.16.aaaaaaaaaaaa') + + def test_unverified_checkout_cannot_assert_stable(self): + self.assertEqual(self.checkout(env={'POLIS_BUILD_SOURCE': 'unverified-archive'})['channel'], 'development') + + def test_dirty_tag_cannot_assert_stable(self): + self.assertEqual(self.checkout(clean=False)['channel'], 'development') + + def test_untagged_checkout(self): + self.assertEqual(self.checkout(tags='')['distance'], 16) + + def test_shallow_history_is_not_zero(self): + self.assertIsNone(self.checkout(tags='', shallow=True)['distance']) diff --git a/server/Dockerfile b/server/Dockerfile index be5fddfb8..b1d5c63f4 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -3,7 +3,7 @@ # the build command with `DOCKER_BUILDKIT=1`). The `RUN --mount=type=cache` # directives below are silently ignored without BuildKit. # To build locally, for example: -# docker build -t polis-server:local . +# docker build -t polis-server:local -f server/Dockerfile . # To run locally, for example: # docker run --rm --name polis-server --env-file .env --network polis-dev_polis-net \ # -p 5000:5000 --target dev polis-server:local @@ -17,6 +17,7 @@ ARG NODE_ENV WORKDIR /app + # Install Python and necessary tools (including pip) RUN apk add --no-cache python3 py3-pip ca-certificates @@ -33,7 +34,7 @@ RUN apk add libpq-dev RUN apk add --no-cache --virtual .build \ g++ make python3 -COPY package*.json ./ +COPY server/package*.json ./ EXPOSE 5000 @@ -49,7 +50,15 @@ RUN npm config set fetch-retries 5 && \ npm config set fetch-retry-maxtimeout 120000 RUN --mount=type=cache,target=/root/.npm npm ci --production=false -COPY . . +COPY server/. . + +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=$GIT_HASH POLIS_BUILD_DISTANCE=$POLIS_BUILD_DISTANCE POLIS_BUILD_TAG=$POLIS_BUILD_TAG POLIS_BUILD_SOURCE=$POLIS_BUILD_SOURCE +COPY VERSION VERSION_STABLE_COMMIT / +COPY scripts/build_identity.py scripts/build-identity.cjs /scripts/ CMD npm run dev @@ -73,8 +82,16 @@ RUN --mount=type=cache,target=/root/.npm npm ci --production=false # For prod builds, to minimize the image size, remove the dependencies tagged with `--virtual .build` above. RUN apk del .build -COPY . . +COPY server/. . + +ARG GIT_HASH=unknown +ARG POLIS_BUILD_DISTANCE=unknown +ARG POLIS_BUILD_TAG +ARG POLIS_BUILD_SOURCE=unverified-archive +ENV GIT_HASH=$GIT_HASH POLIS_BUILD_DISTANCE=$POLIS_BUILD_DISTANCE POLIS_BUILD_TAG=$POLIS_BUILD_TAG POLIS_BUILD_SOURCE=$POLIS_BUILD_SOURCE +COPY VERSION VERSION_STABLE_COMMIT / +COPY scripts/build_identity.py scripts/build-identity.cjs /scripts/ RUN npm run build -CMD npm run serve \ No newline at end of file +CMD npm run serve diff --git a/server/Dockerfile.dockerignore b/server/Dockerfile.dockerignore new file mode 100644 index 000000000..e0f03db3c --- /dev/null +++ b/server/Dockerfile.dockerignore @@ -0,0 +1,23 @@ +# Preserve the server-context image layout while admitting root identity inputs. +** +!server/ +!server/** +!VERSION +!VERSION_STABLE_COMMIT +!scripts/ +!scripts/build_identity.py +!scripts/build-identity.cjs +server/.env +server/.git +server/.google_creds_temp +server/.venv/ +server/coverage/ +server/dist +server/logs/ +server/node_modules/ +server/npm-debug.log* +**/.env +**/.env.* +**/.google_creds_temp +**/.venv +**/node_modules diff --git a/server/__tests__/unit/version.test.ts b/server/__tests__/unit/version.test.ts new file mode 100644 index 000000000..ec57ca2a8 --- /dev/null +++ b/server/__tests__/unit/version.test.ts @@ -0,0 +1,77 @@ +import { spawnSync } from "node:child_process"; +import { + copyFileSync, + mkdirSync, + mkdtempSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { join, resolve } from "node:path"; +import express from "express"; +import request from "supertest"; +const { cases, fixture } = require("../../../scripts/build-identity-test.cjs"); + +describe("build version endpoint", () => { + test.each(cases)("%s build", async (_name, metadata, expected) => { + const info = fixture(metadata); + jest.resetModules(); + jest.doMock("../../src/generated/build-info", () => ({ buildInfo: info })); + const { handleVersion } = require("../../src/routes/version"); + const app = express(); + app.get("/api/v3/version", handleVersion); + const response = await request(app).get("/api/v3/version").expect(200); + expect(response.body.version_display).toBe(expected); + expect(response.body).toEqual(info); + expect(response.headers["cache-control"]).toBe("no-store"); + }); +}); + +// Use a separate source tree and process: no generated module, no Git, and no +// working-directory dependency. Changing VERSION after import must not change +// the metadata served by the running process. +test("source-only startup reads VERSION once when generated metadata is absent", () => { + const root = mkdtempSync(join(tmpdir(), "polis-version-")); + try { + const route = join(root, "server/src/routes/version.ts"); + mkdirSync(join(root, "server/src/routes"), { recursive: true }); + copyFileSync(resolve(__dirname, "../../src/routes/version.ts"), route); + writeFileSync(join(root, "VERSION"), "2.40.0\n"); + const child = spawnSync( + process.execPath, + [ + "-r", + require.resolve("ts-node/register/transpile-only"), + "-e", + `const { handleVersion } = require(${JSON.stringify(route)}); + require('node:fs').writeFileSync(${JSON.stringify( + join(root, "VERSION") + )}, '9.9.9\\n'); + handleVersion(null, { + setHeader: (name, value) => { if (name !== 'Cache-Control' || value !== 'no-store') throw Error('cache header'); }, + json: value => process.stdout.write(JSON.stringify(value)) + });`, + ], + { + cwd: tmpdir(), + encoding: "utf8", + env: { + ...process.env, + TS_NODE_PROJECT: resolve(__dirname, "../../tsconfig.json"), + }, + } + ); + expect(child.stderr).toBe(""); + expect(child.status).toBe(0); + expect(JSON.parse(child.stdout)).toEqual({ + version_base: "2.40.0", + version_display: "2.40.0+dev.unknown.unknown", + commit: "unknown", + distance: null, + channel: "development", + source: "unverified-archive", + }); + } finally { + rmSync(root, { recursive: true, force: true }); + } +}); diff --git a/server/app.ts b/server/app.ts index 7981927d9..2386552b6 100644 --- a/server/app.ts +++ b/server/app.ts @@ -13,6 +13,7 @@ import express from "express"; import morgan from "morgan"; import timeout from "connect-timeout"; +import { handleVersion } from "./src/routes/version"; import server from "./src/server"; import Config from "./src/config"; import { makeFileFetcher } from "./src/utils/file-fetcher"; @@ -368,6 +369,7 @@ export const appReady = helpersInitialized.then( //////////////////////////////////////////// //////////////////////////////////////////// + app.get("/api/v3/version", handleVersion); app.get("/api/v3/math/pca", handle_GET_math_pca); app.get( diff --git a/server/characterization/collective-statement/mutations.cjs b/server/characterization/collective-statement/mutations.cjs index 8061703f4..edc994340 100644 --- a/server/characterization/collective-statement/mutations.cjs +++ b/server/characterization/collective-statement/mutations.cjs @@ -44,6 +44,7 @@ function parseArgs(argv) { function scratchCopy() { const root = fs.mkdtempSync(path.join(os.tmpdir(), "csrec-mutation-")); const dest = path.join(root, "server"); + fs.copyFileSync(path.join(ROOT, "VERSION"), path.join(root, "VERSION")); fs.cpSync(SERVER, dest, { recursive: true, filter: (src) => diff --git a/server/package.json b/server/package.json index 6c6676d6e..78b6fb568 100644 --- a/server/package.json +++ b/server/package.json @@ -13,6 +13,7 @@ "start": "npm run build && npm run serve", "dev": "npm install && npm run build:watch", "type:check:watch": "tsc --watch", + "pretype:check:watch": "npm run build:identity", "format": "prettier --config ./prettier.config.js --no-editorconfig '**/*.ts' --write", "format:check": "prettier --config ./prettier.config.js --no-editorconfig '**/*.ts' --check", "lint": "eslint --quiet --ext .ts,.js,.cjs .", @@ -22,7 +23,11 @@ "test": "if [ -z \"$NODE_EXTRA_CA_CERTS\" ] && command -v mkcert >/dev/null 2>&1; then export NODE_EXTRA_CA_CERTS=$(mkcert -CAROOT)/rootCA.pem; fi && jest", "test:unit": "npm test -- /__tests__/unit/", "test:integration": "npm test -- /__tests__/integration/", - "test:feature": "npm test -- /__tests__/feature/ --testPathIgnorePatterns=[]" + "test:feature": "npm test -- /__tests__/feature/ --testPathIgnorePatterns=[]", + "build:identity": "python3 ../scripts/build_identity.py --format typescript --output src/generated/build-info.ts", + "prebuild": "npm run build:identity", + "prebuild:watch": "npm run build:identity", + "pretest": "npm run build:identity" }, "repository": { "type": "git", diff --git a/server/src/routes/version.ts b/server/src/routes/version.ts new file mode 100644 index 000000000..72ea6f5fe --- /dev/null +++ b/server/src/routes/version.ts @@ -0,0 +1,50 @@ +import { readFileSync } from "node:fs"; +import { basename, resolve } from "node:path"; + +interface BuildInfo { + version_base: string; + version_display: string; + commit: string; + distance: number | null; + channel: string; + source: string; +} + +function loadBuildInfo(): BuildInfo { + let generated: string; + try { + generated = require.resolve("../generated/build-info"); + } catch (error) { + if (error.code !== "MODULE_NOT_FOUND") throw error; + // Source-only harnesses do not run prebuild. Read the root version once, + // without Git or environment overrides, and report unknown provenance. + // Compiled routes have one extra directory level (server/dist/src/routes). + const root = + basename(resolve(__dirname, "../..")) === "dist" + ? "../../../../VERSION" + : "../../../VERSION"; + const version = readFileSync(resolve(__dirname, root), "utf8").trim(); + return Object.freeze({ + version_base: version, + version_display: `${version}+dev.unknown.unknown`, + commit: "unknown", + distance: null, + channel: "development", + source: "unverified-archive", + }); + } + return require(generated).buildInfo; +} + +const buildInfo = loadBuildInfo(); + +export function handleVersion( + _req: unknown, + res: { + setHeader: (name: string, value: string) => unknown; + json: (value: BuildInfo) => unknown; + } +) { + res.setHeader("Cache-Control", "no-store"); + res.json(buildInfo); +} From dd4d86b94dd17dbf712d05d6faca760f9dcaa9ff Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Wed, 21 Oct 2026 11:34:50 -0700 Subject: [PATCH 21/30] version: a tool computes the next Polis version from the last stable tag and the promoted range (#3248) polis-version applies the one rule (a promotion that ships a migration is a minor bump, otherwise a patch; the major never moves; hotfixes follow the same rule; a redeploy gets no new number), prints the plan as text or JSON, dry-run by default, and extends the seeded history of promotions since 2.0.0 to the given stable commit. Nothing calls it yet. Co-authored-by: Claude Fable 5.1 --- queue-rs/src/bin/polis-version/README.md | 239 ++++++ .../src/bin/polis-version/contract_tests.rs | 194 +++++ queue-rs/src/bin/polis-version/git.rs | 133 ++++ queue-rs/src/bin/polis-version/main.rs | 715 ++++++++++++++++++ queue-rs/src/bin/polis-version/model.rs | 429 +++++++++++ queue-rs/src/bin/polis-version/preparation.rs | 291 +++++++ queue-rs/src/bin/polis-version/seed.json | 8 + 7 files changed, 2009 insertions(+) create mode 100644 queue-rs/src/bin/polis-version/README.md create mode 100644 queue-rs/src/bin/polis-version/contract_tests.rs create mode 100644 queue-rs/src/bin/polis-version/git.rs create mode 100644 queue-rs/src/bin/polis-version/main.rs create mode 100644 queue-rs/src/bin/polis-version/model.rs create mode 100644 queue-rs/src/bin/polis-version/preparation.rs create mode 100644 queue-rs/src/bin/polis-version/seed.json diff --git a/queue-rs/src/bin/polis-version/README.md b/queue-rs/src/bin/polis-version/README.md new file mode 100644 index 000000000..1f3cff68c --- /dev/null +++ b/queue-rs/src/bin/polis-version/README.md @@ -0,0 +1,239 @@ +# Computing a Polis release number + +`polis-version` is an offline repository tool in the existing queue adapter +package. It uses that package's toolchain and dependencies and is included in +its normal unit-test and Clippy commands. Nothing invokes it from a workflow or +serving process. It opens no database or network connection and never applies +migrations, creates commits or tags, or publishes releases. + +Build from `queue-rs`: + +```sh +cargo build --locked --bin polis-version +``` + +Supply a local repository with complete stable/source history and all published +canonical version tags. The caller is responsible for refreshing those inputs; +the tool does not contact a remote. Shallow repositories and replacement objects +are refused. Full immutable commit IDs are preferable to moving branch names. +The default repository is the current directory and default stable ref is +`origin/stable`. Repository paths may point to bare repositories for read-only +commands. + +```sh +# Print a proposed number and the release.txt filenames responsible for it. +queue-rs/target/debug/polis-version plan --repo . \ + --stable origin/stable --candidate origin/edge + +# The same computation as structured JSON, without changing files. +queue-rs/target/debug/polis-version plan --repo . \ + --stable origin/stable --candidate origin/edge --json + +# A source branch that incorporates current stable uses the same bump rule. +queue-rs/target/debug/polis-version plan --repo . \ + --stable origin/stable --candidate hotfix --kind hotfix --json + +# Reusing an older stable artifact keeps its known number; allocates nothing. +queue-rs/target/debug/polis-version plan --repo . \ + --stable origin/stable --candidate v2.38.1 --kind redeploy --json + +# Extend the built-in historical seed along stable's first-parent lineage. +queue-rs/target/debug/polis-version history --repo . --stable origin/stable --json + +# Explicit alternative interpretation of the historical manifest transition. +queue-rs/target/debug/polis-version history --repo . --stable origin/stable \ + --rule literal-manifest-lines --json +``` + +Paths above assume Cargo's normal target directory; respect `CARGO_TARGET_DIR` +when it is set. Text goes to stdout by default; `--json` emits one JSON document +instead. Diagnostics go to stderr with a nonzero exit status. Redirect stdout +to retain a plan or history. Output contains no current time or local paths; +repeating a command against unchanged inputs produces identical bytes. + +## Rules + +The `effective-selection` rule increments MINOR and resets PATCH to zero +when the candidate adds one or more selected migration filenames. Otherwise it +increments PATCH. It never increments MAJOR. The number comes from the last +canonical `vMAJOR.MINOR.PATCH` tag on the stable first-parent lineage, never from +the working tree's VERSION value. Tags must increase along that lineage, cannot +assign two numbers to one commit, and the latest must identify the given stable +head. A pending untagged promotion after a release tag must be completed before +another number is allocated. Tags outside that lineage are refused. + +Only exact nonblank, noncomment filename lines are selected. Whitespace within +a filename, duplicate migration numbers, missing selected files and nonregular +migration files are errors. Reordering or comments do not count. Files held out +of the manifest do not count until selected. Adding a migration and removing it +again before the final candidate does not ship it. Data-only migrations follow +the same rule. Prospective releases refuse removal, renaming or any byte change +to a previously selected SQL file; Git blob identities check the exact bytes. +A prospective release must have a manifest. + +For ordinary promotions, the current stable tree must equal its source parent's +tree and the candidate must retain that source ancestry. Those conditions make +the candidate tree the promotion result without running a merge or writing Git +objects. Stable-only changes must first be reconciled. A hotfix must descend +from the current stable commit. Both kinds reject empty or preparation-only +promotions. Preparation includes root VERSION and the generated version lines +in `polis-cli/Cargo.toml` (`[workspace.package].version`) and `polis-cli/Cargo.lock` +(the local `polis` and `polis-client` package versions). The shared contracts +package is independently versioned and is not ignored. Only canonical quoted +version lines in the existing generated layout are normalized; unfamiliar +layouts remain substantive. Other bytes, dependency/build changes, additions, +deletions and file-mode changes still count. The tool does not regenerate these +mirrors. A committed revert is new code and follows the same rule; a redeploy +of a known stable first-parent commit retains its original number. Later +forward plans still use the latest stable head, independent of what is serving. + +Named refs and the tag inventory are rechecked before output or writing. The +future promotion caller must bind its approval to these inputs and revalidate +them before merging/publishing. This tool does not authorize those operations. + +## JSON contracts + +All fields below are always present; nullable fields use JSON `null`, never an +omitted key. Versions are canonical `MAJOR.MINOR.PATCH` strings, not numbers. +Commit/tree/blob identities are full Git object ID strings. A `rule` is either +`effective-selection` or `literal-manifest-lines`. Filename arrays are sorted +and contain migration basenames. PR numbers and counts are unsigned integers. +These schema identifiers and exact keys are covered by serialization tests. + +`polis.release-plan/1`: + +| Field | JSON type | Meaning | +|---|---|---| +| `schema` | string | Exactly `polis.release-plan/1`. | +| `rule` | string | Selected counting rule. | +| `kind` | string | `promotion`, `hotfix`, or `redeploy`. | +| `version` | string | Computed number; original number for redeploy. | +| `previous_version` | string | Latest stable number, also for redeploy. | +| `bump` | string | `minor`, `patch`, or `none` (redeploy). | +| `reason` | string | Human-readable explanation; use `bump` for branching. | +| `release_lines` | array of strings | Added filenames counted by the selected rule; empty for patch/redeploy. | +| `previous_stable_commit` | string | Resolved latest stable commit. | +| `candidate_commit` | string | Resolved proposed source or redeploy target. | +| `previous_tree` | string | Stable tree object ID. | +| `candidate_tree` | string | Candidate tree object ID. | +| `previous_manifest_blob` | string or null | Stable manifest blob; null if absent. | +| `candidate_manifest_blob` | string or null | Candidate manifest blob; null if absent (historical redeploy). | +| `previous_tag` | string or null | Canonical latest stable tag; null during bootstrap. | +| `new_number` | boolean | True for promotion/hotfix; false for redeploy. | + +`polis.release-history/1`: + +| Field | JSON type | Meaning | +|---|---|---| +| `schema` | string | Exactly `polis.release-history/1`. | +| `rule` | string | Selected counting rule. | +| `seed_sha256` | string | Lowercase 64-hex SHA-256 of exact seed input bytes. | +| `promotions` | array of objects | Seed row first, then chronological first-parent promotions; row fields below. | + +Each promotion object: + +| Field | JSON type | Meaning | +|---|---|---| +| `version` | string | Number after this promotion, or supplied seed number. | +| `previous_version` | string or null | Prior row's version; null only on the seed row. | +| `date` | string | Git committer ISO 8601 timestamp, including offset. | +| `stable_commit` | string | Stable promotion commit. | +| `source_commit` | string | Promotion's second parent. | +| `migrations_shipped` | array of strings | Actual additions to effective selection, even when using literal counting. | +| `bump_lines` | array of strings | Added filenames under the chosen rule; empty on the seed row. Can differ from `migrations_shipped`. | +| `migrations_removed` | array of strings | Effective selections removed since the preceding endpoint. | +| `bump` | string | `seed` on the first row, then `minor` or `patch`. | +| `selection_evidence` | string | Committed manifest or recognized historical initializer identity. | +| `manifest_blob` | string or null | Manifest blob ID; null before a manifest exists. | +| `promotion_pr` | integer or null | Public enclosing promotion PR from Git subject; null if unrecognized. The seed requires a number. | +| `pr_count` | integer | Length of `prs`. | +| `prs` | array of integers | Sorted unique source-range PR subject references, excluding the enclosing promotion. | + +The seed row records its actual migration additions/removals relative to its +first parent and its source-range PRs. Its version is supplied, not recomputed: +`previous_version=null`, `bump="seed"`, `bump_lines=[]`. A nonempty +`migrations_shipped` on that row does not allocate another number. + +Seed input (`polis.release-seed/1`); every field is required and non-null, +and unknown keys are rejected: + +| Field | JSON type | Meaning | +|---|---|---| +| `schema` | string | Exactly `polis.release-seed/1`. | +| `version` | string | Trusted historical baseline number. | +| `stable_commit` | string | Full stable promotion commit on the supplied lineage. | +| `source_commit` | string | Full second-parent commit, verified against Git. | +| `date` | string | Exact Git committer ISO 8601 timestamp, verified against Git. | +| `promotion_pr` | integer | Public promotion PR number, verified against the Git subject. | + +## Bootstrap history + +`src/bin/polis-version/seed.json` contains the normalized terminal historical +baseline: `2.34.0` at stable commit +`fd16f790a01d433aa338c06aea77499cf39b9944` (PR #2957). Its source parent, commit +date and public promotion number are checked against Git. This is a supplied +baseline, not a reclassification of the releases preceding it. `--history PATH` +can supply a seed of the same strict `polis.release-seed/1` format. A seed is a +trusted numbering input: its number is not inferred from SQL or VERSION. + +The history command returns the seed row followed by one row per two-parent +first-parent promotion. Each row includes version, previous version, date, +stable and source commits, actual newly selected migrations, counted bump +lines, removed selections, selection evidence, manifest blob, public promotion +PR, and unique PR references/count from merge or squash subjects in the newly +promoted source range. The seed row's bump is `seed`; it does not allocate a new +number. The result includes the SHA-256 of the exact seed bytes. PR counts +exclude the enclosing promotion PR. They describe Git subject references; +release-note publication should resolve GitHub associations and handle direct +commits with no PR reference explicitly. + +Before a manifest exists, effective selection requires the historical +`server/Dockerfile-db` rule copying root migration SQL into the initializer. +Down/archive directories are excluded. An unrecognized or ambiguous rule stops +the walk. A manifest's first appearance compares against that established set, +so relisting old SQL does not count as new. Historical removal/reintroduction +records what each endpoint selected; it does not relax prospective validation. + +The alternative `literal-manifest-lines` rule counts only additions relative to +the previous manifest (absent manifest = no lines). Actual selected additions +remain separately available in `migrations_shipped`; `bump_lines` explains the +number under the chosen rule. Both walks preserve the same seed. Through +`d2da302d0f94fb29fa0e7fde27299509c6f5f28b`, the 34 subsequent promotions yield +`2.41.0` (effective: seven minor, 27 patch) or `2.40.0` (literal: six minor, +28 patch). Omitting `--rule` selects the single `DEFAULT_RULE` constant in `model.rs`; +the help output prints its configured value. Both explicit flags override it. +These computations neither create historical tags nor claim old binaries +embedded these numbers. Once tags exist, prospective computation uses them. + +## Writing VERSION + +Only `plan --write` writes anything. It requires a nonbare checkout at the exact +candidate HEAD, clean except for VERSION, and a regular root VERSION file. +It atomically replaces that file with the computed number and a newline, +preserving permissions. A previous abandoned VERSION edit is overwritten from +the stable baseline; it never reserves a number. No Cargo mirror is changed. +`history --write` and `--kind redeploy --write` are refused. Without `--write`, +even a plan run inside a dirty checkout is read-only and uses committed inputs. + +## Verification + +The ordinary existing CI entries from `queue-rs` include this binary: + +```sh +cargo test --locked +cargo clippy --locked --all-targets -- -D warnings +cargo clippy --locked --all-targets --features jobs-integration -- -D warnings +cargo fmt -p polis-queue-adapter --check +``` + +The full-history regression is explicitly opt-in because ordinary hosted source +checkouts are shallow. It fails if the history variable is absent or incomplete; +it does not silently skip cases. It verifies both real bootstrap walks, the +manifest transition and committed rollback, patch/minor hotfix computation, +redeploy/next-forward behavior, rejected ancestry, seed validation, and repeated +JSON identity: + +```sh +POLIS_VERSION_TEST_REPO=/path/to/complete/polis \ + cargo test --locked --bin polis-version -- --ignored --nocapture +``` diff --git a/queue-rs/src/bin/polis-version/contract_tests.rs b/queue-rs/src/bin/polis-version/contract_tests.rs new file mode 100644 index 000000000..4812259ee --- /dev/null +++ b/queue-rs/src/bin/polis-version/contract_tests.rs @@ -0,0 +1,194 @@ +use super::*; +use serde_json::{Value, json}; + +// Compare the entire key set as well as every value's JSON type. Nullability is +// exercised with both variants, rather than accepting any value for null fields. +fn fields(value: &Value, strings: &[&str], rest: &[(&str, &str)]) { + let object = value.as_object().unwrap(); + let expected: BTreeSet<_> = strings + .iter() + .copied() + .chain(rest.iter().map(|(k, _)| *k)) + .collect(); + assert_eq!( + object.keys().map(String::as_str).collect::>(), + expected + ); + for key in strings { + assert!(object[*key].is_string(), "{key}"); + } + for (key, kind) in rest { + let v = &object[*key]; + assert!( + match *kind { + "null" => v.is_null(), + "string" => v.is_string(), + "bool" => v.is_boolean(), + "u64" => v.as_u64().is_some(), + "strings" => v.as_array().is_some_and(|a| a.iter().all(Value::is_string)), + "integers" => v + .as_array() + .is_some_and(|a| a.iter().all(|v| v.as_u64().is_some())), + "objects" => v.as_array().is_some_and(|a| a.iter().all(Value::is_object)), + _ => panic!("unknown contract type {kind}"), + }, + "{key}: {v}" + ); + } +} + +#[test] +fn seed_exact_contract() { + let seed: Seed = serde_json::from_str(SEED).unwrap(); + let value = serde_json::to_value(seed).unwrap(); + fields( + &value, + &[ + "schema", + "version", + "stable_commit", + "source_commit", + "date", + ], + &[("promotion_pr", "u64")], + ); + assert_eq!(value["schema"], "polis.release-seed/1"); + assert_eq!(value, serde_json::from_str::(SEED).unwrap()); + let mut extra = value.clone(); + extra["extra"] = json!(true); + assert!(serde_json::from_value::(extra).is_err()); + for key in value.as_object().unwrap().keys() { + let mut missing = value.clone(); + missing.as_object_mut().unwrap().remove(key); + assert!(serde_json::from_value::(missing).is_err(), "{key}"); + let mut null = value.clone(); + null[key] = Value::Null; + assert!(serde_json::from_value::(null).is_err(), "{key}"); + } +} + +#[test] +fn plan_exact_contract_and_nullability() { + let mut p = Plan { + schema: "polis.release-plan/1", + rule: Rule::Effective.name(), + kind: "promotion".into(), + version: "2.42.0".into(), + previous_version: "2.41.0".into(), + bump: "minor".into(), + reason: "new selected migrations".into(), + release_lines: vec!["000001_one.sql".into()], + previous_stable_commit: "a".repeat(40), + candidate_commit: "b".repeat(40), + previous_tree: "c".repeat(40), + candidate_tree: "d".repeat(40), + previous_manifest_blob: None, + candidate_manifest_blob: None, + previous_tag: None, + new_number: true, + }; + for kind in ["null", "string"] { + if kind == "string" { + p.previous_manifest_blob = Some("e".repeat(40)); + p.candidate_manifest_blob = Some("f".repeat(40)); + p.previous_tag = Some("v2.41.0".into()); + } + let v = serde_json::to_value(&p).unwrap(); + fields( + &v, + &[ + "schema", + "rule", + "kind", + "version", + "previous_version", + "bump", + "reason", + "previous_stable_commit", + "candidate_commit", + "previous_tree", + "candidate_tree", + ], + &[ + ("release_lines", "strings"), + ("previous_manifest_blob", kind), + ("candidate_manifest_blob", kind), + ("previous_tag", kind), + ("new_number", "bool"), + ], + ); + assert_eq!(v["schema"], "polis.release-plan/1"); + assert_eq!(v["new_number"], true); + } +} + +#[test] +fn history_and_promotion_exact_contract_and_seed_semantics() { + let mut row = Promotion { + version: "2.34.0".into(), + previous_version: None, + date: "2026-10-04T16:27:11-07:00".into(), + stable_commit: "a".repeat(40), + source_commit: "b".repeat(40), + migrations_shipped: vec!["000001_one.sql".into()], + bump_lines: vec![], + migrations_removed: vec![], + bump: "seed".into(), + selection_evidence: "committed manifest".into(), + manifest_blob: None, + promotion_pr: Some(3), + pr_count: 2, + prs: vec![1, 2], + }; + for nullable in [true, false] { + if !nullable { + row.previous_version = Some("2.34.0".into()); + row.version = "2.35.0".into(); + row.bump = "minor".into(); + row.bump_lines = row.migrations_shipped.clone(); + row.manifest_blob = Some("c".repeat(40)); + row.promotion_pr = None; + } + let v = serde_json::to_value(&row).unwrap(); + fields( + &v, + &[ + "version", + "date", + "stable_commit", + "source_commit", + "bump", + "selection_evidence", + ], + &[ + ("previous_version", if nullable { "null" } else { "string" }), + ("manifest_blob", if nullable { "null" } else { "string" }), + ("promotion_pr", if nullable { "u64" } else { "null" }), + ("pr_count", "u64"), + ("prs", "integers"), + ("migrations_shipped", "strings"), + ("bump_lines", "strings"), + ("migrations_removed", "strings"), + ], + ); + assert_eq!(v["pr_count"], v["prs"].as_array().unwrap().len()); + if nullable { + assert_eq!(v["bump"], "seed"); + assert_eq!(v["bump_lines"], json!([])); + } + let h = serde_json::to_value(History { + schema: "polis.release-history/1", + rule: Rule::Literal.name(), + seed_sha256: "a".repeat(64), + promotions: vec![row.clone()], + }) + .unwrap(); + fields( + &h, + &["schema", "rule", "seed_sha256"], + &[("promotions", "objects")], + ); + assert_eq!(h["schema"], "polis.release-history/1"); + assert_eq!(h["promotions"][0], v); + } +} diff --git a/queue-rs/src/bin/polis-version/git.rs b/queue-rs/src/bin/polis-version/git.rs new file mode 100644 index 000000000..ecc232b0b --- /dev/null +++ b/queue-rs/src/bin/polis-version/git.rs @@ -0,0 +1,133 @@ +use crate::model::{MIGRATIONS, Selection, legacy_names, manifest, selected_blobs}; +use anyhow::{Context, Result, ensure}; +use std::{ + collections::BTreeMap, + path::{Path, PathBuf}, + process::Command, +}; + +pub struct Git { + pub path: PathBuf, +} +impl Git { + pub fn new(path: &Path) -> Result { + let git = Self { + path: path.canonicalize()?, + }; + ensure!( + git.run(&["rev-parse", "--is-shallow-repository"])? == "false", + "complete history required; shallow repository refused" + ); + ensure!( + git.run(&["replace", "-l"])?.is_empty(), + "replace objects are not release provenance" + ); + Ok(git) + } + pub fn run(&self, args: &[&str]) -> Result { + Ok(String::from_utf8(self.bytes(args)?)? + .trim_end_matches('\n') + .to_owned()) + } + pub fn bytes(&self, args: &[&str]) -> Result> { + let out = Command::new("git") + .arg("-C") + .arg(&self.path) + .args(args) + .env("GIT_NO_REPLACE_OBJECTS", "1") + .env("GIT_OPTIONAL_LOCKS", "0") + .output() + .context("run Git")?; + ensure!( + out.status.success(), + "git {} failed: {}", + args.join(" "), + String::from_utf8_lossy(&out.stderr) + ); + Ok(out.stdout) + } + pub fn resolve(&self, name: &str) -> Result { + self.run(&[ + "rev-parse", + "--verify", + "--end-of-options", + &format!("{name}^{{commit}}"), + ]) + } + pub fn tree(&self, commit: &str) -> Result { + self.run(&["rev-parse", &format!("{commit}^{{tree}}")]) + } + pub fn parents(&self, commit: &str) -> Result> { + Ok(self + .run(&["show", "-s", "--format=%P", commit])? + .split_whitespace() + .map(str::to_owned) + .collect()) + } + pub fn lineage(&self, stable: &str) -> Result> { + Ok(self + .run(&["rev-list", "--first-parent", stable])? + .lines() + .map(str::to_owned) + .collect()) + } + pub fn ancestor(&self, base: &str, head: &str) -> Result { + Ok(self.run(&["merge-base", base, head])? == base) + } + pub fn text(&self, commit: &str, path: &str) -> Result { + self.run(&["show", &format!("{commit}:{path}")]) + } + pub fn selection(&self, commit: &str) -> Result { + let tree = self.run(&["ls-tree", &format!("{commit}:{MIGRATIONS}")])?; + let mut blobs = BTreeMap::new(); + for entry in tree.lines() { + let (meta, name) = entry.split_once('\t').context("invalid Git tree entry")?; + let fields: Vec<_> = meta.split_whitespace().collect(); + if name.ends_with(".sql") || name == "release.txt" { + ensure!( + fields.len() == 3 && fields[0] == "100644" && fields[1] == "blob", + "migration input must be a regular file: {name}" + ); + blobs.insert(name.to_owned(), fields[2].to_owned()); + } + } + let manifest_blob = blobs.get("release.txt").cloned(); + let (names, evidence) = if manifest_blob.is_some() { + ( + manifest(&self.text(commit, &format!("{MIGRATIONS}/release.txt"))?)?, + format!("{commit}:{MIGRATIONS}/release.txt"), + ) + } else { + // Recognize the historical initializer explicitly. No guess based only on filenames. + let dockerfile = self.text(commit, "server/Dockerfile-db")?; + let selection_line = "COPY ./postgres/migrations/*.sql /docker-entrypoint-initdb.d/"; + let names = legacy_names(&dockerfile, &blobs)?; + ( + names, + format!("{commit}:server/Dockerfile-db: {selection_line}"), + ) + }; + let files = selected_blobs(&blobs, &names)?; + Ok(Selection { + files, + manifest: manifest_blob, + evidence, + }) + } + pub fn tags(&self) -> Result> { + let mut tags = Vec::new(); + for name in self + .run(&["for-each-ref", "--format=%(refname:strip=2)", "refs/tags"])? + .lines() + { + if let Some(v) = name + .strip_prefix('v') + .and_then(|s| crate::model::Version::parse(s).ok()) + { + tags.push((v, self.resolve(&format!("refs/tags/{name}"))?)); + } + } + tags.sort(); + Ok(tags) + } +} diff --git a/queue-rs/src/bin/polis-version/main.rs b/queue-rs/src/bin/polis-version/main.rs new file mode 100644 index 000000000..ab020fb35 --- /dev/null +++ b/queue-rs/src/bin/polis-version/main.rs @@ -0,0 +1,715 @@ +//! Offline release-number computation. No network, database, tag or publication operations. +mod git; +mod model; +mod preparation; +use anyhow::{Context, Result, bail, ensure}; +use git::Git; +use model::*; +use serde::Serialize; +use sha2::{Digest, Sha256}; +use std::{collections::BTreeSet, fs, path::PathBuf}; + +const SEED: &str = include_str!("seed.json"); + +fn history(git: &Git, stable: &str, input: &str, rule: Rule) -> Result { + let seed: Seed = serde_json::from_str(input)?; + ensure!( + seed.schema == "polis.release-seed/1", + "unsupported seed schema" + ); + let mut version = Version::parse(&seed.version)?; + ensure!( + git.resolve(&seed.stable_commit)? == seed.stable_commit + && git.resolve(&seed.source_commit)? == seed.source_commit, + "seed requires full commit identities" + ); + let lineage = git.lineage(stable)?; + let at = lineage + .iter() + .position(|s| s == &seed.stable_commit) + .context("seed not on stable first-parent lineage")?; + let parents = git.parents(&seed.stable_commit)?; + ensure!( + parents.len() == 2 && parents[1] == seed.source_commit, + "seed source must be promotion second parent" + ); + ensure!( + git.run(&["show", "-s", "--format=%cI", &seed.stable_commit])? == seed.date, + "seed timestamp mismatch" + ); + ensure!( + pr_number(&git.run(&["show", "-s", "--format=%s", &seed.stable_commit])?) + == Some(seed.promotion_pr), + "seed promotion PR mismatch" + ); + let mut old = git.selection(&seed.stable_commit)?; + let seed_previous = git.selection(&parents[0])?; + let seed_prs: BTreeSet<_> = git + .run(&[ + "log", + "--format=%s", + &format!("{}..{}", parents[0], parents[1]), + ])? + .lines() + .filter_map(pr_number) + .collect(); + let mut promotions = vec![Promotion { + version: version.to_string(), + previous_version: None, + date: seed.date, + stable_commit: seed.stable_commit.clone(), + source_commit: seed.source_commit, + migrations_shipped: added(&seed_previous, &old, Rule::Effective, true)?, + bump_lines: vec![], + migrations_removed: seed_previous + .files + .keys() + .filter(|n| !old.files.contains_key(*n)) + .cloned() + .collect(), + bump: "seed".into(), + selection_evidence: old.evidence.clone(), + manifest_blob: old.manifest.clone(), + promotion_pr: Some(seed.promotion_pr), + pr_count: seed_prs.len(), + prs: seed_prs.into_iter().collect(), + }]; + let mut previous = seed.stable_commit; + for commit in lineage[..at].iter().rev() { + let parents = git.parents(commit)?; + ensure!( + parents.len() == 2 && parents[0] == previous, + "history requires two-parent promotions: {commit}" + ); + let new = git.selection(commit)?; + let migrations = added(&old, &new, rule, true)?; + let before = version.to_string(); + version = version.bump(!migrations.is_empty())?; + let prs: BTreeSet<_> = git + .run(&["log", "--format=%s", &format!("{previous}..{}", parents[1])])? + .lines() + .filter_map(pr_number) + .collect(); + promotions.push(Promotion { + version: version.to_string(), + previous_version: Some(before), + date: git.run(&["show", "-s", "--format=%cI", commit])?, + stable_commit: commit.clone(), + source_commit: parents[1].clone(), + bump: if migrations.is_empty() { + "patch" + } else { + "minor" + } + .into(), + migrations_shipped: added(&old, &new, Rule::Effective, true)?, + bump_lines: migrations, + migrations_removed: old + .files + .keys() + .filter(|n| !new.files.contains_key(*n)) + .cloned() + .collect(), + selection_evidence: new.evidence.clone(), + manifest_blob: new.manifest.clone(), + promotion_pr: pr_number(&git.run(&["show", "-s", "--format=%s", commit])?), + pr_count: prs.len(), + prs: prs.into_iter().collect(), + }); + old = new; + previous = commit.clone(); + } + Ok(History { + schema: "polis.release-history/1", + rule: rule.name(), + seed_sha256: format!("{:x}", Sha256::digest(input)), + promotions, + }) +} + +fn validate_tags( + tags: &[(Version, String)], + lineage: &[String], + stable: &str, +) -> Result> { + let mut previous_index = usize::MAX; + let mut commits = BTreeSet::new(); + for (version, commit) in tags { + let index = lineage + .iter() + .position(|s| s == commit) + .with_context(|| format!("tag v{version} is outside stable first-parent lineage"))?; + ensure!( + index < previous_index && commits.insert(commit), + "conflicting or non-increasing release tags" + ); + previous_index = index; + } + if let Some((version, commit)) = tags.last() { + ensure!( + commit == stable, + "stable head is not tagged; complete the pending release first" + ); + Ok(Some(*version)) + } else { + Ok(None) + } +} + +#[derive(Debug, Serialize)] +struct Plan { + schema: &'static str, + rule: &'static str, + kind: String, + version: String, + previous_version: String, + bump: String, + reason: String, + release_lines: Vec, + previous_stable_commit: String, + candidate_commit: String, + previous_tree: String, + candidate_tree: String, + previous_manifest_blob: Option, + candidate_manifest_blob: Option, + previous_tag: Option, + new_number: bool, +} +fn plan( + git: &Git, + stable: &str, + candidate: &str, + kind: &str, + seed: &str, + rule: Rule, +) -> Result { + let lineage = git.lineage(stable)?; + let tags = git.tags()?; + let tagged = validate_tags(&tags, &lineage, stable)?; + let tail = + if tagged.is_none() || (kind == "redeploy" && !tags.iter().any(|(_, c)| c == candidate)) { + Some(history(git, stable, seed, rule)?) + } else { + None + }; + let previous = match tagged { + Some(v) => v, + None => Version::parse( + &tail + .as_ref() + .and_then(|h| h.promotions.last()) + .context("missing history")? + .version, + )?, + }; + let old = git.selection(stable)?; + let new = git.selection(candidate)?; + let (version, bump, lines, reason, new_number) = if kind == "redeploy" { + ensure!( + lineage.contains(&candidate.to_owned()), + "redeploy target is not a stable first-parent release" + ); + let version = if let Some((v, _)) = tags.iter().find(|(_, c)| c == candidate) { + v.to_string() + } else { + tail.as_ref() + .and_then(|h| h.promotions.iter().find(|p| p.stable_commit == candidate)) + .context("redeploy target has no known number")? + .version + .clone() + }; + ( + version, + "none", + vec![], + "redeploy retains the original stable release number", + false, + ) + } else { + if kind == "hotfix" { + ensure!( + git.ancestor(stable, candidate)?, + "hotfix must incorporate current stable" + ); + } else { + let parents = git.parents(stable)?; + ensure!(parents.len() == 2, "stable must be a two-parent promotion"); + ensure!( + git.tree(&parents[1])? == git.tree(stable)?, + "stable-only changes must be reconciled before promotion" + ); + ensure!( + git.ancestor(&parents[1], candidate)?, + "candidate must retain previous promoted source ancestry" + ); + } + preparation::require_change(git, stable, candidate)?; + let lines = added(&old, &new, rule, false)?; + let minor = !lines.is_empty(); + ( + previous.bump(minor)?.to_string(), + if minor { "minor" } else { "patch" }, + lines, + if minor { + "new selected migrations" + } else { + "no new selected migrations" + }, + true, + ) + }; + Ok(Plan { + schema: "polis.release-plan/1", + rule: rule.name(), + kind: kind.into(), + version, + previous_version: previous.to_string(), + bump: bump.into(), + reason: reason.into(), + release_lines: lines, + previous_stable_commit: stable.into(), + candidate_commit: candidate.into(), + previous_tree: git.tree(stable)?, + candidate_tree: git.tree(candidate)?, + previous_manifest_blob: old.manifest, + candidate_manifest_blob: new.manifest, + previous_tag: tagged.map(|v| format!("v{v}")), + new_number, + }) +} + +struct Args { + mode: String, + repo: PathBuf, + stable: String, + candidate: Option, + kind: String, + rule: Rule, + seed: Option, + json: bool, + write: bool, +} +fn args(values: impl IntoIterator) -> Result { + let mut it = values.into_iter(); + let mode = it.next().context("expected history or plan (see --help)")?; + ensure!( + mode == "history" || mode == "plan", + "expected history or plan" + ); + let mut a = Args { + mode, + repo: PathBuf::from("."), + stable: "origin/stable".into(), + candidate: None, + kind: "promotion".into(), + rule: Rule::parse(DEFAULT_RULE)?, + seed: None, + json: false, + write: false, + }; + let mut seen = BTreeSet::new(); + while let Some(k) = it.next() { + ensure!(seen.insert(k.clone()), "duplicate option: {k}"); + if k == "--json" { + a.json = true; + continue; + } + if k == "--write" { + a.write = true; + continue; + } + let v = it + .next() + .with_context(|| format!("missing value for {k}"))?; + match k.as_str() { + "--repo" => a.repo = v.into(), + "--stable" => a.stable = v, + "--candidate" => a.candidate = Some(v), + "--kind" => a.kind = v, + "--rule" => a.rule = Rule::parse(&v)?, + "--history" => a.seed = Some(v.into()), + _ => bail!("unknown option: {k}"), + } + } + ensure!( + ["promotion", "hotfix", "redeploy"].contains(&a.kind.as_str()), + "unknown plan kind" + ); + ensure!( + a.mode == "plan" || (!a.write && a.candidate.is_none() && !seen.contains("--kind")), + "history does not accept plan options" + ); + ensure!( + a.mode != "plan" || a.candidate.is_some(), + "plan requires --candidate" + ); + ensure!( + !(a.write && a.kind == "redeploy"), + "redeploy cannot write VERSION" + ); + Ok(a) +} +fn write_version(git: &Git, candidate: &str, version: &str) -> Result<()> { + ensure!( + git.resolve("HEAD")? == candidate, + "--write requires HEAD at candidate" + ); + let root = PathBuf::from(git.run(&["rev-parse", "--show-toplevel"])?); + ensure!( + git.run(&["status", "--porcelain", "--untracked-files=normal"])? + .lines() + .all(|l| l.get(3..) == Some("VERSION")), + "--write requires a clean candidate except VERSION" + ); + save_version(&root, version) +} +fn save_version(root: &std::path::Path, version: &str) -> Result<()> { + use std::io::Write; + Version::parse(version)?; + let target = root.join("VERSION"); + ensure!( + fs::symlink_metadata(&target)?.file_type().is_file(), + "VERSION must be a regular file" + ); + // One writable output. No ref, index, tag, Cargo mirror or release side effect. + let temporary = root.join(format!(".VERSION.polis-version-{}.tmp", std::process::id())); + let mut file = fs::OpenOptions::new() + .write(true) + .create_new(true) + .open(&temporary)?; + let result = (|| -> Result<()> { + file.set_permissions(fs::metadata(&target)?.permissions())?; + writeln!(file, "{version}")?; + file.sync_all()?; + fs::rename(&temporary, &target)?; + Ok(()) + })(); + if result.is_err() { + let _ = fs::remove_file(&temporary); + } + result +} +fn run() -> Result<()> { + let values: Vec<_> = std::env::args().skip(1).collect(); + if values == ["--help"] { + println!( + "polis-version history|plan [--repo PATH] [--stable REF] [--history SEED.json]\n [--rule effective-selection|literal-manifest-lines] [--json]\nplan requires --candidate REF; optional --kind promotion|hotfix|redeploy, --write\nRead-only by default. --write updates root VERSION only. Complete local Git history/tags required.\nDefault rule: {DEFAULT_RULE}." + ); + return Ok(()); + } + let a = args(values)?; + let git = Git::new(&a.repo)?; + let seed = match a.seed { + Some(ref p) => fs::read_to_string(p)?, + None => SEED.into(), + }; + let stable = git.resolve(&a.stable)?; + if a.mode == "history" { + let h = history(&git, &stable, &seed, a.rule)?; + ensure!( + git.resolve(&a.stable)? == stable, + "stable moved during computation" + ); + if a.json { + println!("{}", serde_json::to_string_pretty(&h)?); + } else { + for p in h.promotions { + println!( + "{} previous={} {} {} {} PRs={} migrations={}", + p.version, + p.previous_version.as_deref().unwrap_or("none"), + p.bump, + p.date, + p.stable_commit, + p.pr_count, + p.migrations_shipped.join(",") + ); + } + } + } else { + let candidate_ref = a.candidate.as_deref().context("missing candidate")?; + let candidate = git.resolve(candidate_ref)?; + let tags_before = git.tags()?; + let p = plan(&git, &stable, &candidate, &a.kind, &seed, a.rule)?; + ensure!( + git.resolve(&a.stable)? == stable + && git.resolve(candidate_ref)? == candidate + && git.tags()? == tags_before, + "release inputs moved during computation" + ); + if a.write { + write_version(&git, &candidate, &p.version)?; + } + if a.json { + println!("{}", serde_json::to_string_pretty(&p)?) + } else { + println!( + "{} (previous {}; {}: {})", + p.version, p.previous_version, p.bump, p.reason + ); + for line in p.release_lines { + println!("{MIGRATIONS}/release.txt: {line}") + } + } + } + Ok(()) +} +fn main() { + if let Err(e) = run() { + eprintln!("polis-version: {e:#}"); + std::process::exit(1) + } +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod tests { + use super::*; + fn parse(s: &str) -> Result { + args(s.split_whitespace().map(str::to_owned)) + } + #[test] + fn configured_default_is_dry() { + let a = parse("plan --candidate HEAD").unwrap(); + assert!(!a.write); + assert_eq!(a.rule, Rule::parse(DEFAULT_RULE).unwrap()); + } + #[test] + fn literal_flag() { + assert_eq!( + parse("history --rule literal-manifest-lines").unwrap().rule, + Rule::Literal + ); + } + #[test] + fn effective_flag() { + assert_eq!( + parse("history --rule effective-selection").unwrap().rule, + Rule::Effective + ); + } + #[test] + fn unknown_and_duplicate_options_refused() { + for s in [ + "plan", + "history --write", + "history --candidate HEAD", + "plan --candidate HEAD --kind bad", + "plan --candidate HEAD --version 3.0.0", + "history --json --json", + "history --rule unknown", + "plan --candidate HEAD --kind redeploy --write", + ] { + assert!(parse(s).is_err(), "{s}"); + } + } + #[test] + fn tags_must_end_at_stable() { + let l = vec!["new".into(), "old".into()]; + assert!(validate_tags(&[(Version(2, 0, 0), "old".into())], &l, "new").is_err()); + } + #[test] + fn tags_off_lineage_refused() { + assert!( + validate_tags( + &[(Version(2, 0, 0), "branch".into())], + &["stable".into()], + "stable" + ) + .is_err() + ); + } + #[test] + fn tag_order_and_collision_refused() { + let l = vec!["new".into(), "old".into()]; + for t in [ + vec![ + (Version(2, 0, 0), "new".into()), + (Version(2, 1, 0), "old".into()), + ], + vec![ + (Version(2, 0, 0), "new".into()), + (Version(2, 1, 0), "new".into()), + ], + ] { + assert!(validate_tags(&t, &l, "new").is_err()); + } + } + #[test] + fn valid_tag_baseline() { + assert_eq!( + validate_tags( + &[(Version(2, 1, 0), "new".into())], + &["new".into(), "old".into()], + "new" + ) + .unwrap(), + Some(Version(2, 1, 0)) + ); + } + #[test] + fn no_tags_uses_seed() { + assert_eq!(validate_tags(&[], &["new".into()], "new").unwrap(), None); + } +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod output_tests { + use super::*; + fn directory() -> PathBuf { + static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); + let p = std::env::temp_dir().join(format!( + "polis-version-test-{}-{}", + std::process::id(), + NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + )); + fs::create_dir(&p).unwrap(); + p + } + #[test] + fn write_only_version_and_repeat() { + let p = directory(); + fs::write(p.join("VERSION"), "1.0\n").unwrap(); + fs::write(p.join("sentinel"), "keep").unwrap(); + save_version(&p, "2.42.0").unwrap(); + save_version(&p, "2.42.0").unwrap(); + assert_eq!(fs::read_to_string(p.join("VERSION")).unwrap(), "2.42.0\n"); + assert_eq!(fs::read_to_string(p.join("sentinel")).unwrap(), "keep"); + assert_eq!(fs::read_dir(&p).unwrap().count(), 2); + fs::remove_dir_all(p).unwrap(); + } + #[test] + fn invalid_write_preserves_original() { + let p = directory(); + fs::write(p.join("VERSION"), "1.0\n").unwrap(); + assert!(save_version(&p, "3").is_err()); + assert_eq!(fs::read_to_string(p.join("VERSION")).unwrap(), "1.0\n"); + fs::remove_dir_all(p).unwrap(); + } + #[test] + fn write_refuses_existing_temporary_file() { + let p = directory(); + fs::write(p.join("VERSION"), "1.0\n").unwrap(); + let temp = p.join(format!(".VERSION.polis-version-{}.tmp", std::process::id())); + fs::write(&temp, "other").unwrap(); + assert!(save_version(&p, "2.0.0").is_err()); + assert_eq!(fs::read_to_string(&temp).unwrap(), "other"); + fs::remove_dir_all(p).unwrap(); + } + #[cfg(unix)] + #[test] + fn write_refuses_symlink() { + let p = directory(); + fs::write(p.join("other"), "keep").unwrap(); + std::os::unix::fs::symlink("other", p.join("VERSION")).unwrap(); + assert!(save_version(&p, "2.0.0").is_err()); + assert_eq!(fs::read_to_string(p.join("other")).unwrap(), "keep"); + fs::remove_dir_all(p).unwrap(); + } +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod repository_tests { + use super::*; + // Explicit opt-in: ordinary CI has a shallow source checkout. This command + // fails without a supplied complete history; it never silently skips a case. + #[test] + #[ignore = "run explicitly with POLIS_VERSION_TEST_REPO pointing to complete Polis history"] + fn real_history_and_plans() { + let path = std::env::var("POLIS_VERSION_TEST_REPO").unwrap(); + let git = Git::new(std::path::Path::new(&path)).unwrap(); + let stable = git + .resolve("d2da302d0f94fb29fa0e7fde27299509c6f5f28b") + .unwrap(); + let edge = git + .resolve("4f50b6f28f30160a9d8a0ca3f3024ef3c03b6ec2") + .unwrap(); + for (rule, expected, next) in [ + (Rule::Effective, "2.41.0", "2.42.0"), + (Rule::Literal, "2.40.0", "2.41.0"), + ] { + let h = history(&git, &stable, SEED, rule).unwrap(); + assert_eq!(h.promotions.len(), 35); + assert_eq!(h.promotions.last().unwrap().version, expected); + assert_eq!( + h.promotions.iter().filter(|p| p.bump == "minor").count(), + if rule == Rule::Effective { 7 } else { 6 } + ); + let json = serde_json::to_vec(&h).unwrap(); + assert_eq!( + json, + serde_json::to_vec(&history(&git, &stable, SEED, rule).unwrap()).unwrap() + ); + for p in h.promotions.iter().skip(1) { + assert_eq!(p.pr_count, p.prs.len()); + assert_eq!(git.parents(&p.stable_commit).unwrap()[1], p.source_commit); + } + let p = plan(&git, &stable, &edge, "promotion", SEED, rule).unwrap(); + assert_eq!(p.version, next); + assert_eq!(p.previous_version, expected); + assert_eq!( + p.release_lines, + vec!["000043_add_conversation_activity_indexes.sql"] + ); + let rollback = &h.promotions[1]; + let p = plan( + &git, + &stable, + &rollback.stable_commit, + "redeploy", + SEED, + rule, + ) + .unwrap(); + assert_eq!(p.version, rollback.version); + assert!(!p.new_number); + assert_eq!(p.previous_version, expected); + let forward = plan(&git, &stable, &edge, "promotion", SEED, rule).unwrap(); + assert_eq!(forward.version, next); + assert!(plan(&git, &stable, &stable, "promotion", SEED, rule).is_err()); + assert!(plan(&git, &stable, &edge, "hotfix", SEED, rule).is_err()); + assert!(plan(&git, &stable, &edge, "redeploy", SEED, rule).is_err()); + let older = &h.promotions[10].stable_commit; + let newer = &h.promotions[11].stable_commit; + let hotfix = plan(&git, older, newer, "hotfix", SEED, rule).unwrap(); + assert_eq!(hotfix.bump, "patch"); + assert_eq!(hotfix.version, h.promotions[11].version); + assert!(plan(&git, newer, older, "hotfix", SEED, rule).is_err()); + let before = &h.promotions[9].stable_commit; + let after = &h.promotions[10].stable_commit; + assert_eq!( + plan(&git, before, after, "hotfix", SEED, rule) + .unwrap() + .bump, + "minor" + ); + assert_eq!( + h.promotions[6].bump, + if rule == Rule::Effective { + "patch" + } else { + "minor" + } + ); + assert_eq!( + h.promotions[7].bump, + if rule == Rule::Effective { + "minor" + } else { + "patch" + } + ); + } + let mut bad: serde_json::Value = serde_json::from_str(SEED).unwrap(); + bad["source_commit"] = serde_json::json!(edge); + assert!(history(&git, &stable, &bad.to_string(), Rule::Effective).is_err()); + assert!(history(&git, &edge, SEED, Rule::Effective).is_err()); + assert!(write_version(&git, &edge, "2.42.0").is_err()); + } +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod contract_tests; diff --git a/queue-rs/src/bin/polis-version/model.rs b/queue-rs/src/bin/polis-version/model.rs new file mode 100644 index 000000000..23f5a675d --- /dev/null +++ b/queue-rs/src/bin/polis-version/model.rs @@ -0,0 +1,429 @@ +use anyhow::{Result, bail, ensure}; +use serde::{Deserialize, Serialize}; +use std::collections::{BTreeMap, BTreeSet}; + +pub const MIGRATIONS: &str = "server/postgres/migrations"; +pub const DEFAULT_RULE: &str = "effective-selection"; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Rule { + Effective, + Literal, +} +impl Rule { + pub fn parse(s: &str) -> Result { + match s { + "effective-selection" => Ok(Self::Effective), + "literal-manifest-lines" => Ok(Self::Literal), + _ => bail!("unknown counting rule: {s}"), + } + } + pub fn name(self) -> &'static str { + match self { + Self::Effective => "effective-selection", + Self::Literal => "literal-manifest-lines", + } + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct Version(pub u64, pub u64, pub u64); +impl Version { + pub fn parse(s: &str) -> Result { + let p: Vec<_> = s.split('.').collect(); + ensure!( + p.len() == 3 + && p.iter().all(|v| !v.is_empty() + && v.bytes().all(|b| b.is_ascii_digit()) + && (v.len() == 1 || !v.starts_with('0'))), + "expected canonical MAJOR.MINOR.PATCH: {s}" + ); + Ok(Self(p[0].parse()?, p[1].parse()?, p[2].parse()?)) + } + pub fn bump(self, minor: bool) -> Result { + Ok(if minor { + Self( + self.0, + self.1 + .checked_add(1) + .ok_or_else(|| anyhow::anyhow!("minor overflow"))?, + 0, + ) + } else { + Self( + self.0, + self.1, + self.2 + .checked_add(1) + .ok_or_else(|| anyhow::anyhow!("patch overflow"))?, + ) + }) + } +} +impl std::fmt::Display for Version { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}.{}.{}", self.0, self.1, self.2) + } +} + +pub fn valid_name(name: &str) -> bool { + name.len() > 11 + && name.as_bytes()[..6].iter().all(u8::is_ascii_digit) + && name.as_bytes()[6] == b'_' + && name.ends_with(".sql") + && name.as_bytes()[7..name.len() - 4] + .iter() + .all(|b| b.is_ascii_alphanumeric() || *b == b'_') +} +pub fn manifest(text: &str) -> Result> { + let mut names = BTreeSet::new(); + let mut numbers = BTreeSet::new(); + for line in text + .lines() + .filter(|l| !l.is_empty() && !l.starts_with('#')) + { + ensure!(valid_name(line), "invalid migration filename: {line}"); + ensure!( + numbers.insert(line[..6].to_owned()) && names.insert(line.to_owned()), + "duplicate migration number: {line}" + ); + } + Ok(names) +} + +#[derive(Clone, Debug)] +pub struct Selection { + pub files: BTreeMap, // selected filename -> Git blob identity + pub manifest: Option, + pub evidence: String, +} +impl Selection { + pub fn counted(&self, rule: Rule) -> BTreeSet { + if rule == Rule::Literal && self.manifest.is_none() { + BTreeSet::new() + } else { + self.files.keys().cloned().collect() + } + } +} +pub fn added( + old: &Selection, + new: &Selection, + rule: Rule, + historical: bool, +) -> Result> { + if !historical { + ensure!( + new.manifest.is_some(), + "prospective release requires release.txt" + ); + for (name, blob) in &old.files { + ensure!( + new.files.get(name) == Some(blob), + "released migration removed, renamed or edited: {name}" + ); + } + } + Ok(new + .counted(rule) + .difference(&old.counted(rule)) + .cloned() + .collect()) +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Seed { + pub schema: String, + pub version: String, + pub stable_commit: String, + pub source_commit: String, + pub date: String, + pub promotion_pr: u64, +} +#[derive(Clone, Debug, Serialize)] +pub struct Promotion { + pub version: String, + pub previous_version: Option, + pub date: String, + pub stable_commit: String, + pub source_commit: String, + pub migrations_shipped: Vec, + pub bump_lines: Vec, + pub migrations_removed: Vec, + pub bump: String, + pub selection_evidence: String, + pub manifest_blob: Option, + pub promotion_pr: Option, + pub pr_count: usize, + pub prs: Vec, +} +#[derive(Debug, Serialize)] +pub struct History { + pub schema: &'static str, + pub rule: &'static str, + pub seed_sha256: String, + pub promotions: Vec, +} + +// Public PR references in merge subjects and squash subjects, not arbitrary body mentions. +pub fn pr_number(subject: &str) -> Option { + let n = if let Some(tail) = subject.strip_prefix("Merge pull request #") { + tail.split_whitespace().next()? + } else { + subject.strip_suffix(')')?.rsplit_once("(#")?.1 + }; + n.parse::().ok().filter(|n| *n > 0) +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod tests { + use super::*; + fn selection(manifest: bool, rows: &[(&str, &str)]) -> Selection { + Selection { + files: rows + .iter() + .map(|(a, b)| (a.to_string(), b.to_string())) + .collect(), + manifest: manifest.then(|| "blob".into()), + evidence: "test".into(), + } + } + const A: &str = "000001_one.sql"; + const B: &str = "000002_two.sql"; + #[test] + fn canonical_versions() { + for s in ["2.0.0", "0.1.12", "100.99.1"] { + assert_eq!(Version::parse(s).unwrap().to_string(), s); + } + } + #[test] + fn invalid_versions() { + for s in [ + "2.0", + "v2.0.0", + "02.0.0", + "2.00.0", + "2.0.0-dev", + "2.0.0+dev", + " 2.0.0", + "2.0.-1", + "2.0.0\n", + ] { + assert!(Version::parse(s).is_err(), "{s}"); + } + } + #[test] + fn patch_and_minor_never_major() { + let v = Version(2, 9, 4); + assert_eq!(v.bump(false).unwrap(), Version(2, 9, 5)); + assert_eq!(v.bump(true).unwrap(), Version(2, 10, 0)); + } + #[test] + fn overflow_refused() { + assert!(Version(2, u64::MAX, 0).bump(true).is_err()); + assert!(Version(2, 0, u64::MAX).bump(false).is_err()); + } + #[test] + fn comments_blank_reorder() { + assert_eq!( + manifest(&format!("# hi\n\n{B}\n{A}\n")).unwrap(), + manifest(&format!("{A}\n{B}\n")).unwrap() + ); + } + #[test] + fn invalid_manifest_names() { + for s in [ + "../000001_a.sql", + "00001_a.sql", + "000001_a.sql ", + " 000001_a.sql", + "000001_a-b.sql", + "000001_é.sql", + "000001_.sql", + ] { + assert!(manifest(s).is_err(), "{s}"); + } + } + #[test] + fn duplicate_names_and_numbers() { + for s in [format!("{A}\n{A}"), format!("{A}\n000001_other.sql")] { + assert!(manifest(&s).is_err()); + } + } + #[test] + fn patch_when_unchanged_or_only_held_added() { + let s = selection(true, &[(A, "a")]); + assert!(added(&s, &s, Rule::Effective, false).unwrap().is_empty()); + } + #[test] + fn selected_from_held_counts() { + let a = selection(true, &[(A, "a")]); + let b = selection(true, &[(A, "a"), (B, "b")]); + assert_eq!(added(&a, &b, Rule::Effective, false).unwrap(), vec![B]); + } + #[test] + fn many_migrations_one_minor() { + let a = selection(true, &[]); + let b = selection(true, &[(A, "a"), (B, "b")]); + assert_eq!( + Version(2, 1, 9) + .bump(!added(&a, &b, Rule::Effective, false).unwrap().is_empty()) + .unwrap(), + Version(2, 2, 0) + ); + } + #[test] + fn first_manifest_does_not_reship() { + let a = selection(false, &[(A, "a")]); + let b = selection(true, &[(A, "a")]); + assert!(added(&a, &b, Rule::Effective, true).unwrap().is_empty()); + assert_eq!(added(&a, &b, Rule::Literal, true).unwrap(), vec![A]); + } + #[test] + fn premanifest_migration_effective_only() { + let a = selection(false, &[(A, "a")]); + let b = selection(false, &[(A, "a"), (B, "b")]); + assert_eq!(added(&a, &b, Rule::Effective, true).unwrap(), vec![B]); + assert!(added(&a, &b, Rule::Literal, true).unwrap().is_empty()); + } + #[test] + fn historical_revert_then_reintroduction() { + let a = selection(true, &[(A, "a")]); + let b = selection(false, &[(A, "a"), (B, "b")]); + assert_eq!(added(&a, &b, Rule::Effective, true).unwrap(), vec![B]); + assert!(added(&a, &b, Rule::Literal, true).unwrap().is_empty()); + assert!(added(&b, &a, Rule::Effective, true).unwrap().is_empty()); + assert_eq!(added(&b, &a, Rule::Literal, true).unwrap(), vec![A]); + } + #[test] + fn prospective_removal_refused_for_both_rules() { + let a = selection(true, &[(A, "a")]); + let b = selection(true, &[]); + for r in [Rule::Effective, Rule::Literal] { + assert!(added(&a, &b, r, false).is_err()); + } + } + #[test] + fn prospective_edit_refused() { + assert!( + added( + &selection(true, &[(A, "a")]), + &selection(true, &[(A, "changed")]), + Rule::Effective, + false + ) + .is_err() + ); + } + #[test] + fn prospective_manifest_removal_refused() { + let a = selection(true, &[(A, "a")]); + assert!(added(&a, &selection(false, &[(A, "a")]), Rule::Literal, false).is_err()); + } + #[test] + fn added_then_removed_not_shipped() { + let a = selection(true, &[(A, "a")]); + assert!(added(&a, &a, Rule::Effective, false).unwrap().is_empty()); + } + #[test] + fn public_pr_subjects_only() { + assert_eq!( + pr_number("Merge pull request #123 from org/branch"), + Some(123) + ); + assert_eq!(pr_number("A change (#456)"), Some(456)); + assert_eq!(pr_number("references #456"), None); + } +} + +pub fn selected_blobs( + blobs: &BTreeMap, + names: &BTreeSet, +) -> Result> { + use anyhow::Context; + let mut numbers = BTreeSet::new(); + for name in blobs.keys().filter(|n| n.ends_with(".sql")) { + ensure!( + valid_name(name) && numbers.insert(name[..6].to_owned()), + "invalid or duplicate migration number: {name}" + ); + } + names + .iter() + .map(|name| { + ensure!(valid_name(name), "invalid selected migration: {name}"); + Ok(( + name.clone(), + blobs + .get(name) + .with_context(|| format!("selected migration missing: {name}"))? + .clone(), + )) + }) + .collect() +} + +pub fn legacy_names( + dockerfile: &str, + blobs: &BTreeMap, +) -> Result> { + let instructions: Vec<_> = dockerfile + .lines() + .map(str::trim) + .filter(|l| !l.is_empty() && !l.starts_with('#')) + .collect(); + ensure!( + instructions + == [ + "FROM postgres:17-alpine", + "COPY ./postgres/migrations/*.sql /docker-entrypoint-initdb.d/" + ], + "unrecognized or ambiguous legacy initializer; explicit selection evidence required" + ); + Ok(blobs + .keys() + .filter(|n| n.ends_with(".sql")) + .cloned() + .collect()) +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod selection_tests { + use super::*; + #[test] + fn selected_file_must_exist() { + assert!( + selected_blobs(&BTreeMap::new(), &BTreeSet::from(["000001_one.sql".into()])).is_err() + ); + } + #[test] + fn duplicate_number_in_unselected_file_refused() { + let b = BTreeMap::from([ + ("000001_one.sql".into(), "a".into()), + ("000001_two.sql".into(), "b".into()), + ]); + assert!(selected_blobs(&b, &BTreeSet::from(["000001_one.sql".into()])).is_err()); + } + #[test] + fn legacy_selection_must_be_known() { + let good = "FROM postgres:17-alpine\nCOPY ./postgres/migrations/*.sql /docker-entrypoint-initdb.d/"; + let b = BTreeMap::from([ + ("000001_one.sql".into(), "a".into()), + ("held.txt".into(), "b".into()), + ]); + assert_eq!( + legacy_names(good, &b).unwrap(), + BTreeSet::from(["000001_one.sql".into()]) + ); + for bad in [ + "FROM postgres:17-alpine".to_owned(), + format!("{good}\nRUN change-selection"), + format!("{good}\nADD extra /docker-entrypoint-initdb.d/"), + ] { + assert!(legacy_names(&bad, &b).is_err()); + } + } +} diff --git a/queue-rs/src/bin/polis-version/preparation.rs b/queue-rs/src/bin/polis-version/preparation.rs new file mode 100644 index 000000000..2846454cc --- /dev/null +++ b/queue-rs/src/bin/polis-version/preparation.rs @@ -0,0 +1,291 @@ +//! Ignore only the version fields emitted by release preparation. Unknown layouts +//! remain substantive changes; this is deliberately not a general TOML rewriter. +use crate::{git::Git, model::Version}; +use anyhow::{Context, Result, ensure}; + +pub fn require_change(git: &Git, stable: &str, candidate: &str) -> Result<()> { + // No rename detection or pathname quoting: every added/deleted file and mode + // change is substantive, even if its path is a supported mirror. + let raw = git.bytes(&[ + "diff", + "--raw", + "--no-abbrev", + "--no-renames", + "-z", + stable, + candidate, + "--", + ])?; + require_product_change(&raw, |id| git.bytes(&["cat-file", "blob", id])) +} + +fn require_product_change(raw: &[u8], mut blob: impl FnMut(&str) -> Result>) -> Result<()> { + let raw = std::str::from_utf8(raw)?; + let mut entries = raw.split_terminator('\0'); + let mut substantive = false; + while let Some(header) = entries.next() { + let path = entries.next().context("missing changed path")?; + let fields: Vec<_> = header.trim_start_matches(':').split_whitespace().collect(); + ensure!(fields.len() == 5, "invalid raw change record"); + if fields[0] != "100644" || fields[1] != "100644" || fields[4] != "M" { + substantive = true; + } else if path != "VERSION" { + if matches!(path, "polis-cli/Cargo.toml" | "polis-cli/Cargo.lock") { + let old = blob(fields[2])?; + let new = blob(fields[3])?; + substantive |= !mirror_only(path, &old, &new); + } else { + substantive = true; + } + } + } + ensure!( + substantive, + "empty promotion or version-only preparation does not allocate a release" + ); + Ok(()) +} + +fn mirror_only(path: &str, old: &[u8], new: &[u8]) -> bool { + match (normalized(path, old), normalized(path, new)) { + (Some(a), Some(b)) => a == b, + _ => false, + } +} + +fn normalized(path: &str, bytes: &[u8]) -> Option { + let text = std::str::from_utf8(bytes).ok()?; + // A section-looking line inside a multiline TOML string is not a section. + // Generated mirrors use no such strings; refuse to normalize unfamiliar input. + if text.contains("\"\"\"") || text.contains("'''") { + return None; + } + match path { + "polis-cli/Cargo.toml" => { + let mut workspace = false; + let mut count = 0; + let mut out = String::new(); + for line in text.split_inclusive('\n') { + if line.trim_start().starts_with('[') { + workspace = line.trim() == "[workspace.package]"; + } + if workspace && version_line(line) { + count += 1; + out.push_str("version = \"\""); + if line.ends_with('\n') { + out.push('\n'); + } + } else { + out.push_str(line); + } + } + (count == 1).then_some(out) + } + "polis-cli/Cargo.lock" => { + let mut out = String::new(); + let mut seen = std::collections::BTreeSet::new(); + let mut blocks = text.split("[[package]]\n"); + out.push_str(blocks.next()?); + for block in blocks { + out.push_str("[[package]]\n"); + // These two crates inherit the CLI workspace version. The shared + // contracts crate and registry/git packages have independent versions. + let name = block.lines().next()?; + let local = matches!(name, "name = \"polis\"" | "name = \"polis-client\"") + && !block.lines().any(|l| { + l.trim_start().starts_with("source") + || l.trim_start().starts_with("checksum") + }); + let mut count = 0; + for line in block.split_inclusive('\n') { + if local && version_line(line) { + count += 1; + out.push_str("version = \"\""); + if line.ends_with('\n') { + out.push('\n'); + } + } else { + out.push_str(line); + } + } + if local && (count != 1 || !seen.insert(name)) { + return None; + } + } + (!seen.is_empty()).then_some(out) + } + _ => None, + } +} + +fn version_line(line: &str) -> bool { + line.strip_suffix('\n') + .unwrap_or(line) + .strip_prefix("version = \"") + .and_then(|s| s.strip_suffix('"')) + .is_some_and(|s| Version::parse(s).is_ok()) +} + +#[cfg(test)] +mod tests { + use super::*; + const MANIFEST: &str = "[workspace]\nmembers = [\"crates/polis\"]\n[workspace.package]\nversion = \"0.1.0\"\nedition = \"2021\"\n[workspace.dependencies]\nserde = { version = \"1\" }\n[profile.release]\nlto = \"thin\"\n"; + const LOCK: &str = "version = 4\n\n[[package]]\nname = \"polis\"\nversion = \"0.1.0\"\ndependencies = [\"polis-client\"]\n\n[[package]]\nname = \"polis-client\"\nversion = \"0.1.0\"\n\n[[package]]\nname = \"polis-contracts\"\nversion = \"0.1.0\"\n\n[[package]]\nname = \"serde\"\nversion = \"1.0.0\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\n"; + fn record(path: &str, old: &str, new: &str) -> String { + format!(":100644 100644 {old} {new} M\0{path}\0") + } + fn check(records: &str, extra_code: bool) -> Result<()> { + let mut records = records.to_owned(); + if extra_code { + records.push_str(&record("README.md", "old", "new")); + } + require_product_change(records.as_bytes(), |id| { + Ok(match id { + "manifest-old" => MANIFEST.to_owned(), + "manifest-new" => MANIFEST.replace("0.1.0", "2.42.0"), + "lock-old" => LOCK.to_owned(), + "lock-new" => LOCK.replacen("0.1.0", "2.42.0", 2), + "dependency-new" => MANIFEST.replace("version = \"1\"", "version = \"2\""), + _ => anyhow::bail!("unexpected blob {id}"), + } + .into_bytes()) + }) + } + #[test] + fn new_release_guard_rejects_empty_and_combined_preparation() { + // Ordinary and hotfix plans call this same guard after ancestry checks. + let version = record("VERSION", "old", "new"); + let manifest = record("polis-cli/Cargo.toml", "manifest-old", "manifest-new"); + let lock = record("polis-cli/Cargo.lock", "lock-old", "lock-new"); + for changes in [ + String::new(), + version.clone(), + manifest.clone(), + lock.clone(), + format!("{version}{manifest}{lock}"), + ] { + assert!(check(&changes, false).is_err()); + assert!(check(&changes, true).is_ok()); + } + assert!( + check( + &record("polis-cli/Cargo.toml", "manifest-old", "dependency-new"), + false + ) + .is_ok() + ); + } + #[test] + fn mode_changes_additions_deletions_and_unusual_paths_count() { + for header in [ + ":100644 100755 old new M", + ":000000 100644 zero new A", + ":100644 000000 old zero D", + ":100644 120000 old new T", + ] { + for path in ["VERSION", "polis-cli/Cargo.toml", "polis-cli/Cargo.lock"] { + assert!(check(&format!("{header}\0{path}\0"), false).is_ok()); + } + } + assert!(check(&record("VERSION\nREADME.md", "old", "new"), false).is_ok()); + } + #[test] + fn preparation_workspace_version_is_ignored() { + assert!(mirror_only( + "polis-cli/Cargo.toml", + MANIFEST.as_bytes(), + MANIFEST.replace("0.1.0", "2.42.0").as_bytes() + )); + } + #[test] + fn preparation_local_package_versions_are_ignored() { + let next = LOCK.replacen("0.1.0", "2.42.0", 2); + assert!(mirror_only( + "polis-cli/Cargo.lock", + LOCK.as_bytes(), + next.as_bytes() + )); + } + #[test] + fn dependency_and_build_changes_remain_substantive() { + for (a, b) in [ + ("version = \"1\"", "version = \"2\""), + ("thin", "fat"), + ("2021", "2024"), + ("crates/polis", "crates/other"), + ] { + let next = MANIFEST.replace("0.1.0", "2.42.0").replace(a, b); + assert!( + !mirror_only("polis-cli/Cargo.toml", MANIFEST.as_bytes(), next.as_bytes()), + "{a}" + ); + } + } + #[test] + fn dependency_contract_and_lock_format_versions_remain_substantive() { + for next in [ + LOCK.replace("1.0.0", "1.1.0"), + LOCK.replace( + "name = \"polis-contracts\"\nversion = \"0.1.0\"", + "name = \"polis-contracts\"\nversion = \"0.2.0\"", + ), + LOCK.replace("version = 4", "version = 3"), + LOCK.replace("[\"polis-client\"]", "[\"serde\"]"), + ] { + assert!(!mirror_only( + "polis-cli/Cargo.lock", + LOCK.as_bytes(), + next.as_bytes() + )); + } + } + #[test] + fn registry_package_with_local_name_is_not_a_mirror() { + let old = LOCK.replace( + "name = \"polis\"\n", + "name = \"polis\"\nsource = \"registry+example\"\n", + ); + assert!(!mirror_only( + "polis-cli/Cargo.lock", + old.as_bytes(), + old.replacen("0.1.0", "2.42.0", 1).as_bytes() + )); + } + #[test] + fn unfamiliar_layouts_and_unrelated_files_are_not_ignored() { + for path in [ + "polis-cli/Cargo.toml", + "polis-cli/Cargo.lock", + "queue-rs/Cargo.toml", + ] { + for old in [ + "", + "version = \"0.1.0\"", + "x = '''\n[workspace.package]\nversion = \"0.1.0\"\n'''\n", + "x = \"\"\"\n[workspace.package]\nversion = \"0.1.0\"\n\"\"\"\n", + ] { + assert!(!mirror_only( + path, + old.as_bytes(), + old.replace("0.1.0", "2.42.0").as_bytes() + )); + } + } + } + #[test] + fn other_bytes_in_supported_mirrors_are_preserved() { + for (path, old) in [ + ("polis-cli/Cargo.toml", MANIFEST), + ("polis-cli/Cargo.lock", LOCK), + ] { + for next in [ + format!("{old}\n"), + format!("{old}# comment\n"), + old.trim_end().to_owned(), + old.replace("0.1.0", "invalid"), + ] { + assert!(!mirror_only(path, old.as_bytes(), next.as_bytes())); + } + } + } +} diff --git a/queue-rs/src/bin/polis-version/seed.json b/queue-rs/src/bin/polis-version/seed.json new file mode 100644 index 000000000..59f17c978 --- /dev/null +++ b/queue-rs/src/bin/polis-version/seed.json @@ -0,0 +1,8 @@ +{ + "schema": "polis.release-seed/1", + "version": "2.34.0", + "stable_commit": "fd16f790a01d433aa338c06aea77499cf39b9944", + "source_commit": "32a6b388a1cf8dee296ece42c1a0e2dafeef81ed", + "date": "2026-10-04T16:27:11-07:00", + "promotion_pr": 2957 +} From c476b36104f85e5e6d0c8dec056c47e2bdc61c53 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Wed, 21 Oct 2026 11:39:38 -0700 Subject: [PATCH 22/30] cli: polis update follows the Polis release tag (#3249) The updater resolves the newest release tagged vMAJOR.MINOR.PATCH, the Polis release on the stable merge commit, and takes the CLI's eight assets from it; asset names, checksum verification, atomic replacement and every failure case are unchanged. A cli-v tag is ignored with a clear message, and a development build never replaces itself unasked. Co-authored-by: Claude Fable 5.1 --- polis-cli/crates/polis/src/update.rs | 37 ++++++-- polis-cli/crates/polis/tests/update.rs | 125 ++++++++++++++++++++++--- polis-cli/docs/releases.md | 106 ++++++++++++++------- 3 files changed, 213 insertions(+), 55 deletions(-) diff --git a/polis-cli/crates/polis/src/update.rs b/polis-cli/crates/polis/src/update.rs index 4d0bdb892..71b637f25 100644 --- a/polis-cli/crates/polis/src/update.rs +++ b/polis-cli/crates/polis/src/update.rs @@ -98,7 +98,7 @@ fn latest(client: &Client, base: Url) -> Result<(Version, Release)> { } let Some(version) = release .tag_name - .strip_prefix("cli-v") + .strip_prefix("v") .and_then(|s| Version::parse(s).ok()) else { continue; @@ -111,11 +111,11 @@ fn latest(client: &Client, base: Url) -> Result<(Version, Release)> { } } if last { - return chosen.ok_or_else(|| fail("No published stable CLI release was found.")); + return chosen.ok_or_else(|| fail("No published stable Polis release was found (expected vMAJOR.MINOR.PATCH; legacy cli-v tags are ignored).")); } } Err(fail( - "Release list exceeds ten pages; cannot determine the latest CLI release.", + "Release list exceeds ten pages; cannot determine the latest Polis release.", )) } fn digest(bytes: &[u8]) -> String { @@ -299,6 +299,13 @@ fn install(_: &Path, _: &[u8], _: &str) -> Result<()> { Err(fail("This platform does not support CLI updates.")) } +// The shared build identity supplies the Polis base. Older build scripts only +// supply the Cargo version; keep that fallback until all builds use the identity. +fn installed_base(raw: &str) -> Result { + let version = Version::parse(raw).map_err(|_| fail("Invalid installed version."))?; + Ok(Version::new(version.major, version.minor, version.patch)) +} + pub fn execute(base: Option<&str>, timeout: u64) -> Result { let platform = target()?; let configured = base @@ -332,11 +339,11 @@ pub fn execute(base: Option<&str>, timeout: u64) -> Result { let installed_digest = digest(&fs::read(&executable).map_err(|_| fail("Cannot read installed executable."))?); let (version, release) = latest(&client, base)?; - let current = Version::parse(env!("CARGO_PKG_VERSION")) - .map_err(|_| fail("Invalid installed version."))?; + let current = + installed_base(option_env!("POLIS_VERSION_BASE").unwrap_or(env!("CARGO_PKG_VERSION")))?; if version <= current { return Ok( - json!({"state":"up_to_date", "version":current.to_string(), "commit":env!("POLIS_BUILD_COMMIT"), "latest":version.to_string(), "message":"No newer stable CLI release is available."}), + json!({"state":"up_to_date", "version":current.to_string(), "commit":env!("POLIS_BUILD_COMMIT"), "latest":version.to_string(), "message":"No newer stable Polis release is available; equal-base development builds require an explicitly selected artifact."}), ); } let suffix = format!("-{platform}.tar.gz"); @@ -347,7 +354,7 @@ pub fn execute(base: Option<&str>, timeout: u64) -> Result { .collect(); if candidates.len() != 1 { return Err(fail( - "The latest CLI release does not contain exactly one archive for this platform.", + "The latest Polis release does not contain exactly one archive for this platform.", )); } let asset = candidates[0]; @@ -394,6 +401,22 @@ mod tests { use super::*; use std::os::fd::AsRawFd; + #[test] + fn development_metadata_does_not_make_an_equal_base_release_newer() { + for installed in [ + "2.41.0", + "2.41.0+dev.7.abcdef123456", + "2.41.0+dev.0.abcdef123456", + ] { + let current = installed_base(installed).unwrap(); + assert_eq!(current, Version::new(2, 41, 0)); + assert!(Version::new(2, 41, 0) <= current); + assert!(Version::new(2, 40, 9) <= current); + assert!(Version::new(2, 41, 1) > current); + } + assert!(installed_base("invalid").is_err()); + } + #[test] fn directory_sync_failure_after_replacement_reports_unknown() { let directory = tempfile::tempdir().unwrap(); diff --git a/polis-cli/crates/polis/tests/update.rs b/polis-cli/crates/polis/tests/update.rs index 35fa74c8b..4e259b6bf 100644 --- a/polis-cli/crates/polis/tests/update.rs +++ b/polis-cli/crates/polis/tests/update.rs @@ -39,14 +39,26 @@ impl Drop for Server { self.handle.take().unwrap().join().unwrap(); } } +fn current_version() -> semver::Version { + let version = semver::Version::parse( + option_env!("POLIS_VERSION_BASE").unwrap_or(env!("CARGO_PKG_VERSION")), + ) + .unwrap(); + semver::Version::new(version.major, version.minor, version.patch) +} +fn next_version() -> String { + format!("{}.10.0", current_version().major + 1) +} fn server(mode: &str) -> (Server, Vec) { let listener = TcpListener::bind("127.0.0.1:0").unwrap(); let origin = format!("http://{}", listener.local_addr().unwrap()); listener.set_nonblocking(true).unwrap(); let version = if mode == "old" { - env!("CARGO_PKG_VERSION") + current_version().to_string() + } else if mode == "lower" { + "0.0.0".to_owned() } else { - "999.0.0" + next_version() }; let commit = "a".repeat(40); let root = format!("polis-{version}-{}-{}", &commit[..12], target()); @@ -104,17 +116,62 @@ fn server(mode: &str) -> (Server, Vec) { {"name":format!("{name}.sha256"),"browser_download_url":format!("{origin}/checksum")} ]) }; - let releases = json!([ + let mut releases = json!([ {"tag_name":"server-v9999.0.0","draft":false,"prerelease":false,"assets":[]}, - {"tag_name":"cli-v9999.0.0","draft":true,"prerelease":false,"assets":[]}, - {"tag_name":"cli-v9998.0.0","draft":false,"prerelease":true,"assets":[]}, - {"tag_name":format!("cli-v{version}"),"draft":false,"prerelease":false,"body":"New commands.\u{1b}[31m","assets":assets} + {"tag_name":"v9999.0.0","draft":true,"prerelease":false,"assets":[]}, + {"tag_name":"v9998.0.0","draft":false,"prerelease":true,"assets":[]}, + {"tag_name":format!("v{version}"),"draft":false,"prerelease":false,"body":"New commands.\u{1b}[31m","assets":assets} ]); - let releases = if mode == "empty" { json!([]) } else { releases }; + // These malformed or legacy tags must never outrank the canonical release. + for tag in [ + "cli-v9999.0.0", + "v9999.0.0-rc.1", + "v9999.0.0+build", + "v09999.0.0", + "9999.0.0", + "v9999.0", + ] { + releases + .as_array_mut() + .unwrap() + .push(json!({"tag_name":tag,"draft":false,"prerelease":false,"assets":[]})); + } + // Numeric ordering must win over listing order and lexicographic ordering. + if matches!(mode, "match" | "paged") { + releases.as_array_mut().unwrap().push(json!({"tag_name":format!("v{}.9.0", current_version().major + 1),"draft":false,"prerelease":false,"assets":[]})); + } + if mode == "missing" { + releases.as_array_mut().unwrap().push(json!({"tag_name":format!("v{}", current_version()),"draft":false,"prerelease":false,"assets":assets})); + } + if mode == "legacy" { + releases = + json!([{"tag_name":"cli-v9999.0.0","draft":false,"prerelease":false,"assets":[]}]); + } + if mode == "empty" { + releases = json!([]); + } + let page_one = if matches!(mode, "paged" | "bounded") { + // A higher valid release on the first page must survive a later page. + let mut page = vec![ + json!({"tag_name":"cli-v9999.0.0","draft":false,"prerelease":false,"assets":[]}); + 99 + ]; + page.push(json!({"tag_name":format!("v{version}"),"draft":false,"prerelease":false,"body":"New commands.\u{1b}[31m","assets":assets})); + serde_json::to_vec(&page).unwrap() + } else { + serde_json::to_vec(&releases).unwrap() + }; + let page_two = if mode == "paged" { + serde_json::to_vec(&json!([{"tag_name":format!("v{}.9.0", current_version().major + 1),"draft":false,"prerelease":false,"assets":[]}])).unwrap() + } else { + serde_json::to_vec(&releases).unwrap() + }; + let bounded = mode == "bounded"; let not_found = mode == "not_found"; let offline = mode == "offline"; let routes = HashMap::from([ - ("/releases", serde_json::to_vec(&releases).unwrap()), + ("/releases", page_one), + ("/releases-next", page_two), ("/archive", archive), ("/checksum", checksum.into_bytes()), ]); @@ -156,6 +213,11 @@ fn server(mode: &str) -> (Server, Vec) { .split('?') .next() .unwrap(); + let path = if path == "/releases" && !bounded && !request.contains("page=1 ") { + "/releases-next" + } else { + path + }; let body = routes .get(path) .unwrap_or_else(|| panic!("unexpected path {path}")); @@ -236,7 +298,8 @@ fn run(mode: &str, json_mode: bool, env_source: bool) { let out = output.unwrap(); let stdout = String::from_utf8(out.stdout).unwrap(); let stderr = String::from_utf8(out.stderr).unwrap(); - let success = matches!(mode, "match" | "old"); + let updated = matches!(mode, "match" | "paged"); + let success = updated || matches!(mode, "old" | "lower"); assert_eq!(out.status.success(), success, "{stdout}\n{stderr}"); assert!(!stdout.contains('\u{1b}')); assert!(!stdout.contains("unused-fixture-token")); @@ -246,7 +309,10 @@ fn run(mode: &str, json_mode: bool, env_source: bool) { let expected_message = match mode { "offline" => Some("Cannot download release data."), "not_found" => Some("Release server returned an unsuccessful status."), - "empty" => Some("No published stable CLI release was found."), + "empty" | "legacy" => Some("No published stable Polis release was found (expected vMAJOR.MINOR.PATCH; legacy cli-v tags are ignored)."), + "missing" => Some("The latest Polis release does not contain exactly one archive for this platform."), + "mismatch" => Some("Release archive checksum mismatch."), + "bounded" => Some("Release list exceeds ten pages; cannot determine the latest Polis release."), "denied_lock" => Some("Cannot open the update lock in the installation directory."), "denied_staging" => Some("Installation directory is not writable."), _ => None, @@ -258,16 +324,22 @@ fn run(mode: &str, json_mode: bool, env_source: bool) { assert_eq!(data["error"]["outcome"], "not_sent"); assert!(stderr.is_empty()); } - if mode == "match" { - assert_eq!(data["data"]["to"]["version"], "999.0.0"); + if updated { + assert_eq!(data["data"]["to"]["version"], next_version()); + assert_eq!( + data["data"]["from"]["version"], + current_version().to_string() + ); assert_eq!(data["data"]["to"]["commit"], "a".repeat(40)); assert_eq!(data["data"]["changes"], "New commands.\u{1b}[31m"); } - if mode == "old" { + if matches!(mode, "old" | "lower") { assert_eq!(data["data"]["state"], "up_to_date"); + assert_eq!(data["data"]["version"], current_version().to_string()); + assert_eq!(data["data"]["message"], "No newer stable Polis release is available; equal-base development builds require an explicitly selected artifact."); } } - if mode == "match" { + if updated { assert_eq!(fs::read(&exe).unwrap(), binary); assert_eq!(fs::read(dir.path().join("polis.prev")).unwrap(), original); #[cfg(unix)] @@ -285,6 +357,15 @@ fn run(mode: &str, json_mode: bool, env_source: bool) { b"older backup" ); } + let expected_requests = match mode { + "paged" => Some(4), + "bounded" => Some(10), + "old" | "lower" | "empty" | "legacy" | "missing" | "not_found" => Some(1), + _ => None, + }; + if let Some(expected) = expected_requests { + assert_eq!(server.requests.load(Ordering::SeqCst), expected); + } assert_eq!( fs::read(config.join("profiles.json")).unwrap(), b"invalid config; must not be read" @@ -303,6 +384,22 @@ fn no_newer_version_does_not_replace() { run("old", true, false); } #[test] +fn lower_version_does_not_replace() { + run("lower", true, false); +} +#[test] +fn legacy_only_releases_explain_the_required_tag() { + run("legacy", true, false); +} +#[test] +fn numeric_order_and_later_pages_preserve_highest_release() { + run("paged", true, false); +} +#[test] +fn ten_full_pages_refuse_to_guess() { + run("bounded", true, false); +} +#[test] fn platform_missing_does_not_replace() { run("missing", true, false); } diff --git a/polis-cli/docs/releases.md b/polis-cli/docs/releases.md index 798f9f5e3..1c07fb129 100644 --- a/polis-cli/docs/releases.md +++ b/polis-cli/docs/releases.md @@ -1,7 +1,11 @@ # Building, installing and updating the CLI -`polis --version` prints the semantic CLI version, full source commit and source -status. An ordinary Cargo build without metadata says `commit unknown; +`polis --version` prints the installed build version, full source commit and +source status. The CLI is a client of Polis and follows the Polis release version. +The shared build identity supplies root `VERSION` as `POLIS_VERSION_BASE`, plus +commit and distance for development display. Until that identity is available, +the updater compares the version embedded from `polis-cli/Cargo.toml`. It never +reads a version from the configured site or a runtime environment variable. An ordinary Cargo build without metadata says `commit unknown; development`. A native artifact built by the release script says `clean-checkout`; an explicitly declared archive rehearsal says `unverified-archive`. These are build descriptions, not signatures or proof of @@ -25,15 +29,15 @@ toolchain, `cargo build --locked --release`, and the actual Cargo target directo It builds the production binary without fixture features, checks version/help, and refuses modified or untracked build inputs. It never publishes or installs. -The **polis-cli release** workflow uses these same commands on native macOS -and Linux runners. Manual dispatch builds review artifacts only. A pushed -`cli-vMAJOR.MINOR.PATCH` tag builds and publishes after all four jobs pass. Its artifacts expire after 14 days; -they are review inputs, not permanent release URLs. All target jobs must pass -before a distributor claims that version supports all four targets. A passing -ARM64 Mac build alone does not qualify Intel or Linux. GNU/Linux binaries use -the runner's glibc and are not promised to work on older distributions. A source -build remains available there. Mac archives are unsigned unless a distributor -separately signs and notarizes them; no signing identity is supplied here. +The existing native build entry points can prepare review artifacts. Publication +must follow the shared Polis release checklist below; this updater change does +not change the build or publication workflow. Legacy `cli-v` publication tooling +must be migrated before publishing the first shared release. All target jobs +must pass before publication. A passing ARM64 Mac build alone does not qualify +Intel or Linux. GNU/Linux binaries use the runner's glibc and are not promised +to work on older distributions. A source build remains available there. Mac +archives are unsigned unless a distributor separately signs and notarizes them; +no signing identity is supplied here. Archive names contain version, abbreviated commit and target. Each archive has one named directory containing `polis`, `manifest.json`, `LICENSE`, and @@ -58,10 +62,10 @@ the distributor on its own. In the download directory: ```sh # Use the exact downloaded checksum filename; substitute your chosen artifact. -shasum -a 256 -c polis-VERSION-COMMIT-TARGET.tar.gz.sha256 +shasum -a 256 -c polis-VERSION-COMMIT12-TARGET.tar.gz.sha256 mkdir unpacked # Substitute the same exact filename; unpack into the new directory. -tar -xzf polis-VERSION-COMMIT-TARGET.tar.gz -C unpacked +tar -xzf polis-VERSION-COMMIT12-TARGET.tar.gz -C unpacked ``` Inspect the manifest and run the unpacked `polis --version` before installation. @@ -109,9 +113,25 @@ release-list compatible endpoint: an array of objects with `tag_name`, `draft`, `browser_download_url`. It receives `per_page=100&page=N`; a page shorter than 100 ends the list. More than ten full pages fails instead of guessing. -The updater chooses the highest stable semantic version with a `cli-v` tag; -it ignores draft, prerelease, and non-CLI releases. Equal or older versions do -nothing, even if their commit differs. A version bump is required for an update. +The updater chooses the highest numeric stable Polis version tagged exactly +`vMAJOR.MINOR.PATCH`, across every returned page. It ignores drafts, prereleases, +tags with prerelease or build suffixes, malformed versions, and other namespaces, +including the old `cli-v` tags. If only legacy tags exist, the error states the +required tag format and that legacy tags are ignored. Equal or older versions do +nothing, even if their commit differs. Comparison uses only major, minor and patch +from the compiled `POLIS_VERSION_BASE` (or the embedded Cargo version before the +shared identity is available), never commit ordering or development distance. + +A development build such as `2.41.0+dev.7.abcdef123456` is never updated in the +background. Explicit `polis update` can install a strictly higher base version; +it leaves an equal-base stable release alone. To replace a development build +with an equal-base stable build, explicitly select and verify an artifact using +the installation procedure above. There is no implicit downgrade or force flag. + +An installed older updater that only recognizes `cli-v` cannot discover these +Polis releases. Replace it once using an explicitly selected verified artifact +containing the new updater; subsequent `polis update` calls follow `v` releases. +Do not publish compatibility `cli-v` tags or a separate CLI version line. The newest release must contain the running platform's archive and its checksum; a missing platform fails, without silently selecting an older release. @@ -148,21 +168,39 @@ mv -f polis.rollback polis ./polis --version ``` -## Publish from a reviewed tag - -The semantic version lives in `polis-cli/Cargo.toml`; increment it and refresh -`Cargo.lock` in the reviewed change. A `cli-vMAJOR.MINOR.PATCH` tag must match that -exact version. Pushing the tag starts the existing four-target native matrix. -The publish job alone has `contents: write`; builds retain read-only permission. -It downloads the current run's assets and validates exactly four archives and -four checksums, all with clean source status and the tagged full commit. - -The job creates a draft release for the existing tag (`--verify-tag`), uploads -the complete set, then publishes with generated release notes. It does not change -the repository's general latest-release pointer: the updater selects the CLI tag -namespace independently. A failed upload leaves a draft; an existing release -causes a rerun to stop, rather than overwrite its assets. Inspect and remove the -failed draft explicitly before rerunning. Signing/notarization and older glibc -compatibility remain separate distribution choices; the workflow adds neither. -No tag, public release, or workflow execution is needed to test this code: the -CLI uses a loopback release server and publication tests mock the GitHub CLI. +## Publish from a reviewed stable promotion + +The publication contract is one Polis release, with root `VERSION` as the +version authority. Generated Cargo versions must match it. The tag is exactly +`vMAJOR.MINOR.PATCH` on the full stable merge commit, never an edge or version +preparation commit. Release title: `Polis MAJOR.MINOR.PATCH`. The CLI has no +separate release numbering stream. + +Before publication: + +1. Review the computed version and stable promotion, migration list, release + notes and exact source commit. A promotion shipping a migration bumps MINOR; + otherwise PATCH. Major changes are Colin's decision. +2. Build and validate all four native targets from that stable commit. Each + archive manifest must contain the same Polis version, full stable commit and + clean source status. Preserve the `polis-cli-release/1` manifest format and + archive layout described above. +3. Prepare exactly eight assets on that same Polis release: four + `polis-VERSION-COMMIT12-TARGET.tar.gz` archives and their four `.sha256` files. + `COMMIT12` is the first 12 characters of the stable commit. Targets are + `aarch64-apple-darwin`, `x86_64-apple-darwin`, + `aarch64-unknown-linux-gnu`, and `x86_64-unknown-linux-gnu`. Asset names do not + gain a `v` or `cli-v` prefix. +4. Colin pushes the reviewed tag and publishes, or the publication workflow does + so only after his explicit release-environment approval. Builds and review + preparation have read-only permissions. Do not assume existing deployment + approval authorizes publication. This change does not enable that workflow; + shared publication tooling and its approval gate must be ready first. +5. Keep the release a draft until all eight assets and release notes validate. + A missing target prevents publication. Never silently overwrite published + tags or assets. Failed uploads leave a draft for explicit inspection and + cleanup or a verified resume. An older stable redeploy reuses its number. + +No tag, public release, or workflow execution is needed to test the updater: +its tests use a loopback release server. Signing/notarization and older glibc +compatibility remain separate distribution choices. From 19873803fa2b84ddca841a50cfb57009650554de Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Thu, 22 Oct 2026 12:45:22 -0700 Subject: [PATCH 23/30] participation: an unknown conversation id answers 404, not 500 (#3250) GET /api/v3/participation reported a server failure for a well-formed conversation id that matches no conversation; it now answers 404 with the code the resolver already used for that case, through an optional error responder on the shared parameter helper that only this route calls. Malformed ids keep their 400 codes and auth failures their 401; the success path is byte-identical. Co-authored-by: Claude Fable 5.1 --- .../integration/participation-errors.test.ts | 270 ++++++++++++++++++ server/app.ts | 7 +- server/src/routes/participation.ts | 48 +++- server/src/utils/parameter.ts | 17 +- 4 files changed, 332 insertions(+), 10 deletions(-) create mode 100644 server/__tests__/integration/participation-errors.test.ts diff --git a/server/__tests__/integration/participation-errors.test.ts b/server/__tests__/integration/participation-errors.test.ts new file mode 100644 index 000000000..0c21efa87 --- /dev/null +++ b/server/__tests__/integration/participation-errors.test.ts @@ -0,0 +1,270 @@ +import { + afterAll, + afterEach, + beforeAll, + describe, + expect, + jest, + test, +} from "@jest/globals"; +import { randomBytes, randomUUID } from "crypto"; +import type { Express } from "express"; +import request from "supertest"; +import { getApp } from "../app-loader"; +import { pool } from "../setup/db-test-helpers"; +import { issueParticipantJWT } from "../../src/auth/jwt-utils"; +import Config from "../../src/config"; +import pg from "../../src/db/pg-query"; + +const missingCode = "polis_err_fetching_zid_for_conversation_id"; +const parseCode = "polis_err_param_parse_failed_conversation_id"; +const summaryBytes = '{"0":{"votes":0,"comments":1}}'; + +describe("participation conversation errors", () => { + let app: Express; + let owner: number; + let stranger: number; + let token: string; + let strangerToken: string; + const zids: number[] = []; + const conversationId = `2${randomBytes(5).toString("hex").slice(0, 9)}`; + const shortId = `3${randomBytes(3).toString("hex").slice(0, 5)}`; + const unknownId = `4${randomBytes(5).toString("hex").slice(0, 9)}`; + + async function createConversation(id: string) { + const { rows } = await pool.query( + "INSERT INTO conversations (owner, is_active) VALUES ($1, TRUE) RETURNING zid", + [owner] + ); + const zid = rows[0].zid; + zids.push(zid); + await pool.query("INSERT INTO zinvites (zid, zinvite) VALUES ($1, $2)", [zid, id]); + return zid; + } + + beforeAll(async () => { + app = await getApp(); + const { rows } = await pool.query( + "INSERT INTO users (email) VALUES ($1), ($2) RETURNING uid", + [`owner-${randomUUID()}@example.invalid`, `stranger-${randomUUID()}@example.invalid`] + ); + [owner, stranger] = rows.map((row) => row.uid); + token = issueParticipantJWT("standard_user", conversationId, owner, 0, "owner"); + strangerToken = issueParticipantJWT("standard_user", conversationId, stranger, 0, "stranger"); + const zid = await createConversation(conversationId); + await createConversation(shortId); + const participant = await pool.query( + "INSERT INTO participants (zid, uid) VALUES ($1, $2) RETURNING pid", + [zid, owner] + ); + expect(participant.rows[0].pid).toBe(0); + await pool.query( + "INSERT INTO comments (zid, tid, pid, uid, txt) VALUES ($1, 0, 0, $2, $3)", + [zid, owner, "A comment for the participation summary"] + ); + }); + + afterEach(() => jest.restoreAllMocks()); + + afterAll(async () => { + await pool.query("DELETE FROM comments WHERE zid = ANY($1)", [zids]); + await pool.query("DELETE FROM participants WHERE zid = ANY($1)", [zids]); + await pool.query("DELETE FROM zinvites WHERE zid = ANY($1)", [zids]); + await pool.query("DELETE FROM conversations WHERE zid = ANY($1)", [zids]); + await pool.query("DELETE FROM users WHERE uid = ANY($1)", [[owner, stranger]]); + }); + + function visit(query: Record, auth: string | null = token) { + const req = request(app).get("/api/v3/participation").query(query); + return auth === null ? req : req.set("Authorization", `Bearer ${auth}`); + } + + function errorBody(code: string, status: number) { + return { error: code, message: code, status }; + } + + function expectLegacyParameterError( + response: request.Response, + error = missingCode, + name = "conversation_id", + value = unknownId + ) { + if (Config.reachableErrorHandler) { + expect(response.status).toBe(500); + expect(response.text).toBe(JSON.stringify({ + error: "internal_server_error", + message: "An unexpected error occurred. Please try again.", + })); + } else { + expect(response.status).toBe(400); + expect(response.text).toBe( + `polis_err_param_parse_failed_${name} (val='${value}', error=${error})\n` + ); + } + } + + async function ownedRows() { + const { rows } = await pool.query( + `SELECT + (SELECT count(*)::int FROM conversations WHERE owner = $1) AS conversations, + (SELECT count(*)::int FROM zinvites WHERE zinvite = $2 OR zid = ANY($3)) AS invites, + (SELECT count(*)::int FROM participants WHERE zid = ANY($3)) AS participants, + (SELECT count(*)::int FROM comments WHERE zid = ANY($3)) AS comments, + (SELECT count(*)::int FROM votes WHERE zid = ANY($3)) AS votes`, + [owner, unknownId, zids] + ); + return rows[0]; + } + + test("an unknown well-formed id answers 404 without writes or aggregation", async () => { + const before = await ownedRows(); + const writes = jest.spyOn(pg, "query"); + const promiseWrites = jest.spyOn(pg, "queryP"); + const aggregates = jest.spyOn(pg, "queryP_reportExport"); + const response = await visit({ conversation_id: unknownId }); + expect(await ownedRows()).toEqual(before); + expect(writes).not.toHaveBeenCalled(); + expect(promiseWrites).not.toHaveBeenCalled(); + expect(aggregates).not.toHaveBeenCalled(); + expect(response.status).toBe(404); + expect(response.body).toEqual(errorBody(missingCode, 404)); + }); + + test.each([ + ["overlong", "a".repeat(101)], + ["array", ["first", "second"]], + ["object", { value: "first" }], + ["empty", ""], + ["whitespace", " \t "], + ])("a %s id answers the existing parse code with 400", async (_label, value) => { + const lookup = jest.spyOn(pg, "query_readOnly"); + const response = await visit({ conversation_id: value }); + expect(response.status).toBe(400); + expect(response.body).toEqual(errorBody(parseCode, 400)); + expect(lookup).not.toHaveBeenCalled(); + }); + + test("a missing id answers the existing missing code with 400", async () => { + const response = await visit({}); + expect(response.status).toBe(400); + expect(response.body).toEqual(errorBody("polis_err_param_missing_conversation_id", 400)); + }); + + test("the owner's populated summary preserves the baseline response bytes", async () => { + const response = await visit({ conversation_id: conversationId }); + expect(response.status).toBe(200); + expect(response.text).toBe(summaryBytes); + }); + + test("six-character ids and empty summaries preserve the baseline response bytes", async () => { + const response = await visit({ conversation_id: shortId }); + expect(response.status).toBe(200); + expect(response.text).toBe("{}"); + }); + + test("closed conversations retain owner access and the baseline response bytes", async () => { + await pool.query("UPDATE conversations SET is_active = FALSE WHERE zid = $1", [zids[0]]); + try { + const response = await visit({ conversation_id: conversationId }); + expect(response.status).toBe(200); + expect(response.text).toBe(summaryBytes); + } finally { + await pool.query("UPDATE conversations SET is_active = TRUE WHERE zid = $1", [zids[0]]); + } + }); + + test("strict mode retains its 409 response bytes", async () => { + const response = await visit({ conversation_id: conversationId, strict: true }); + expect(response.status).toBe(409); + expect(response.text).toBe(JSON.stringify(errorBody( + "polis_err_get_participation_missing_xids This conversation has no xids for its participants.", + 409 + ))); + }); + + test("an authenticated non-owner retains the 403 response bytes", async () => { + const response = await visit({ conversation_id: conversationId }, strangerToken); + expect(response.status).toBe(403); + expect(response.text).toBe(JSON.stringify(errorBody("polis_err_get_participation_auth", 403))); + }); + + test.each([ + ["missing", null, "No authentication token found"], + ["invalid", "invalid-token", "Invalid token format"], + ])("%s auth retains the 401 response bytes before lookup", async (_label, auth, error) => { + const lookup = jest.spyOn(pg, "query_readOnly"); + const response = await visit({ conversation_id: unknownId }, auth); + expect(response.status).toBe(401); + expect(response.text).toBe(JSON.stringify(auth === null ? { error } : { + error, + details: "Token does not match any supported JWT type", + })); + expect(lookup).not.toHaveBeenCalled(); + }); + + test("a removed conversation with a cached id answers 404 without aggregation", async () => { + const id = `5${randomBytes(5).toString("hex").slice(0, 9)}`; + const zid = await createConversation(id); + const before = await visit({ conversation_id: id }); + expect(before.status).toBe(200); + expect(before.text).toBe("{}"); + await pool.query("DELETE FROM zinvites WHERE zid = $1", [zid]); + await pool.query("DELETE FROM conversations WHERE zid = $1", [zid]); + const aggregates = jest.spyOn(pg, "queryP_reportExport"); + const response = await visit({ conversation_id: id }); + expect(aggregates).not.toHaveBeenCalled(); + expect(response.status).toBe(404); + expect(response.body).toEqual(errorBody(missingCode, 404)); + }); + + test("a lookup service Error with the missing-row message retains the baseline response", async () => { + const read = pg.query_readOnly.bind(pg); + jest.spyOn(pg, "query_readOnly").mockImplementation((sql, params, callback) => { + if (String(sql).startsWith("select zid from zinvites")) { + callback(new Error(missingCode), undefined); + return; + } + return read(sql, params, callback); + }); + const response = await visit({ conversation_id: unknownId }); + expectLegacyParameterError(response, `Error: ${missingCode}`); + }); + + test.each(["/api/v3/participants", "/api/v3/comments"])( + "%s retains its existing lookup-error status and bytes", + async (path) => { + const response = await request(app).get(path) + .set("Authorization", `Bearer ${token}`) + .query({ conversation_id: unknownId }); + expectLegacyParameterError(response); + } + ); + + test("an invalid strict parameter retains its existing status and bytes", async () => { + const response = await visit({ conversation_id: conversationId, strict: "invalid" }); + expectLegacyParameterError(response, "polis_fail_parse_boolean", "strict", "invalid"); + }); + + test("an owner lookup service failure retains its 500 response bytes", async () => { + const query = pg.query.bind(pg); + jest.spyOn(pg, "query").mockImplementation((sql, params, callback) => { + if (String(sql).startsWith("SELECT * FROM conversations WHERE zid")) { + callback(new Error("owner lookup unavailable"), undefined); + return; + } + return query(sql, params, callback); + }); + const response = await visit({ conversation_id: conversationId }); + expect(response.status).toBe(500); + expect(response.text).toBe(JSON.stringify(errorBody("polis_err_get_participation_misc", 500))); + }); + + test("a report pool acquire timeout retains its 503 response bytes", async () => { + jest.spyOn(pg, "queryP_reportExport").mockRejectedValue( + new Error("timeout exceeded when trying to connect") + ); + const response = await visit({ conversation_id: conversationId }); + expect(response.status).toBe(503); + expect(response.text).toBe(JSON.stringify(errorBody("polis_err_get_participation_busy", 503))); + }); +}); diff --git a/server/app.ts b/server/app.ts index 2386552b6..3e730052f 100644 --- a/server/app.ts +++ b/server/app.ts @@ -133,6 +133,7 @@ import { import { handle_GET_participants, handle_GET_participation, + needParticipationConversationId, handle_GET_participationInit, handle_POST_query_participants_by_metadata, handle_PUT_participants_extended, @@ -762,11 +763,7 @@ export const appReady = helpersInitialized.then( "/api/v3/participation", moveToBody, hybridAuth(assignToP), - need( - "conversation_id", - getConversationIdFetchZid, - assignToPCustom("zid") - ), + needParticipationConversationId, want("strict", getBool, assignToP), handle_GET_participation ); diff --git a/server/src/routes/participation.ts b/server/src/routes/participation.ts index 1ad4e2a48..f6ced0e31 100644 --- a/server/src/routes/participation.ts +++ b/server/src/routes/participation.ts @@ -8,7 +8,13 @@ import { getPid, getUser } from "../user"; import { getVotesForSingleParticipant } from "./votes"; import { getXidRecord } from "../xids"; import { getXids } from "./xids"; -import { isConversationOwner, isOwner } from "../utils/common"; +import { isConversationOwner } from "../utils/common"; +import { getConversationInfo } from "../conversation"; +import { + assignToPCustom, + getConversationIdFetchZid, + need, +} from "../utils/parameter"; import { MPromise } from "../utils/metered"; import { ParticipantFields, ExpressResponse } from "../d"; import { sql_participants_extended } from "../db/sql"; @@ -100,6 +106,35 @@ function handle_GET_participants( }); } +const needParticipationConversationId = need( + "conversation_id", + (value: unknown) => { + if (typeof value === "string" && !value.trim()) { + return Promise.reject("polis_fail_parse_string_missing"); + } + return getConversationIdFetchZid(value); + }, + assignToPCustom("zid"), + (res, code, err) => { + // The resolver rejects this string only for an absent invite; database + // Errors, including one with the same message, keep the existing fallback. + if (err === "polis_err_fetching_zid_for_conversation_id") { + failJson(res, 404, err); + return true; + } + if ( + err === undefined || + err === "polis_fail_parse_string_missing" || + err === "polis_fail_parse_string_too_long" || + err === "polis_fail_parse_string_too_short" + ) { + failJson(res, 400, code); + return true; + } + return false; + } +); + function handle_GET_participation( req: { p: { zid: number; uid?: number; strict: any } }, res: ExpressResponse @@ -107,9 +142,13 @@ function handle_GET_participation( const zid = req.p.zid; const uid = req.p.uid; const strict = req.p.strict; - isOwner(zid, uid) - .then(function (ok: any) { - if (!ok) { + getConversationInfo(zid) + .then(function (info) { + if (!info) { + failJson(res, 404, "polis_err_fetching_zid_for_conversation_id"); + return; + } + if (info.owner !== uid) { failJson(res, 403, "polis_err_get_participation_auth"); return; } @@ -454,6 +493,7 @@ function handle_POST_query_participants_by_metadata( } export { + needParticipationConversationId, handle_GET_participants, handle_GET_participation, handle_GET_participationInit, diff --git a/server/src/utils/parameter.ts b/server/src/utils/parameter.ts index 7914eac4d..57ed698c8 100644 --- a/server/src/utils/parameter.ts +++ b/server/src/utils/parameter.ts @@ -31,13 +31,21 @@ function moveToBody(req: Req, res: any, next: () => void) { next(); } -function need(name: any, parserWhichReturnsPromise: any, assigner: any) { +type ParameterErrorHandler = (res: any, code: string, err?: any) => boolean; + +function need( + name: any, + parserWhichReturnsPromise: any, + assigner: any, + onError?: ParameterErrorHandler +) { return _buildCallback({ name: name, extractor: _extractFromBody, parserWhichReturnsPromise: parserWhichReturnsPromise, assigner: assigner, required: true, + onError, }); } @@ -97,6 +105,7 @@ function _buildCallback(config: { assigner: any; required: any; defaultVal?: any; + onError?: ParameterErrorHandler; }) { const name = config.name; const parserWhichReturnsPromise = config.parserWhichReturnsPromise; @@ -128,6 +137,9 @@ function _buildCallback(config: { function (err: any) { const s = `polis_err_param_parse_failed_${name} (val='${val}', error=${err})`; logger.error(s, err); + if (config.onError?.(res, `polis_err_param_parse_failed_${name}`, err)) { + return; + } res.status(400); next(s); return; @@ -145,6 +157,9 @@ function _buildCallback(config: { } else { const s = "polis_err_param_missing_" + name; logger.error(s); + if (config.onError?.(res, s)) { + return; + } res.status(400); next(s); } From 7204521a0c9381c36dc641877c02dce77f371563 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Thu, 22 Oct 2026 17:16:38 -0700 Subject: [PATCH 24/30] tls: distrust the eMudhra intermediates in every runtime, bundle and image, with tests (#3253) * tls: distrust the eMudhra intermediates in every runtime, bundle and image, with tests Eight eMudhra intermediate CA keys were recoverable; browsers block them but file-based trust stores do not until updated. Node images move to 22.23.4 / 24.22.1 (compiled-in SPKI blocklist), certifi to 2026.10.19, webpki-roots to 1.0.10 and rustls-webpki to 0.103.16, base image CA packages updated, and ci/tls asserts offline that each trust store rejects the sixteen affected certificate objects, direct and cross-signed. No served behaviour changes. Co-Authored-By: Claude Fable 5.1 * tls: the review's corrections: hash-checked Lambda payload, all sixteen objects with native verifiers, final runtime images and the probe base's local distrust The backup Lambda's certifi wheel is hash-checked and its real package is tested. ci/tls now checks all sixteen affected certificate objects by fingerprint and SPKI, including the code-signing intermediates, and proves the result with each runtime's native verifier (Node's compiled blocklist, Python's ssl/certifi/botocore paths, Java PKIX). The image gate covers the fifteen final runtime images. The probe base's Amazon Linux 2023 ca-certificates package has no fix yet, so it distrusts the affected roots locally by exact fingerprint through the p11-kit blocklist, to be removed once the vendor package ships. The legacy commentgraph image, which is not built or deployed, stays selectable but outside the required gate. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Fable 5.1 --- .../workflows/characterization-rerecord.yml | 2 +- .../client-participation-alpha-ci.yml | 2 +- .../collective-statement-recordings.yml | 4 +- .github/workflows/coordinator-ci.yml | 2 +- .github/workflows/delphi-characterization.yml | 2 +- .github/workflows/delphi-result-reads.yml | 2 +- .github/workflows/dynamo-removal.yml | 4 +- .github/workflows/jest-client-admin-test.yml | 2 +- .github/workflows/jest-client-report-test.yml | 2 +- .github/workflows/jest-server-test.yml | 2 +- .github/workflows/job-provenance.yml | 2 +- .github/workflows/job-views.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/polis-cli-ci.yml | 2 + .github/workflows/queue-rs-ci.yml | 4 +- .github/workflows/routing-recordings.yml | 2 +- .github/workflows/sensemaker-cron.yml | 2 +- .github/workflows/tls-trust.yml | 66 ++++ .github/workflows/vote-convention-gate.yml | 2 +- cdk/lambda/handler/requirements.txt | 2 + .../__snapshots__/workerClasses.test.ts.snap | 2 +- cdk/test/dbBackupLambda.test.ts | 15 +- ci/probe_box/ami/requirements.lock | 1 + ci/probe_box/local/Dockerfile | 3 + ci/probe_box/local/distrust-ca.py | 43 +++ ci/probe_box/requirements.txt | 1 + ci/tls/CheckJava.java | 51 +++ ci/tls/README.md | 115 ++++++ ci/tls/check-images.sh | 74 ++++ ci/tls/check-node.cjs | 60 +++ ci/tls/check-python.py | 115 ++++++ ci/tls/check_image.py | 105 ++++++ ci/tls/check_trust.py | 122 ++++++ ci/tls/distrust.json | 124 +++++++ ci/tls/fixtures/affected-intermediates.pem | 350 ++++++++++++++++++ ci/tls/fixtures/affected-roots.pem | 68 ++++ ...-g3b-aaa-emudhra.we-have-a-problem.com.pem | 38 ++ .../dv-g3b-emudhra.we-have-a-problem.com.pem | 56 +++ ...-g3c-aaa-emudhra.we-have-a-problem.com.pem | 38 ++ .../dv-g3c-emudhra.we-have-a-problem.com.pem | 56 +++ ...-g3b-aaa-emudhra.we-have-a-problem.com.pem | 38 ++ .../ev-g3b-emudhra.we-have-a-problem.com.pem | 56 +++ ...-g3c-aaa-emudhra.we-have-a-problem.com.pem | 38 ++ .../ev-g3c-emudhra.we-have-a-problem.com.pem | 56 +++ ...-g3b-aaa-emudhra.we-have-a-problem.com.pem | 38 ++ .../ov-g3b-emudhra.we-have-a-problem.com.pem | 56 +++ ...-g3c-aaa-emudhra.we-have-a-problem.com.pem | 38 ++ .../ov-g3c-emudhra.we-have-a-problem.com.pem | 56 +++ ci/tls/native_checks.py | 44 +++ ci/tls/python.Dockerfile | 6 + ci/tls/test_images.py | 79 ++++ ci/tls/test_probe_trust.py | 54 +++ ci/tls/test_trust.py | 79 ++++ client-admin/Dockerfile | 3 +- client-participation-alpha/Dockerfile | 3 +- client-participation/Dockerfile | 3 +- client-report/Dockerfile | 3 +- coordinator-rs/deploy/Dockerfile | 8 +- .../evidence/python-requirements.txt | 1 + delphi/Dockerfile | 13 +- delphi/pyproject.toml | 1 + delphi/requirements.lock | 2 +- .../polismath_commentgraph/pyproject.toml | 1 + .../polismath_commentgraph/requirements.txt | 1 + delphi/uv.lock | 16 +- deploy/requirements.txt | 1 + file-server/Dockerfile | 12 +- file-server/nginx.Dockerfile | 6 + math/Dockerfile | 10 +- math/distrust-ca.sh | 25 ++ oidc-simulator/Dockerfile | 4 +- polis-cli/Cargo.lock | 11 +- polis-cli/crates/polis-client/Cargo.toml | 6 + .../crates/polis-client/tests/tls_roots.rs | 74 ++++ queue-rs/polis-api/Dockerfile | 4 +- queue-rs/polis-migrate/Dockerfile | 4 +- server/Dockerfile | 6 +- server/Dockerfile-db | 4 +- server/Dockerfile-pdb | 1 + server/characterization/Dockerfile | 5 +- server/mise.toml | 2 +- 81 files changed, 2349 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/tls-trust.yml create mode 100644 ci/probe_box/local/distrust-ca.py create mode 100644 ci/tls/CheckJava.java create mode 100644 ci/tls/README.md create mode 100644 ci/tls/check-images.sh create mode 100644 ci/tls/check-node.cjs create mode 100644 ci/tls/check-python.py create mode 100644 ci/tls/check_image.py create mode 100644 ci/tls/check_trust.py create mode 100644 ci/tls/distrust.json create mode 100644 ci/tls/fixtures/affected-intermediates.pem create mode 100644 ci/tls/fixtures/affected-roots.pem create mode 100644 ci/tls/fixtures/dv-g3b-aaa-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/dv-g3b-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/dv-g3c-aaa-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/dv-g3c-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/ev-g3b-aaa-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/ev-g3b-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/ev-g3c-aaa-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/ev-g3c-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/ov-g3b-aaa-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/ov-g3b-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/ov-g3c-aaa-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/fixtures/ov-g3c-emudhra.we-have-a-problem.com.pem create mode 100644 ci/tls/native_checks.py create mode 100644 ci/tls/python.Dockerfile create mode 100644 ci/tls/test_images.py create mode 100644 ci/tls/test_probe_trust.py create mode 100644 ci/tls/test_trust.py create mode 100644 math/distrust-ca.sh create mode 100644 polis-cli/crates/polis-client/tests/tls_roots.rs diff --git a/.github/workflows/characterization-rerecord.yml b/.github/workflows/characterization-rerecord.yml index 0a34d5640..87d292c8c 100644 --- a/.github/workflows/characterization-rerecord.yml +++ b/.github/workflows/characterization-rerecord.yml @@ -46,7 +46,7 @@ jobs: persist-credentials: false - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 with: - node-version: '22' + node-version: "22.23.4" - name: Fetch the authenticated archive source object working-directory: target run: | diff --git a/.github/workflows/client-participation-alpha-ci.yml b/.github/workflows/client-participation-alpha-ci.yml index 4b88d4938..3410afd28 100644 --- a/.github/workflows/client-participation-alpha-ci.yml +++ b/.github/workflows/client-participation-alpha-ci.yml @@ -24,7 +24,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: "24" + node-version: "24.22.1" cache: "npm" cache-dependency-path: client-participation-alpha/package-lock.json diff --git a/.github/workflows/collective-statement-recordings.yml b/.github/workflows/collective-statement-recordings.yml index 56f39f5c1..c7aba2095 100644 --- a/.github/workflows/collective-statement-recordings.yml +++ b/.github/workflows/collective-statement-recordings.yml @@ -64,7 +64,7 @@ jobs: with: # The recordings were made on this Node; V8's error wording can # change between releases. - node-version: "22.23.1" + node-version: "22.23.4" cache: npm cache-dependency-path: server/package-lock.json @@ -75,7 +75,7 @@ jobs: - name: Install server dependencies and the reset routine's boto3 (delphi's locked versions) run: | npm ci --prefix server --no-audit --no-fund - python -m pip install --quiet boto3==1.34.70 botocore==1.34.162 s3transfer==0.10.4 + python -m pip install --quiet certifi==2026.10.19 boto3==1.34.70 botocore==1.34.162 s3transfer==0.10.4 - name: The harness's own rules (expected differences, refusal of foreign stores, the schema pin against the real migrations) working-directory: server diff --git a/.github/workflows/coordinator-ci.yml b/.github/workflows/coordinator-ci.yml index 184aebeff..6d2f6039f 100644 --- a/.github/workflows/coordinator-ci.yml +++ b/.github/workflows/coordinator-ci.yml @@ -57,7 +57,7 @@ jobs: - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 if: steps.paths.outputs.run == 'true' with: - node-version: '24' + node-version: "24.22.1" cache: npm cache-dependency-path: server/package-lock.json - name: Provision locked candidate and server modules diff --git a/.github/workflows/delphi-characterization.yml b/.github/workflows/delphi-characterization.yml index 53eb95d53..fa810b97d 100644 --- a/.github/workflows/delphi-characterization.yml +++ b/.github/workflows/delphi-characterization.yml @@ -47,7 +47,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: "22" + node-version: "22.23.4" cache: npm cache-dependency-path: server/package-lock.json diff --git a/.github/workflows/delphi-result-reads.yml b/.github/workflows/delphi-result-reads.yml index 8cbdedcb4..a164c71f5 100644 --- a/.github/workflows/delphi-result-reads.yml +++ b/.github/workflows/delphi-result-reads.yml @@ -19,5 +19,5 @@ jobs: persist-credentials: false - uses: actions/setup-node@v4 with: - node-version: '24' + node-version: "24.22.1" - run: bash scripts/test-delphi-result-reads.sh --ci diff --git a/.github/workflows/dynamo-removal.yml b/.github/workflows/dynamo-removal.yml index 0618553f7..746a49218 100644 --- a/.github/workflows/dynamo-removal.yml +++ b/.github/workflows/dynamo-removal.yml @@ -37,12 +37,12 @@ jobs: python-version: '3.12' - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: - node-version: '22' + node-version: "22.23.4" - name: Queue toolchain working-directory: queue-rs run: rustup show active-toolchain - name: Install uv - run: python -m pip install uv==0.9.2 + run: python -m pip install uv==0.13.4 - name: Queue, Postgres results, importer and report with DynamoDB stopped run: bash scripts/test-dynamo-removal.sh - name: Retain proof logs and report screenshots diff --git a/.github/workflows/jest-client-admin-test.yml b/.github/workflows/jest-client-admin-test.yml index d8b51e273..a38668760 100644 --- a/.github/workflows/jest-client-admin-test.yml +++ b/.github/workflows/jest-client-admin-test.yml @@ -20,7 +20,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '24' + node-version: "24.22.1" cache: 'npm' cache-dependency-path: client-admin/package-lock.json diff --git a/.github/workflows/jest-client-report-test.yml b/.github/workflows/jest-client-report-test.yml index 9af47e58e..bb1190007 100644 --- a/.github/workflows/jest-client-report-test.yml +++ b/.github/workflows/jest-client-report-test.yml @@ -20,7 +20,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '24' + node-version: "24.22.1" - name: Install dependencies run: npm install diff --git a/.github/workflows/jest-server-test.yml b/.github/workflows/jest-server-test.yml index e9626c442..68be63f38 100644 --- a/.github/workflows/jest-server-test.yml +++ b/.github/workflows/jest-server-test.yml @@ -127,7 +127,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '22' + node-version: "22.23.4" cache: 'npm' cache-dependency-path: server/package-lock.json diff --git a/.github/workflows/job-provenance.yml b/.github/workflows/job-provenance.yml index e73ee56e9..bb445a372 100644 --- a/.github/workflows/job-provenance.yml +++ b/.github/workflows/job-provenance.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 - with: {node-version: 22, cache: npm, cache-dependency-path: server/package-lock.json} + with: {node-version: "22.23.4", cache: npm, cache-dependency-path: server/package-lock.json} - run: npm ci --no-audit --no-fund working-directory: server - run: sh server/characterization/jobviews/check-provenance.sh diff --git a/.github/workflows/job-views.yml b/.github/workflows/job-views.yml index 8223c0923..df97e21d5 100644 --- a/.github/workflows/job-views.yml +++ b/.github/workflows/job-views.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4 with: {fetch-depth: 0} - uses: actions/setup-node@v4 - with: {node-version: 22} + with: {node-version: "22.23.4"} - run: npm ci --no-audit --no-fund working-directory: server - run: npm ci --no-audit --no-fund diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 88e6843ed..46963426d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,7 +17,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 24 + node-version: "24.22.1" - name: Get npm cache directory id: npm-cache diff --git a/.github/workflows/polis-cli-ci.yml b/.github/workflows/polis-cli-ci.yml index 7fcfbebce..0a5759282 100644 --- a/.github/workflows/polis-cli-ci.yml +++ b/.github/workflows/polis-cli-ci.yml @@ -7,6 +7,7 @@ on: pull_request: paths: - 'polis-cli/**' + - 'ci/tls/**' - 'queue-rs/polis-contracts/**' - 'server/__tests__/fixtures/vote-declaration/**' - 'scripts/test-polis-cli.sh' @@ -18,6 +19,7 @@ on: branches: [edge, stable] paths: - 'polis-cli/**' + - 'ci/tls/**' - 'queue-rs/polis-contracts/**' - 'server/__tests__/fixtures/vote-declaration/**' - 'scripts/test-polis-cli.sh' diff --git a/.github/workflows/queue-rs-ci.yml b/.github/workflows/queue-rs-ci.yml index b35cd9d84..1e74eabf6 100644 --- a/.github/workflows/queue-rs-ci.yml +++ b/.github/workflows/queue-rs-ci.yml @@ -187,7 +187,7 @@ jobs: persist-credentials: false - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 with: - node-version: '22.23.3' + node-version: "22.23.4" - name: Build and lint the runner working-directory: queue-rs run: | @@ -230,7 +230,7 @@ jobs: persist-credentials: false - uses: actions/setup-node@v4 with: - node-version: 22 + node-version: "22.23.4" - name: Install Node adapter test dependencies working-directory: server run: npm ci --no-audit --no-fund diff --git a/.github/workflows/routing-recordings.yml b/.github/workflows/routing-recordings.yml index e2fee2850..760febfa5 100644 --- a/.github/workflows/routing-recordings.yml +++ b/.github/workflows/routing-recordings.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v4 with: {fetch-depth: 0} - uses: actions/setup-node@v4 - with: {node-version: 22, cache: npm, cache-dependency-path: server/package-lock.json} + with: {node-version: "22.23.4", cache: npm, cache-dependency-path: server/package-lock.json} - run: npm ci --no-audit --no-fund working-directory: server - if: github.event_name == 'pull_request' diff --git a/.github/workflows/sensemaker-cron.yml b/.github/workflows/sensemaker-cron.yml index 336f5f1b6..3e245e392 100644 --- a/.github/workflows/sensemaker-cron.yml +++ b/.github/workflows/sensemaker-cron.yml @@ -22,7 +22,7 @@ jobs: uses: actions/setup-node@v3 with: cache-dependency-path: sensemaking-tools/package-lock.json - node-version: "18" + node-version: "22.23.4" cache: "npm" - name: Install dependencies diff --git a/.github/workflows/tls-trust.yml b/.github/workflows/tls-trust.yml new file mode 100644 index 000000000..16a8c04a0 --- /dev/null +++ b/.github/workflows/tls-trust.yml @@ -0,0 +1,66 @@ +name: TLS trust stores +on: + pull_request: + paths: + - '**/*Dockerfile*' + - '**/*requirements*' + - '**/pyproject.toml' + - '**/uv.lock' + - 'polis-cli/Cargo.lock' + - 'ci/tls/**' + - 'cdk/lambda/**' + - 'cdk/test/dbBackupLambda.test.ts' + - 'cdk/package*.json' + - 'ci/probe_box/local/**' + - 'ci/probe_box/ami/**' + - 'math/distrust-ca.sh' + - 'server/mise.toml' + - '.github/workflows/tls-trust.yml' + push: + branches: [edge, stable] + paths: + - '**/*Dockerfile*' + - '**/*requirements*' + - '**/pyproject.toml' + - '**/uv.lock' + - 'polis-cli/Cargo.lock' + - 'ci/tls/**' + - 'cdk/lambda/**' + - 'cdk/test/dbBackupLambda.test.ts' + - 'cdk/package*.json' + - 'ci/probe_box/local/**' + - 'ci/probe_box/ami/**' + - 'math/distrust-ca.sh' + - 'server/mise.toml' + - '.github/workflows/tls-trust.yml' + workflow_dispatch: +permissions: + contents: read +jobs: + trust: + strategy: + fail-fast: false + matrix: + image: [server, python, nginx, postgres, java, api, migrate, oidc, coordinator, file-server, clients, probe] + env: + TLS_IMAGE_SELECTION: ${{ matrix.image }} + # Match the arm64 runtime/probe builds without emulation. + runs-on: ubuntu-24.04-arm + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + persist-credentials: false + - name: Regression controls and version pins + run: python3 -m unittest discover -s ci/tls -p 'test_*.py' + - name: Build and inspect effective trust stores + run: bash ci/tls/check-images.sh + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 + if: matrix.image == 'server' + with: + node-version: '22.23.4' + - name: Hash-checked backup Lambda package + if: matrix.image == 'server' + working-directory: cdk + run: | + npm ci + npm test -- --runInBand dbBackupLambda diff --git a/.github/workflows/vote-convention-gate.yml b/.github/workflows/vote-convention-gate.yml index dc07f49e8..02ea62b3a 100644 --- a/.github/workflows/vote-convention-gate.yml +++ b/.github/workflows/vote-convention-gate.yml @@ -50,7 +50,7 @@ jobs: python-version: '3.12' - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: - node-version: '22' + node-version: "22.23.4" cache: npm cache-dependency-path: server/package-lock.json - name: Install the locked engine requirements and the server modules diff --git a/cdk/lambda/handler/requirements.txt b/cdk/lambda/handler/requirements.txt index 7d3eee270..8fe941d02 100644 --- a/cdk/lambda/handler/requirements.txt +++ b/cdk/lambda/handler/requirements.txt @@ -1,3 +1,5 @@ +certifi==2026.10.19 \ + --hash=sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b # Installed by lambda/lambda.ts (packageHandler) with pip for the Lambda's own # platform: CPython 3.12, x86_64, manylinux2014. The hash is the wheel's, so # the exact file is verified; it is the version the deployed function carries. diff --git a/cdk/test/__snapshots__/workerClasses.test.ts.snap b/cdk/test/__snapshots__/workerClasses.test.ts.snap index 6d0a48593..7a4a8b312 100644 --- a/cdk/test/__snapshots__/workerClasses.test.ts.snap +++ b/cdk/test/__snapshots__/workerClasses.test.ts.snap @@ -2075,7 +2075,7 @@ echo "polis-ci bootstrap ready at $(date -u --iso-8601=seconds) sha=$(cat /var/l "Properties": { "Code": { "S3Bucket": "cdk-hnb659fds-assets-123456789012-us-east-1", - "S3Key": "7627bf1413b97178c1f503313660828dafa457e250ede350f4d2897073221950.zip", + "S3Key": "75c3c8d7d6411954e53e87fb05e142ba2e20576b96e96dd1105773c1e1cde61d.zip", }, "EphemeralStorage": { "Size": 4096, diff --git a/cdk/test/dbBackupLambda.test.ts b/cdk/test/dbBackupLambda.test.ts index 6ed26c7fc..4a1110092 100644 --- a/cdk/test/dbBackupLambda.test.ts +++ b/cdk/test/dbBackupLambda.test.ts @@ -58,12 +58,18 @@ test('nothing in the cdk package depends on the Docker-bundling construct', () = test('the pinned requirement carries a hash for the Lambda platform wheel', () => { const requirements = fs.readFileSync(path.join(__dirname, '..', 'lambda', 'handler', 'requirements.txt'), 'utf8'); - const pins = requirements.split('\n').filter((l) => l.trim() && !l.trim().startsWith('#')).join('\n'); - expect(pins).toMatch(/^psycopg2-binary==\d+\.\d+\.\d+ \\\n\s+--hash=sha256:[0-9a-f]{64}$/); + const pins = requirements.split('\n').filter((l) => l.trim() && !l.trim().startsWith('#')) + .join('\n').replace(/\s*\\\n\s*/g, ' ').split('\n'); + expect(pins).toHaveLength(2); + expect(pins).toContain('certifi==2026.10.19 --hash=sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b'); + expect(pins.some((pin) => pin.startsWith('psycopg2-binary=='))).toBe(true); + for (const pin of pins) { + expect(pin).toMatch(/^[a-z0-9-]+==\d+\.\d+\.\d+ --hash=sha256:[0-9a-f]{64}$/); + } }); // Runs pip for real (no Docker): the package must hold exactly the handler, -// its requirements file and the psycopg2 wheel's contents, and nothing else. +// its requirements file, psycopg2 and the hash-checked certifi trust bundle. // Needs python3 with pip and the wheel (network, or a warm pip cache). test('packageHandler builds the Lambda package with pip, without Docker', () => { const out = fs.mkdtempSync(path.join(os.tmpdir(), 'db-backup-package-')); @@ -80,6 +86,9 @@ test('packageHandler builds the Lambda package with pip, without Docker', () => expect(files).toContain('dbBackuplambda.py'); expect(files).toContain('requirements.txt'); expect(files).toContain('psycopg2/__init__.py'); + expect(files).toContain('certifi/cacert.pem'); + expect(files).toContain('certifi-2026.10.19.dist-info/RECORD'); + expect(fs.readFileSync(path.join(out, 'certifi', '__init__.py'), 'utf8')).toContain('2026.10.19'); expect(files).toContain('psycopg2/_psycopg.cpython-312-x86_64-linux-gnu.so'); expect(files.filter((f) => f.startsWith('psycopg2_binary.libs/libpq-'))).toHaveLength(1); expect(files.filter((f) => /^psycopg2_binary-\d+\.\d+\.\d+\.dist-info\/RECORD$/.test(f))).toHaveLength(1); diff --git a/ci/probe_box/ami/requirements.lock b/ci/probe_box/ami/requirements.lock index 086ca733f..90db355d5 100644 --- a/ci/probe_box/ami/requirements.lock +++ b/ci/probe_box/ami/requirements.lock @@ -7,3 +7,4 @@ python-dateutil==2.9.0.post0 --hash=sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0 six==1.17.0 --hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 urllib3==2.7.0 --hash=sha256:9fb4c81ebbb1ce9531cce37674bbc6f1360472bc18ca9a553ede278ef7276897 psycopg2-binary==2.9.13 --hash=sha256:3dc3372b3731b3ef23407fe06b94f640ef87a2bda242fa386033d5589c87514a +certifi==2026.10.19 --hash=sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b diff --git a/ci/probe_box/local/Dockerfile b/ci/probe_box/local/Dockerfile index 9c876d8b8..dd67db430 100644 --- a/ci/probe_box/local/Dockerfile +++ b/ci/probe_box/local/Dockerfile @@ -1,2 +1,5 @@ FROM amazonlinux:2023 RUN dnf -y --releasever=2023.12.20260831 --disablerepo='*' --enablerepo=amazonlinux install docker-25.0.16-1.amzn2023.0.4.aarch64 containerd-2.2.5-1.amzn2023.0.2.aarch64 runc-1.3.5-1.amzn2023.0.2.aarch64 skopeo-2:1.22.2-1.amzn2023.0.1.aarch64 python3.12 util-linux && dnf clean all +# Local distrust pending a fixed Amazon Linux ca-certificates package. +COPY distrust-ca.py /tmp/distrust-ca.py +RUN python3.12 /tmp/distrust-ca.py && update-ca-trust extract && rm /tmp/distrust-ca.py diff --git a/ci/probe_box/local/distrust-ca.py b/ci/probe_box/local/distrust-ca.py new file mode 100644 index 000000000..68b944901 --- /dev/null +++ b/ci/probe_box/local/distrust-ca.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +"""Block affected parent roots pending the Amazon Linux CA package update.""" +import hashlib +from pathlib import Path +import re +import ssl + + +# Keep these certificate fingerprints aligned with ci/tls/distrust.json roots. +BLOCKED = { + '86A1ECBA089C4A8D3BBE2734C612BA341D813E043CF9E8A862CD5C57A36BBE6B', + 'D7A7A0FB5D7E2731D771E9484EBCDEF71D5F0C3E0A2948782BC83EE0EA699EF4', + '7DD78D5F4F13459A83DFF9ABBBA62EDBAF6F2D102BF257FD712F4D9F2746ED8D', + 'F2EDAAFF3D9B701FB4D14C9F285F8C0BAD90FC3BCC1FA07D47F4718EDABA34A5', +} +PEM = re.compile(r'-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----', re.S) + + +def block_roots(bundle, destination): + certificates = PEM.findall(Path(bundle).read_text()) + if not certificates: + raise ValueError('Source CA bundle is empty or malformed') + matches = {} + for certificate in certificates: + digest = hashlib.sha256(ssl.PEM_cert_to_DER_cert(certificate)).hexdigest().upper() + if digest in BLOCKED: + matches[digest] = certificate + Path(destination).mkdir(parents=True, exist_ok=True) + for digest, certificate in sorted(matches.items()): + (Path(destination) / f'emudhra-{digest}.pem').write_text(certificate + '\n') + print(f'Blocklisted certificate SHA256 {digest}') + return set(matches) + + +def install_blocklist(source, destination): + # A parent can remain trusted for email/object signing after leaving TLS. + for purpose in ('tls', 'email', 'objsign'): + block_roots(Path(source) / f'{purpose}-ca-bundle.pem', destination) + + +if __name__ == '__main__': + install_blocklist('/etc/pki/ca-trust/extracted/pem', + '/etc/pki/ca-trust/source/blocklist') diff --git a/ci/probe_box/requirements.txt b/ci/probe_box/requirements.txt index 24d5ba287..417cb0e99 100644 --- a/ci/probe_box/requirements.txt +++ b/ci/probe_box/requirements.txt @@ -1,3 +1,4 @@ +certifi==2026.10.19 boto3==1.43.89 botocore==1.43.89 jmespath==1.1.0 diff --git a/ci/tls/CheckJava.java b/ci/tls/CheckJava.java new file mode 100644 index 000000000..01e1cd581 --- /dev/null +++ b/ci/tls/CheckJava.java @@ -0,0 +1,51 @@ +import java.io.*; +import java.nio.file.*; +import java.security.*; +import java.security.cert.*; +import java.util.*; + +// PKIX path validation, without a TLS EKU requirement: code-signing +// intermediates must fail because no trusted path exists, not wrong usage. +class CheckJava { + static Collection certs(Path file) throws Exception { + try (InputStream in = Files.newInputStream(file)) { + var result = new ArrayList(); + for (var cert : CertificateFactory.getInstance("X.509").generateCertificates(in)) + result.add((X509Certificate) cert); + return result; + } + } + static void verify(X509Certificate cert, Set roots, boolean accepted) throws Exception { + var params = new PKIXParameters(roots); + params.setRevocationEnabled(false); + // Use a fixed point in this object's validity interval, independent of + // wall clock; trust-anchor validity is not checked by PKIX validation. + params.setDate(new Date(cert.getNotBefore().getTime() + 86400000L)); + var path = CertificateFactory.getInstance("X.509").generateCertPath(List.of(cert)); + try { + CertPathValidator.getInstance("PKIX").validate(path, params); + if (!accepted) throw new AssertionError("affected object still trusted: " + cert.getSerialNumber()); + } catch (CertPathValidatorException error) { + if (accepted || error.getReason() != PKIXReason.NO_TRUST_ANCHOR) throw error; + } + } + public static void main(String[] args) throws Exception { + var objects = certs(Path.of("/audit/fixtures/affected-intermediates.pem")); + if (objects.size() != 16) throw new AssertionError("expected sixteen objects"); + var old = new HashSet(); + for (var cert : certs(Path.of("/audit/fixtures/affected-roots.pem"))) old.add(new TrustAnchor(cert, null)); + var store = KeyStore.getInstance(KeyStore.getDefaultType()); + try (InputStream in = Files.newInputStream(Path.of(System.getProperty("java.home"), "lib/security/cacerts"))) { + store.load(in, "changeit".toCharArray()); + } + var current = new HashSet(); + var aliases = store.aliases(); + while (aliases.hasMoreElements()) current.add(new TrustAnchor((X509Certificate) store.getCertificate(aliases.nextElement()), null)); + if (current.size() < 50) throw new AssertionError("unexpectedly small Java store"); + for (var cert : objects) { + verify(cert, old, true); + verify(cert, current, false); + } + System.out.println("PASS Java native PKIX: 16/16 stale-store acceptances and 16/16 distrust refusals"); + } +} diff --git a/ci/tls/README.md b/ci/tls/README.md new file mode 100644 index 000000000..4d2605b99 --- /dev/null +++ b/ci/tls/README.md @@ -0,0 +1,115 @@ +# TLS trust regression checks + +The [October 2026 disclosure](https://emudhra.we-have-a-problem.com/) identifies +compromised eMudhra intermediate keys and their Sectigo cross-signs. The public +certificate fixtures come from that disclosure's `chains.zip` and `roots.json`, +retrieved 2026-10-21. They contain certificates only, never private keys. + +Run the same entry points locally and in hosted CI: + +```sh +python3 -m unittest discover -s ci/tls -p 'test_*.py' +bash ci/tls/check-images.sh +cd cdk && npm ci && npm test -- --runInBand dbBackupLambda +``` + +OpenSSL 3, Python 3.11+, Docker with named build contexts, and the toolchains +needed by the final images are required. Set `OPENSSL` if OpenSSL 3 is not the +default executable. Builds and Lambda wheel installation need package-network +access. Certificate checks themselves are offline. All audit containers run +with `--network=none`; Node handshakes use container-local loopback only. +No application, job worker, database or production endpoint is started. + +`check_trust.py` checks exact SHA-256, SPKI and serial identities for all sixteen +intermediate objects. Each effective PEM store must reject all sixteen with an +issuer/trust error using `-purpose any`, isolated roots and disabled time checks. +Four objects are code-signing intermediates: a TLS-usage failure would not prove +distrust. Separately, all twelve published direct/cross-signed TLS leaf chains +must fail for trust, with expiry disabled. Stale roots must accept all sixteen +objects and twelve leaf chains in the regression controls, and fail the gate. +Empty/truncated stores and affected objects installed as anchors fail as well. + +The native checks add evidence beyond exporting stores to host OpenSSL: + +- Node's real TLS handshake accepts a generated local chain, rejects it with + `CERT_REVOKED` after its intermediate is added using Node's test-only hook, + then accepts it after that test entry is cleared. Each affected object is + also sent alongside an untrusted local chain: all sixteen must return + `CERT_REVOKED` from the **compiled** blocklist, without injecting those keys. + This tests Node's documented peer-chain fallback, not a forged affected leaf + chain. The unaffected untrusted control must return the ordinary issuer error. + Temporary test keys are generated for each run and removed afterwards. + See the [upstream native callback and test hooks](https://github.com/nodejs/node/commit/4342503fd8). +- Python's actual HTTPX and stdlib SSL contexts, plus requests/certifi/botocore + bundle paths, are validated with the image's native libcrypto. The probe + worker declares its smaller boto-only dependency set explicitly. The checker + requires that libcrypto and Python ssl report the same OpenSSL version. + Generic path verification disables time checks and does not select TLS EKU; + every store rejects sixteen objects, while isolated stale roots accept them. +- Java uses its own PKIX validator and final `cacerts`, with revocation-network + lookups disabled and a fixed date within each object's validity. Every object + must fail with `NO_TRUST_ANCHOR`; old roots must accept the same objects. There + is no TLS EKU restriction that could hide code-signing trust. + +The matrix builds final server `prod`, Delphi `final` (CPU dependency option, +including the real `polis-jobs` binary and RDS bundle), math `runtime`, nginx, +migration-carrying Postgres, API, migrator, OIDC, coordinator, file-server, three +standalone client images and the local probe base/worker. Commentgraph is not +built or deployed; its legacy recipe remains an optional named audit. +No base/trust-only stage substitutes for a shipped runtime. The daemon's +`--version` check establishes presence/loadability, not database connectivity. +No numerical/model integration or deployed-image equivalence is claimed. + +`TLS_IMAGE_TAG` selects an isolated tag prefix. `TLS_IMAGE_SELECTION` can select +one or more of the named groups in `check-images.sh`; unset means every required +group. Use `TLS_IMAGE_SELECTION=commentgraph` to audit the legacy recipe. +Hosted CI assigns a group to each native arm64 runner to bound disk use and +match the probe recipes. An x86 local builder needs arm64 emulation for probes. The matrix regression +tests require all fifteen shipped configurations and the daemon/RDS audit, and +check that the optional legacy audit remains selectable. +Remove only your own image tags and build outputs after local checks. + +Node 22.23.4 / 24.22.1 update NSS roots and block the compromised intermediate +keys. certifi 2026.10.19 removes the affected roots. The CLI locks webpki-roots +1.0.10 and rustls-webpki 0.103.16; its separate tests check anchors and the twelve +TLS chains with old roots supplied. The legacy nginx and Java images explicitly +remove affected roots. Maintained Alpine/Debian versions are checked against +the advisory floor. RPM stores are verified by their actual certificate paths, +not by assuming a release-pinned package command updated them. + +Rebuild and replace running images and CLI binaries. An OS update does not +change embedded Node or Rust stores. Deployments must separately audit mounted +CA files, Java truststore overrides, NODE_EXTRA_CA_CERTS, SSL_CERT_FILE/ +SSL_CERT_DIR, REQUESTS_CA_BUNDLE and AWS_CA_BUNDLE. `--rds-only` is reserved for +the coordinator, whose TLS client disables system roots; it is inappropriate +for a client which also trusts public roots. Backup Lambda packaging retains +`--require-hashes` and tests the real platform-specific pip invocation and the +included certifi bundle. Existing host/AMI/CodeDeploy/browser stores and already +issued CLI binaries require their own update and effective-store verification. +Neither certificate-verification bypasses nor served certificates are changed. + +### Temporary Amazon Linux probe blocklist + +The local probe base fingerprint-matches every affected parent root present in +its extracted TLS, email and object-signing bundles against the four roots in `distrust.json`, writes those +certificates to `/etc/pki/ca-trust/source/blocklist/`, then runs +`update-ca-trust extract`. It retains the pinned runtime packages. The required +probe base and worker gates audit the system alias and extracted TLS, email and +object-signing PEM bundles, plus the worker's Python stores. Stale-root controls +remain required; removing a certificate by its display name is not sufficient. + +This is temporary while Amazon Linux 2023 `ca-certificates` is awaiting its +[CVE-2026-113470 fix](https://explore.alas.aws.amazon.com/CVE-2026-113470.html). +The affected package observed on October 22 is +`2025.2.76-1.0.amzn2023.0.3`; no fixed version is published yet. Watch that +advisory for the first fixed AL2023 package and its repository release. Once +available, pin the fixed package/release, remove the Dockerfile helper copy/run +and `distrust-ca.py`, and rebuild from a clean base without the local blocklist. +Require the full trust gate to pass, including every affected-object refusal +and stale-store control; a numerically newer package alone is insufficient. +Remove the helper-specific unit test in that same replacement change, retaining +the final-image and stale-store tests. + +After merge, the release operator must rebuild and republish the probe base, +record its new digest, and update/readmit the approved digest-pinned inputs. +Running this local gate does not publish an image or update an approved digest. diff --git a/ci/tls/check-images.sh b/ci/tls/check-images.sh new file mode 100644 index 000000000..3a8b72a5a --- /dev/null +++ b/ci/tls/check-images.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# Build final shipped images; the same gate runs locally and in hosted CI. +set -euo pipefail +cd "$(dirname "$0")/../.." +tag=${TLS_IMAGE_TAG:-polis-tls-check} +export PYTHONDONTWRITEBYTECODE=1 + +# Leave unset to run required final-image checks; CI assigns one group per runner. +# Commentgraph is optional: not built or deployed; legacy recipe. +for selection in ${TLS_IMAGE_SELECTION:-server python nginx postgres java api migrate oidc coordinator file-server clients probe}; do + case "$selection" in + server) + docker build --pull --target prod -t "$tag-server" -f server/Dockerfile . + python3 ci/tls/check_image.py "$tag-server" --node --rds + ;; + python) + docker build --pull --target final --build-context queue-rs=queue-rs \ + --build-arg USE_CPU_TORCH=true -t "$tag-python" delphi + python3 ci/tls/check_image.py "$tag-python" --python --rds --jobs + ;; + nginx) + docker build --pull -t "$tag-nginx" -f file-server/nginx.Dockerfile file-server + python3 ci/tls/check_image.py "$tag-nginx" --manual-distrust + ;; + postgres) + docker build --pull --build-context queue-rs=queue-rs -t "$tag-postgres" -f server/Dockerfile-db server + python3 ci/tls/check_image.py "$tag-postgres" + ;; + java) + docker build --pull --target runtime -t "$tag-java" math + python3 ci/tls/check_image.py "$tag-java" --java --manual-distrust + ;; + api) + docker build --pull -t "$tag-api" -f queue-rs/polis-api/Dockerfile queue-rs + python3 ci/tls/check_image.py "$tag-api" + ;; + migrate) + docker build --pull -t "$tag-migrate" -f queue-rs/polis-migrate/Dockerfile . + python3 ci/tls/check_image.py "$tag-migrate" --rds + ;; + oidc) + docker build --pull -t "$tag-oidc" oidc-simulator + python3 ci/tls/check_image.py "$tag-oidc" --node + ;; + coordinator) + docker build --pull -t "$tag-coordinator" -f coordinator-rs/deploy/Dockerfile . + python3 ci/tls/check_image.py "$tag-coordinator" --rds-only + ;; + file-server) + docker build --pull -t "$tag-file-server" -f file-server/Dockerfile . + python3 ci/tls/check_image.py "$tag-file-server" --node + ;; + clients) + for client in admin participation report; do + docker build --pull -t "$tag-client-$client" -f "client-$client/Dockerfile" . + python3 ci/tls/check_image.py "$tag-client-$client" --node + done + ;; + commentgraph) + docker build --pull -t "$tag-commentgraph" delphi/umap_narrative/polismath_commentgraph + python3 ci/tls/check_image.py "$tag-commentgraph" --python --rpm + ;; + probe) + # The local probe recipe explicitly installs aarch64 packages. Its worker + # copies the same hash-locked requirements used by the immutable AMI build. + docker build --pull --platform linux/arm64 -t "$tag-probe-base" ci/probe_box/local + python3 ci/tls/check_image.py "$tag-probe-base" --rpm + docker build --platform linux/arm64 --build-arg RUNTIME_IMAGE="$tag-probe-base" \ + -t "$tag-probe-worker" -f ci/probe_box/local/worker.Dockerfile ci/probe_box/ami + python3 ci/tls/check_image.py "$tag-probe-worker" --python --python-bin python3.12 --boto-only --rpm + ;; + *) echo "Unknown image selection: $selection" >&2; exit 2;; + esac +done diff --git a/ci/tls/check-node.cjs b/ci/tls/check-node.cjs new file mode 100644 index 000000000..352b2e004 --- /dev/null +++ b/ci/tls/check-node.cjs @@ -0,0 +1,60 @@ +'use strict'; +// Offline native-verifier controls. The runtime's compiled blocklist is used +// for affected objects; test hooks are used only for our generated local CA. +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const tls = require('node:tls'); +const { once } = require('node:events'); +const { X509Certificate, createHash } = require('node:crypto'); +const { internalBinding } = require('internal/test/binding'); +const { addBlockedSPKIForTesting, clearBlockedSPKIsForTesting } = internalBinding('crypto'); +const dir = process.argv[2]; +const root = fs.readFileSync(`${dir}/root.pem`, 'utf8'); +const intermediate = fs.readFileSync(`${dir}/intermediate.pem`, 'utf8'); +const leaf = fs.readFileSync(`${dir}/leaf.pem`, 'utf8'); +const key = fs.readFileSync(`${dir}/leaf.key`, 'utf8'); +const objects = fs.readFileSync('/audit/fixtures/affected-intermediates.pem', 'utf8') + .match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g); +assert.equal(objects.length, 16); + +async function handshake(extra, ca, expected) { + const server = tls.createServer({ key, cert: leaf + intermediate + extra }, s => s.end()); + server.on('tlsClientError', () => {}); + server.listen(0, '127.0.0.1'); + await once(server, 'listening'); + let client; + try { + client = tls.connect({ host: '127.0.0.1', port: server.address().port, + servername: 'localhost', ca, rejectUnauthorized: true }); + client.setTimeout(5000, () => client.destroy(new Error('local TLS test timed out'))); + if (expected) { + await assert.rejects(once(client, 'secureConnect'), { code: expected }); + } else { + await once(client, 'secureConnect'); + assert.equal(client.authorized, true); + } + } finally { + client?.destroy(); + await new Promise(resolve => server.close(resolve)); + } +} + +(async () => { + await handshake('', root); + await handshake('', [], 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'); + const spki = new X509Certificate(intermediate).publicKey.export({ type: 'spki', format: 'der' }); + try { + addBlockedSPKIForTesting(createHash('sha256').update(spki).digest()); + await handshake('', root, 'CERT_REVOKED'); + } finally { + clearBlockedSPKIsForTesting(); + } + await handshake('', root); + // An untrusted generated chain makes Node inspect every peer-sent object. + // These are blocklist-precedence checks, not forged affected leaf chains. + // No hook inserts affected keys: each must already be compiled into Node. + for (const object of objects) { + await handshake(object, [], 'CERT_REVOKED'); + } + console.log('PASS Node native verifier: 16/16 compiled-key refusals; 4 generated-chain controls'); +})().catch(error => { console.error(error); process.exitCode = 1; }); diff --git a/ci/tls/check-python.py b/ci/tls/check-python.py new file mode 100644 index 000000000..8433941c5 --- /dev/null +++ b/ci/tls/check-python.py @@ -0,0 +1,115 @@ +"""Validate all intermediate objects with the image's native OpenSSL library. + +Use the actual HTTPX/stdlib contexts and requests/botocore CA files. No network, +TLS EKU or wall-clock validity checks: code-signing objects are included. +""" +import ctypes as c +import ctypes.util +import re +import ssl +import sys +from pathlib import Path + +import botocore.httpsession +import certifi + +PEM = re.compile(r'-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----', re.S) +lib = c.CDLL(ctypes.util.find_library('crypto')) + + +def bind(name, result, *arguments): + function = getattr(lib, name) + function.restype = result + function.argtypes = arguments + return function + + +ptr = c.c_void_p +bio_new = bind('BIO_new_mem_buf', ptr, ptr, c.c_int) +bio_free = bind('BIO_free', c.c_int, ptr) +read_cert = bind('PEM_read_bio_X509', ptr, ptr, ptr, ptr, ptr) +free_cert = bind('X509_free', None, ptr) +new_store = bind('X509_STORE_new', ptr) +free_store = bind('X509_STORE_free', None, ptr) +add_cert = bind('X509_STORE_add_cert', c.c_int, ptr, ptr) +set_flags = bind('X509_STORE_set_flags', c.c_int, ptr, c.c_ulong) +new_ctx = bind('X509_STORE_CTX_new', ptr) +free_ctx = bind('X509_STORE_CTX_free', None, ptr) +init_ctx = bind('X509_STORE_CTX_init', c.c_int, ptr, ptr, ptr, ptr) +verify = bind('X509_verify_cert', c.c_int, ptr) +get_error = bind('X509_STORE_CTX_get_error', c.c_int, ptr) +version = bind('OpenSSL_version', c.c_char_p, c.c_int) +if version(0).decode() != ssl.OPENSSL_VERSION: + raise AssertionError('Loaded libcrypto does not match Python ssl') + + +def parse(text): + data = text.encode() + bio = bio_new(data, len(data)) + if not bio: + raise AssertionError('BIO allocation failed') + try: + cert = read_cert(bio, None, None, None) + if not cert: + raise AssertionError('certificate parse failed') + return cert + finally: + bio_free(bio) + + +def check(roots, objects, accepted, label): + store = new_store() + if not store: + raise AssertionError('store allocation failed') + try: + # X509_V_FLAG_NO_CHECK_TIME. No purpose set: generic PKIX validation. + assert set_flags(store, 0x200000) == 1 + for root in set(roots): + cert = parse(root) + try: + assert add_cert(store, cert) == 1 + finally: + free_cert(cert) + for text in objects: + cert, ctx = parse(text), new_ctx() + try: + assert ctx and init_ctx(ctx, store, cert, None) == 1 + result = verify(ctx) + error = get_error(ctx) + if accepted: + assert result == 1 and error == 0, (label, result, error) + else: + assert result == 0 and error in {2, 18, 19, 20, 21, 28}, (label, result, error) + finally: + free_ctx(ctx) + free_cert(cert) + finally: + free_store(store) + print(f'PASS Python native {label}: 16/16 ' + ('stale-store acceptances' if accepted else 'distrust refusals')) + + +objects = PEM.findall(Path('/audit/fixtures/affected-intermediates.pem').read_text()) +assert len(objects) == 16 +check(PEM.findall(Path('/audit/fixtures/affected-roots.pem').read_text()), objects, True, 'old roots') +paths = {certifi.where(), botocore.httpsession.get_cert_path(True)} +try: + import requests.certs +except ImportError: + if '--boto-only' not in sys.argv: + raise +else: + paths.add(requests.certs.where()) +for path in sorted(paths): + check(PEM.findall(Path(path).read_text()), objects, False, path) +contexts = {'stdlib': ssl.create_default_context()} +try: + import httpx +except ImportError: + if '--boto-only' not in sys.argv: + raise +else: + contexts['HTTPX'] = httpx.create_ssl_context() +for label, context in contexts.items(): + roots = [ssl.DER_cert_to_PEM_cert(cert) for cert in context.get_ca_certs(binary_form=True)] + assert roots, f'empty {label} context' + check(roots, objects, False, label) diff --git a/ci/tls/check_image.py b/ci/tls/check_image.py new file mode 100644 index 000000000..2d3d8f63f --- /dev/null +++ b/ci/tls/check_image.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +"""Inspect built images without starting the application or using credentials.""" +import argparse +import json +import subprocess +from check_trust import BLOCKED, audit_bundle, audit_chains, audit_objects + +from native_checks import node, run_native + +def run(image, executable, *args): + return subprocess.check_output(['docker', 'run', '--rm', '--network=none', + '--entrypoint', executable, image, *args], text=True) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('image') + parser.add_argument('--node', action='store_true') + parser.add_argument('--python', action='store_true') + parser.add_argument('--python-bin', default='python') + parser.add_argument('--boto-only', action='store_true') + parser.add_argument('--rpm', action='store_true') + parser.add_argument('--jobs', action='store_true') + parser.add_argument('--rds', action='store_true') + parser.add_argument('--rds-only', action='store_true') + parser.add_argument('--java', action='store_true') + parser.add_argument('--manual-distrust', action='store_true') + args = parser.parse_args() + image = args.image + bundles = {} + if not args.rds_only: + versions = run(image, 'sh', '-c', 'if command -v apk >/dev/null; then apk list --installed ca-certificates; elif command -v rpm >/dev/null; then rpm -q ca-certificates; else dpkg-query -W ca-certificates; fi') + print(image, versions.strip()) + if not args.manual_distrust and not args.rpm: + run(image, 'sh', '-ec', """if command -v apk >/dev/null; then + apk info -e 'ca-certificates>=20261020-r0' + else + . /etc/os-release + case "$VERSION_CODENAME" in + bookworm) floor='20250419~deb12u2';; + trixie) floor='20250419+deb13u1';; + *) echo 'Unsupported distribution: declare and test its advisory version'; exit 1;; + esac + installed=$(dpkg-query -W -f='${Version}' ca-certificates) + dpkg --compare-versions "$installed" ge "$floor" + fi""") + print('PASS distribution ca-certificates advisory version') + bundles['system'] = run(image, 'cat', '/etc/pki/tls/certs/ca-bundle.crt' if args.rpm else '/etc/ssl/certs/ca-certificates.crt') + if args.rpm: + for purpose in ('tls', 'email', 'objsign'): + path = f'/etc/pki/ca-trust/extracted/pem/{purpose}-ca-bundle.pem' + bundles[path] = run(image, 'cat', path) + if args.rds or args.rds_only: + bundles['rds'] = run(image, 'cat', '/etc/polis/rds-ca.pem') + if args.java: + bundles['java-cacerts'] = run(image, 'keytool', '-list', '-rfc', '-cacerts', '-storepass', 'changeit') + if args.node: + version = run(image, 'node', '-p', 'process.versions.node').strip() + parts = tuple(map(int, version.split('.'))) + floors = {22: (22, 23, 4), 24: (24, 22, 1), 26: (26, 12, 1)} + if parts[0] not in floors or parts < floors[parts[0]]: + raise ValueError(f'Unpatched Node: {version}') + print('PASS Node', version) + # Emit compact fingerprints instead of a large PEM dump; validate each + # certificate with Node's own parser before checking the effective store. + roots = json.loads(run(image, 'node', '-e', "const X=require('crypto').X509Certificate; console.log(JSON.stringify(require('tls').getCACertificates('default').map(p => new X(p).fingerprint256.replaceAll(':',''))))")) + if len(roots) < 100: + raise ValueError('Unexpectedly small Node default trust store') + for digest in roots: + if digest in BLOCKED: + raise ValueError(f'Node default store trusts {BLOCKED[digest]}') + print(f'PASS Node default store: {len(roots)} parsed certificates, no affected anchors') + names = run(image, 'node', '-e', "const X=require('crypto').X509Certificate; console.log(JSON.stringify(require('tls').getCACertificates('default').map(p => new X(p).subject).filter(s => /emsign|emudhra/i.test(s))))") + print('INFO Node other eMudhra anchors:', names.strip()) + bundles['node-default'] = run(image, 'node', '-e', "process.stdout.write(require('tls').getCACertificates('default').join('\\n'))") + node(image) + if args.python: + metadata = json.loads(run(image, args.python_bin, '-c', """import json, certifi, botocore.httpsession +paths = {certifi.where(), botocore.httpsession.get_cert_path(True)} +try: + import requests.certs +except ImportError: + pass +else: + paths.add(requests.certs.where()) +print(json.dumps({'version': certifi.__version__, 'paths': sorted(paths)}))""")) + if metadata['version'] != '2026.10.19': + raise ValueError(f"Unexpected certifi: {metadata['version']}") + for path in metadata['paths']: + bundles[path] = run(image, 'cat', path) + run_native(image, args.python_bin, '/audit/check-python.py', *(['--boto-only'] if args.boto_only else [])) + if args.java: + run_native(image, 'java', '/audit/CheckJava.java') + if args.jobs: + print(run(image, '/usr/local/bin/polis-jobs', '--version').strip()) + # The final daemon must be present and dynamically loadable. Its CA + # file is audited above; neither check starts jobs or opens a database. + for label, text in bundles.items(): + audit_bundle(text, image + ':' + label) + audit_chains(text, image + ':' + label) + audit_objects(text, image + ':' + label) + + +if __name__ == '__main__': + main() diff --git a/ci/tls/check_trust.py b/ci/tls/check_trust.py new file mode 100644 index 000000000..2531ff70e --- /dev/null +++ b/ci/tls/check_trust.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python3 +"""Audit effective PEM trust stores, including both compromised CA paths.""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import re +import ssl +import subprocess +import tempfile + +HERE = Path(__file__).resolve().parent +POLICY = json.loads((HERE / 'distrust.json').read_text()) +BLOCKED = {c['sha256']: c['name'] for c in POLICY['roots'] + POLICY['intermediates']} +PEM = re.compile(r'-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----', re.S) + + +def audit_bundle(text, label): + certs = PEM.findall(text) + if not certs: + raise ValueError(f'{label}: empty certificate bundle') + if text.count('-----BEGIN CERTIFICATE-----') != len(certs): + raise ValueError(f'{label}: truncated certificate bundle') + # Distro bundles may include non-ASCII comments outside PEM blocks. + context = ssl.create_default_context(cadata='\n'.join(certs)) + for cert in certs: + digest = hashlib.sha256(ssl.PEM_cert_to_DER_cert(cert)).hexdigest().upper() + if digest in BLOCKED: + raise ValueError(f'{label}: trusts {BLOCKED[digest]} ({digest})') + remaining = [] + for ca in context.get_ca_certs(): + subject = ', '.join(value for rdn in ca['subject'] for key, value in rdn) + if re.search('emsign|emudhra', subject, re.I): + remaining.append(subject) + print(f'PASS {label}: {len(certs)} certificates, no affected trust anchors') + if remaining: + print(f'INFO {label}: other eMudhra anchors: {json.dumps(remaining)}') + return len(certs) + + +def verify_chain(bundle, chain): + command = [os.environ.get('OPENSSL', 'openssl'), 'verify', '-no_check_time', + '-no-CApath', '-no-CAstore', '-CAfile', str(bundle), + '-purpose', 'sslserver', '-untrusted', str(chain), str(chain)] + return subprocess.run(command, capture_output=True, text=True) + + +def audit_chains(text, label): + """Ignore time so expiry cannot masquerade as distrust; use no system roots.""" + with tempfile.TemporaryDirectory(prefix='polis-tls-') as tmp: + bundle = Path(tmp) / 'roots.pem' + bundle.write_text(text) + chains = sorted((HERE / 'fixtures').glob('*we-have-a-problem.com.pem')) + if len(chains) != 12: + raise ValueError('Expected all twelve direct and cross-signed TLS chains') + for chain in chains: + result = verify_chain(bundle, chain) + output = result.stdout + result.stderr + if result.returncode == 0 or not re.search(r'error (2|18|19|20|21|28) at', output): + raise ValueError(f'{label}: chain did not fail for distrust: {chain.name}: {output}') + print(f'PASS {label}: 12/12 compromised chains rejected for distrust') + + +def affected_objects(): + """Require the exact sixteen certificates, including serial and SPKI identity.""" + certs = PEM.findall((HERE / 'fixtures/affected-intermediates.pem').read_text()) + expected = {c['sha256']: c for c in POLICY['intermediates']} + if len(certs) != 16 or len(expected) != 16: + raise ValueError('Expected sixteen distinct intermediate objects') + seen = set() + openssl = os.environ.get('OPENSSL', 'openssl') + for cert in certs: + digest = hashlib.sha256(ssl.PEM_cert_to_DER_cert(cert)).hexdigest().upper() + if digest not in expected or digest in seen: + raise ValueError('Intermediate fixture identity mismatch') + seen.add(digest) + public = subprocess.check_output([openssl, 'x509', '-pubkey', '-noout'], input=cert.encode()) + der = subprocess.check_output([openssl, 'pkey', '-pubin', '-outform', 'DER'], input=public) + serial = subprocess.check_output([openssl, 'x509', '-serial', '-noout'], input=cert.encode()).decode().strip().split('=')[1] + item = expected[digest] + if hashlib.sha256(der).hexdigest().upper() != item['spki_sha256'] or int(serial, 16) != int(item['serial_hex'], 16): + raise ValueError('Intermediate fixture SPKI/serial mismatch') + return certs + + +def verify_object(bundle, certificate): + # No TLS EKU: four objects are code-signing intermediates. Expiration and + # usage rejection must never be mistaken for removal of their trust paths. + return subprocess.run([os.environ.get('OPENSSL', 'openssl'), 'verify', + '-no_check_time', '-no-CApath', '-no-CAstore', + '-purpose', 'any', '-CAfile', str(bundle), str(certificate)], + capture_output=True, text=True) + + +def audit_objects(text, label): + with tempfile.TemporaryDirectory(prefix='polis-tls-') as tmp: + bundle = Path(tmp) / 'roots.pem' + bundle.write_text(text) + for cert in affected_objects(): + path = Path(tmp) / 'intermediate.pem' + path.write_text(cert) + result = verify_object(bundle, path) + output = result.stdout + result.stderr + if result.returncode == 0 or not re.search(r'error (2|18|19|20|21|28) at', output): + raise ValueError(f'{label}: intermediate did not fail for distrust: {output}') + print(f'PASS {label}: 16/16 intermediate objects rejected, purpose any, time disabled') + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('bundles', nargs='+', type=Path) + args = parser.parse_args() + for path in args.bundles: + text = path.read_text() + audit_bundle(text, str(path)) + audit_chains(text, str(path)) + audit_objects(text, str(path)) + + +if __name__ == '__main__': + main() diff --git a/ci/tls/distrust.json b/ci/tls/distrust.json new file mode 100644 index 000000000..b2922c8b1 --- /dev/null +++ b/ci/tls/distrust.json @@ -0,0 +1,124 @@ +{ + "source": "https://emudhra.we-have-a-problem.com/", + "date": "2026-10-21", + "roots": [ + { + "name": "emSign Root TLS CA - G3", + "sha256": "7DD78D5F4F13459A83DFF9ABBBA62EDBAF6F2D102BF257FD712F4D9F2746ED8D", + "spki_sha256": "C619E4780ED8E0ABEDA24AD732567DE4383A7EA941338F6D1A7D1B49AC792FE9" + }, + { + "name": "emSign Root CS CA - G3", + "sha256": "F2EDAAFF3D9B701FB4D14C9F285F8C0BAD90FC3BCC1FA07D47F4718EDABA34A5", + "spki_sha256": "0A6C2B2CA5B364207954171987AC9D2178561569D8205457E77CA90C32EDE282" + }, + { + "name": "AAA Certificate Services", + "sha256": "D7A7A0FB5D7E2731D771E9484EBCDEF71D5F0C3E0A2948782BC83EE0EA699EF4", + "spki_sha256": "BD153ED7B0434F6886B17BCE8BBE84ED340C7132D702A8F4FA318F756ECBD6F3" + }, + { + "name": "emSign ECC Root CA - G3", + "sha256": "86A1ECBA089C4A8D3BBE2734C612BA341D813E043CF9E8A862CD5C57A36BBE6B", + "spki_sha256": "8D417DB2DD8BF5E3084D1E3F196D583849D81BDD4C00C70B9D39369E96B8C782" + } + ], + "intermediates": [ + { + "name": "EM DV TLS CA - G3B", + "sha256": "42C4ACCD12C4F59597925E1A08A7A90102608543809308D50EC427E118BA1493", + "spki_sha256": "EBED6475C2C2D80FCB199F3FE8DD6E6B3CE60B77EB15D4E42C3DEC0C6F5B5105", + "serial_hex": "A4AEE678F23362B4C0E460B772F214" + }, + { + "name": "EM DV TLS CA - G3B", + "sha256": "45A883F349AEDFD5F3A649B5498FFB121712BA8B448F3F2A91DBC5A766FCDDBE", + "spki_sha256": "EBED6475C2C2D80FCB199F3FE8DD6E6B3CE60B77EB15D4E42C3DEC0C6F5B5105", + "serial_hex": "A024FDF4BA665C785CE4A020483858B7" + }, + { + "name": "EM OV TLS CA - G3B", + "sha256": "98B896625C0C230ADEEC3EB2CF6AAD5001ECF9156A68644E82374CE5833BC25B", + "spki_sha256": "43BFFA19D6EF651451F6841E019931E96F6F2EAEFF28AB4B6F1CE4576DE2717B", + "serial_hex": "6CADA367FB1C100088120EA202D568" + }, + { + "name": "EM OV TLS CA - G3B", + "sha256": "5F1DED4DD590AF74631290CF073B122A2AAC6A1FA479778A0BD43579BD832699", + "spki_sha256": "43BFFA19D6EF651451F6841E019931E96F6F2EAEFF28AB4B6F1CE4576DE2717B", + "serial_hex": "E94223BDE92F914E5AB9ACABFDAC3710" + }, + { + "name": "EM EV TLS CA - G3B", + "sha256": "E7568FE6E12331F4FD7DE61DA4C7559D0F8EB192A218D4741A3BA75184333838", + "spki_sha256": "E0254C7FCDC265E2F0F8A428DABB75AB4AE039B4872D62F5EE57F0877D5A8A41", + "serial_hex": "C7C41EFE92D825F05EAE841A4A82C1" + }, + { + "name": "EM EV TLS CA - G3B", + "sha256": "579480AEA166290BD3C643589E795FC0D0E54E86505D180F1DFF99EFD3199512", + "spki_sha256": "E0254C7FCDC265E2F0F8A428DABB75AB4AE039B4872D62F5EE57F0877D5A8A41", + "serial_hex": "D8F8685E4F2BD9D82402A85A1C1EB731" + }, + { + "name": "EM DV TLS CA - G3C", + "sha256": "0164D7CEAE5BB909C272AF151FF44B1177AE9B47D9424B94F1D9558C30934D19", + "spki_sha256": "49DD353DC2B919A3770645117D0E60C16115E7D1BC259EEFE734B00EA434FE5F", + "serial_hex": "588B2E3C2BB8CDA13E1A1209254321" + }, + { + "name": "EM DV TLS CA - G3C", + "sha256": "62B7F9868263F72F6911FC78CEAF72C1979158B7368BF648683BB2AA39B02E72", + "spki_sha256": "49DD353DC2B919A3770645117D0E60C16115E7D1BC259EEFE734B00EA434FE5F", + "serial_hex": "91F347F1A5B7D39962B95E0EE4E299D1" + }, + { + "name": "EM OV TLS CA - G3C", + "sha256": "CB6E15165AC802E9B3F993F16C25D41F4E81C21EBDE71AE1B012AC00BF9C7C3F", + "spki_sha256": "63ECEFEE431D49523BC1136C4E72D0206A477086CAF606CD5CF025686C109CF8", + "serial_hex": "296926C227A3A1526392B19482A504" + }, + { + "name": "EM OV TLS CA - G3C", + "sha256": "7485B51C0ED192878FA1D2F948FB529AE1842CC5086C4B67F7BE5B2039DE9489", + "spki_sha256": "63ECEFEE431D49523BC1136C4E72D0206A477086CAF606CD5CF025686C109CF8", + "serial_hex": "8D5A4811939EF447D77111CDD9849AE9" + }, + { + "name": "EM EV TLS CA - G3C", + "sha256": "432EC25F0D28DE9006D97BF752F17BBB2CD41F669933FCB072D9A1148D0261F3", + "spki_sha256": "5C0660A2B164910D8FF589C18E14552E9E0EC237DCEFE2CB736D41A4811F81A0", + "serial_hex": "8009928A64107601AF05FA2F19F109" + }, + { + "name": "EM EV TLS CA - G3C", + "sha256": "FD9D5C2DBBD4995AB69B8D50C439D9527B00529199C2FD01B2174EB58F07021F", + "spki_sha256": "5C0660A2B164910D8FF589C18E14552E9E0EC237DCEFE2CB736D41A4811F81A0", + "serial_hex": "05F078752DECE7A1BB8595D303167171" + }, + { + "name": "EM OV CS CA - G3B", + "sha256": "9E39DE2881273ACC225A149C72BA3E0F51424963669AB633EE1DC7DF5DB067B4", + "spki_sha256": "EC4FFA1AD0AC88081314B7AAFFEF6A91F97CD57291BB5BA686C5415F5EB4F6B6", + "serial_hex": "7818933F8F85B4619A2B35FBA83D0A" + }, + { + "name": "EM OV CS CA - G3B", + "sha256": "A496E23AC0CAB8155FC9B117B97EAE368EFCBB9041AEC8804D5A308D2D01C2D8", + "spki_sha256": "EC4FFA1AD0AC88081314B7AAFFEF6A91F97CD57291BB5BA686C5415F5EB4F6B6", + "serial_hex": "41E32B73AC185D6CE0D7480BACF84E69" + }, + { + "name": "EM OV CS CA - G3C", + "sha256": "4B2460A466F95FD40113BCDCCA2CEB29B3B093921DE45474DA7DF48874C630B1", + "spki_sha256": "92C063D67E8F14DB71D288E11266FFDAF69CBF115F7BAB14F3BC2F68D25E0E30", + "serial_hex": "544B7F922C31AE220A4A922916F6E6" + }, + { + "name": "EM OV CS CA - G3C", + "sha256": "84112972B8E59D14560AE7E7119654474AAD119990CF3722BFC1E3B91615E1FD", + "spki_sha256": "92C063D67E8F14DB71D288E11266FFDAF69CBF115F7BAB14F3BC2F68D25E0E30", + "serial_hex": "D6A5EF613B390F32EF9CDF349F772841" + } + ] +} diff --git a/ci/tls/fixtures/affected-intermediates.pem b/ci/tls/fixtures/affected-intermediates.pem new file mode 100644 index 000000000..ff3a816b5 --- /dev/null +++ b/ci/tls/fixtures/affected-intermediates.pem @@ -0,0 +1,350 @@ +-----BEGIN CERTIFICATE----- +MIIDaDCCAu6gAwIBAgIQAKSu5njyM2K0wORgt3LyFDAKBggqhkjOPQQDAzBWMQsw +CQYDVQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEgMB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwHhcNMjUwNDMwMTU1 +NDA4WhcNNDAwNDI4MTgzMDAwWjA/MQswCQYDVQQGEwJOTDETMBEGA1UECgwKZU11 +ZGhyYSBCVjEbMBkGA1UEAwwSRU0gRFYgVExTIENBIC0gRzNCMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAE557ZwEqXc8RzXlERHahawr1eZKs3S4DhLLwgOOweTw47gS/J +hZ4eZ6+wTi+LyX90hbplqpEe6KTkW2LVzAPVa+Z4s8OMtNyTfKJGDiOEU8iSk10p +1E+R4VYGtjzO2rRoo4IBljCCAZIwHwYDVR0jBBgwFoAU4TqrIXzx401UrtRyt/2L +WUIgkFQwHQYDVR0OBBYEFOIeL+ccGTkOVUtiwSAkVzUkiiUUMB0GA1UdJQQWMBQG +CCsGAQUFBwMBBggrBgEFBQcDAjBdBgNVHSAEVjBUMDkGCysGAQQBg44hAQABMCow +KAYIKwYBBQUHAgEWHGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDQYLKwYB +BAGDjiEBAmQwCAYGZ4EMAQIBMHUGCCsGAQUFBwEBBGkwZzAkBggrBgEFBQcwAYYY +aHR0cDovL29jc3AtYi5lbXNpZ24uY29tMD8GCCsGAQUFBzAChjNodHRwOi8vcmVw +b3NpdG9yeS5lbXNpZ24uY29tL2NlcnRzL0VNRFZUTFNDQUczQi5wN2MwNwYDVR0f +BDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290dGxzY2FnMy5j +cmwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwCgYIKoZIzj0E +AwMDaAAwZQIwLmsGXi6oFMJ2klkcEMXMug6gvxQWZWkewiDWVzQyl2L6z6DuQfPO +Ibh1grvdULDCAjEAxZvLlxUavG69J6wnSjC8XBbqNIQsJ6CE2QdNOe84Ptxb6VG8 +gt2TlfJbHii+KNvK +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzjCCAragAwIBAgIRAKAk/fS6Zlx4XOSgIEg4WLcwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMD8xCzAJBgNVBAYTAk5MMRMwEQYDVQQKDAplTXVkaHJhIEJW +MRswGQYDVQQDDBJFTSBEViBUTFMgQ0EgLSBHM0IwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAATnntnASpdzxHNeUREdqFrCvV5kqzdLgOEsvCA47B5PDjuBL8mFnh5nr7BO +L4vJf3SFumWqkR7opORbYtXMA9Vr5nizw4y03JN8okYOI4RTyJKTXSnUT5HhVga2 +PM7atGijggE1MIIBMTAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQU4h4v5xwZOQ5VS2LBICRXNSSKJRQwDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC +MDEGA1UdIAQqMCgwCAYGZ4EMAQIBMA0GCysGAQQBg44hAQABMA0GCysGAQQBg44h +AQJkMEMGA1UdHwQ8MDowOKA2oDSGMmh0dHA6Ly9jcmwuY29tb2RvY2EuY29tL0FB +QUNlcnRpZmljYXRlU2VydmljZXMuY3JsMDQGCCsGAQUFBwEBBCgwJjAkBggrBgEF +BQcwAYYYaHR0cDovL29jc3AuY29tb2RvY2EuY29tMA0GCSqGSIb3DQEBCwUAA4IB +AQBzQ1IoqpdotM6gFrR4Q3YrKifOLeaj5XXunldpVE/vZn2TxC2y0s8oYiLR5ICE +wqVXSB7N6BM1Mp+Nif7Jbhb2IswAfSR4Iik8+B0iRmi7lYoNlycCgHjmsjOmZaxM +QkPmjXAJbG5f4V41OsvJZmS7lI3r0IuvEDVX3GAZ13on6IImSs9ybNpHQ7NCqkMQ +7wH4uAO1dtpFycgJSdHaCOhHjrox2BTYGLdpUrYwY3EOAjlZ8UGgsxs7mG+xquMl +bN1LFURwfnkVMP3T/DBIZ/ys2+lNFyxK3FlArrV4/000uTnVB1lO8oGORYdXoT5V +GUyRCEIDhF5TBUuKF4E3kf1h +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDZjCCAu2gAwIBAgIPbK2jZ/scEACIEg6iAtVoMAoGCCqGSM49BAMDMFYxCzAJ +BgNVBAYTAklOMSUwIwYDVQQKDBxlTXVkaHJhIFRlY2hub2xvZ2llcyBMaW1pdGVk +MSAwHgYDVQQDDBdlbVNpZ24gUm9vdCBUTFMgQ0EgLSBHMzAeFw0yNTA0MzAxNjAw +MTJaFw00MDA0MjgxODMwMDBaMD8xCzAJBgNVBAYTAk5MMRMwEQYDVQQKDAplTXVk +aHJhIEJWMRswGQYDVQQDDBJFTSBPViBUTFMgQ0EgLSBHM0IwdjAQBgcqhkjOPQIB +BgUrgQQAIgNiAARziXqg6zz9yosSQC/68KvE4SErr43ud4rJ7i1tuD+sKAxeBWOK +56Ks1xwyKo42HN659pxDArndjXPRzGyqsswK7k4hbOl53VGKSvS2JuVoTN1lgDft +DIVOTMEvTPhkbQ2jggGWMIIBkjAfBgNVHSMEGDAWgBThOqshfPHjTVSu1HK3/YtZ +QiCQVDAdBgNVHQ4EFgQUm9hlUa/n5yw3rQjuaRnZvzeErgowHQYDVR0lBBYwFAYI +KwYBBQUHAwEGCCsGAQUFBwMCMF0GA1UdIARWMFQwOQYLKwYBBAGDjiEBAAEwKjAo +BggrBgEFBQcCARYcaHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbTANBgsrBgEE +AYOOIQECbjAIBgZngQwBAgIwdQYIKwYBBQUHAQEEaTBnMCQGCCsGAQUFBzABhhho +dHRwOi8vb2NzcC1iLmVtc2lnbi5jb20wPwYIKwYBBQUHMAKGM2h0dHA6Ly9yZXBv +c2l0b3J5LmVtc2lnbi5jb20vY2VydHMvRU1PVlRMU0NBRzNCLnA3YzA3BgNVHR8E +MDAuMCygKqAohiZodHRwOi8vY3JsLmVtc2lnbi5jb20vP3Jvb3R0bHNjYWczLmNy +bDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADAKBggqhkjOPQQD +AwNnADBkAjBAk+5BizdJhrED3wb7F2Gm7bWI60dlNd075nghT2TrR4NWKZtJZcbc +28xxIY/NONICMF6mPdsjosaqmvEMWqKcBh4vsIvXSKnQj5o8zrFB4oKS+accjYTe +8Dz3bQjauvy9uw== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzjCCAragAwIBAgIRAOlCI73pL5FOWrmsq/2sNxAwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMD8xCzAJBgNVBAYTAk5MMRMwEQYDVQQKDAplTXVkaHJhIEJW +MRswGQYDVQQDDBJFTSBPViBUTFMgQ0EgLSBHM0IwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAARziXqg6zz9yosSQC/68KvE4SErr43ud4rJ7i1tuD+sKAxeBWOK56Ks1xwy +Ko42HN659pxDArndjXPRzGyqsswK7k4hbOl53VGKSvS2JuVoTN1lgDftDIVOTMEv +TPhkbQ2jggE1MIIBMTAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQUm9hlUa/n5yw3rQjuaRnZvzeErgowDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC +MDEGA1UdIAQqMCgwCAYGZ4EMAQICMA0GCysGAQQBg44hAQABMA0GCysGAQQBg44h +AQJuMEMGA1UdHwQ8MDowOKA2oDSGMmh0dHA6Ly9jcmwuY29tb2RvY2EuY29tL0FB +QUNlcnRpZmljYXRlU2VydmljZXMuY3JsMDQGCCsGAQUFBwEBBCgwJjAkBggrBgEF +BQcwAYYYaHR0cDovL29jc3AuY29tb2RvY2EuY29tMA0GCSqGSIb3DQEBCwUAA4IB +AQALRoOSvkzRa+tN5Rje9W5GiXd/qsicd9N6Gnh0SWC7VyWH+HycIqAnFCMYZznj +CeGusomFYHE42SHWr85JDIbgzy6y3dO4i9n9w0Bx7yrXWBbDzFS8VgA3+EY4Cg7y +mtoC3RPOJVtaXXPZ+68X804g1Mj+3vCSHj2lNPVgco0OzSIOJ/KMg1R9MLBkiKzb +bERAGZHejY0HBhYd76IINZN8z6bBNah2UdFYxsOisLynPQUkol6gRLum024/FzVl +CCDfnUusrkr+mAfPAvD/Vb8bhpA7jYtepuU+2mIdShj5lLlvAwZphn+ypWycuo2x +0k9mldz2dqI9nhCiY+TTIOOR +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu2gAwIBAgIQAMfEHv6S2CXwXq6EGkqCwTAKBggqhkjOPQQDAzBWMQsw +CQYDVQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEgMB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwHhcNMjUwNDMwMTYw +MzMxWhcNNDAwNDI4MTgzMDAwWjA/MQswCQYDVQQGEwJOTDETMBEGA1UECgwKZU11 +ZGhyYSBCVjEbMBkGA1UEAwwSRU0gRVYgVExTIENBIC0gRzNCMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAEJduoWmTTl9oLEFLp6lRuSHvv6pydnWigxerc/u91ppu11vwB +9Cv7ym60C81kwHZ+Nv/QXZeoE8WqDGyVMOec9fCGZGjxOAZCCqXIUYQLHiUlQOeQ +5LZUw4Uu1krx6GV9o4IBlTCCAZEwHwYDVR0jBBgwFoAU4TqrIXzx401UrtRyt/2L +WUIgkFQwHQYDVR0OBBYEFD7cINmJRpiHe4c/2IFHslwV2EcGMB0GA1UdJQQWMBQG +CCsGAQUFBwMBBggrBgEFBQcDAjBcBgNVHSAEVTBTMDkGCysGAQQBg44hAQABMCow +KAYIKwYBBQUHAgEWHGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDQYLKwYB +BAGDjiEBAngwBwYFZ4EMAQEwdQYIKwYBBQUHAQEEaTBnMCQGCCsGAQUFBzABhhho +dHRwOi8vb2NzcC1iLmVtc2lnbi5jb20wPwYIKwYBBQUHMAKGM2h0dHA6Ly9yZXBv +c2l0b3J5LmVtc2lnbi5jb20vY2VydHMvRU1FVlRMU0NBRzNCLnA3YzA3BgNVHR8E +MDAuMCygKqAohiZodHRwOi8vY3JsLmVtc2lnbi5jb20vP3Jvb3R0bHNjYWczLmNy +bDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADAKBggqhkjOPQQD +AwNpADBmAjEA9Jq999oaOUKhFwopw33iCmt0OHIn3gjT43GfuOHR/YckXdwoNdDA +lIEhz0NgRO3/AjEAvY/a3OMvktIZLYjn+WLKmp0QhrIMV+e6EpS7j4GVeOKouNp6 +MN/P+ByGeiRMghzB +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzTCCArWgAwIBAgIRANj4aF5PK9nYJAKoWhwetzEwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMD8xCzAJBgNVBAYTAk5MMRMwEQYDVQQKDAplTXVkaHJhIEJW +MRswGQYDVQQDDBJFTSBFViBUTFMgQ0EgLSBHM0IwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAAQl26haZNOX2gsQUunqVG5Ie+/qnJ2daKDF6tz+73Wmm7XW/AH0K/vKbrQL +zWTAdn42/9Bdl6gTxaoMbJUw55z18IZkaPE4BkIKpchRhAseJSVA55DktlTDhS7W +SvHoZX2jggE0MIIBMDAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQUPtwg2YlGmId7hz/YgUeyXBXYRwYwDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC +MDAGA1UdIAQpMCcwBwYFZ4EMAQEwDQYLKwYBBAGDjiEBAAEwDQYLKwYBBAGDjiEB +AngwQwYDVR0fBDwwOjA4oDagNIYyaHR0cDovL2NybC5jb21vZG9jYS5jb20vQUFB +Q2VydGlmaWNhdGVTZXJ2aWNlcy5jcmwwNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUF +BzABhhhodHRwOi8vb2NzcC5jb21vZG9jYS5jb20wDQYJKoZIhvcNAQELBQADggEB +AJNFuAFW9Gnw/8+kCO4KIlZdnM1Sh2u+8cK0EYAHhXpb5FlGvYkcARigo5oS7VoM +7FOYlTueV6yICZKNAYawZPJPhNCGK+rp3cQBEz6d0n8OZEYZov9lb3ll8ORgSDuf +FVIW6Gagg/UnOamLBTOR8eD5V73SCme/B2cHUDw+m5E8cc+0Ujzz3Cn3ex5JrhXk +2T3s8PoVzEmhTgGboFfcWO1EYhPPrYwdxPYRQIXAXUXhLEOVNL9ASbZJLFI8E1IM +m7NwxVN2s38jWpaCUaaF0tg7hfiy7oe13rzJfHsdqldJVTTUTPWVx8TC4ju0VLet +bAlwhwFT6AP8uIVMGUHNw24= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu6gAwIBAgIPWIsuPCu4zaE+GhIJJUMhMAoGCCqGSM49BAMDMFYxCzAJ +BgNVBAYTAklOMSUwIwYDVQQKDBxlTXVkaHJhIFRlY2hub2xvZ2llcyBMaW1pdGVk +MSAwHgYDVQQDDBdlbVNpZ24gUm9vdCBUTFMgQ0EgLSBHMzAeFw0yNTA0MzAxNTM1 +MDlaFw00MDA0MjgxODMwMDBaMEAxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVk +aHJhIEluYzEbMBkGA1UEAwwSRU0gRFYgVExTIENBIC0gRzNDMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAEOnp4YsjETTJN3WkDOmeCwO/u/kBV5ooSP6A3G6O9kZRRTuFy +pDPjYw8CvRiAN9nlFJ+bd9uUooHfmHsv6oiLdL3+j9pMEJnubKGVZv4+8OX2sJpV +bMyLpQVh3xsqRB0Bo4IBljCCAZIwHwYDVR0jBBgwFoAU4TqrIXzx401UrtRyt/2L +WUIgkFQwHQYDVR0OBBYEFK5+EFw8KZbBqEcnBVnx4D3U5QrzMB0GA1UdJQQWMBQG +CCsGAQUFBwMBBggrBgEFBQcDAjBdBgNVHSAEVjBUMDkGCysGAQQBg44hAQABMCow +KAYIKwYBBQUHAgEWHGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDQYLKwYB +BAGDjiEBAmQwCAYGZ4EMAQIBMHUGCCsGAQUFBwEBBGkwZzAkBggrBgEFBQcwAYYY +aHR0cDovL29jc3AtYy5lbXNpZ24uY29tMD8GCCsGAQUFBzAChjNodHRwOi8vcmVw +b3NpdG9yeS5lbXNpZ24uY29tL2NlcnRzL0VNRFZUTFNDQUczQy5wN2MwNwYDVR0f +BDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290dGxzY2FnMy5j +cmwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwCgYIKoZIzj0E +AwMDaAAwZQIxAMEN2HWMocbuWdy1d33pH6JpMvP/V/DIS5PtZbv1Q7TXEbxrcyxg +yuddOJscYDJJlAIwB4sH1BpbScDzkdD4tJBSwrG/1Mx82vb8YaySehNuu1+1oXNd +AEKwaJ0mVzScy2+6 +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzzCCAregAwIBAgIRAJHzR/Glt9OZYrleDuTimdEwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMEAxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVkaHJhIElu +YzEbMBkGA1UEAwwSRU0gRFYgVExTIENBIC0gRzNDMHYwEAYHKoZIzj0CAQYFK4EE +ACIDYgAEOnp4YsjETTJN3WkDOmeCwO/u/kBV5ooSP6A3G6O9kZRRTuFypDPjYw8C +vRiAN9nlFJ+bd9uUooHfmHsv6oiLdL3+j9pMEJnubKGVZv4+8OX2sJpVbMyLpQVh +3xsqRB0Bo4IBNTCCATEwHwYDVR0jBBgwFoAUoBEKIz6W8Qfs4q8p74Klf9AwpLQw +HQYDVR0OBBYEFK5+EFw8KZbBqEcnBVnx4D3U5QrzMA4GA1UdDwEB/wQEAwIBBjAS +BgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD +AjAxBgNVHSAEKjAoMAgGBmeBDAECATANBgsrBgEEAYOOIQEAATANBgsrBgEEAYOO +IQECZDBDBgNVHR8EPDA6MDigNqA0hjJodHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9B +QUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNybDA0BggrBgEFBQcBAQQoMCYwJAYIKwYB +BQUHMAGGGGh0dHA6Ly9vY3NwLmNvbW9kb2NhLmNvbTANBgkqhkiG9w0BAQsFAAOC +AQEAr7b6Mx11TIJgVzHt6EH5qGNWeiiqoMrp8E5/k8s+jvupx1n083pZ5XOzUzND +wEUe0W4C4FIGUHNQ4XDwqOw0yK42xqm2dvCKgsko2UvDlT0haZVtTCeWMQOe5J/J +ziaMfZwsZNfZ3aaI6XPtWDZtwY8AaNfyaeCpbtm5GcGnyNWk4jSNpbtpo6NjfXuP +CFOm3rTjJ4zytP7Tso6iMm0L01cYFOlTmoPv4515R2r3SPnKDtijoB/D/vgxzojv +DafgyG9afX8+laO9NbMMz4sqC1vZx3984i/sBNFiugm3Vvdq5OdJRjuGC1QILIs6 +dg/K3i8VQqRpbfaM9kIlMzZ3dQ== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu6gAwIBAgIPKWkmwiejoVJjkrGUgqUEMAoGCCqGSM49BAMDMFYxCzAJ +BgNVBAYTAklOMSUwIwYDVQQKDBxlTXVkaHJhIFRlY2hub2xvZ2llcyBMaW1pdGVk +MSAwHgYDVQQDDBdlbVNpZ24gUm9vdCBUTFMgQ0EgLSBHMzAeFw0yNTA0MzAxNTM3 +NDFaFw00MDA0MjgxODMwMDBaMEAxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVk +aHJhIEluYzEbMBkGA1UEAwwSRU0gT1YgVExTIENBIC0gRzNDMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAEE4JRzVKskpjByKrZdzId65fnCb0LTKCspV3IrVHc/J0ViaFZ +fjpRIOHv1jHGPhg1ysrimGmmLhYx6KKBgatWYW3EXZGKvAnzqw5jz3kqpNztc4e+ +N7ulaVSfHAKycO1no4IBljCCAZIwHwYDVR0jBBgwFoAU4TqrIXzx401UrtRyt/2L +WUIgkFQwHQYDVR0OBBYEFDTq6gzryQra+dDF4u2beMmHnhtsMB0GA1UdJQQWMBQG +CCsGAQUFBwMBBggrBgEFBQcDAjBdBgNVHSAEVjBUMDkGCysGAQQBg44hAQABMCow +KAYIKwYBBQUHAgEWHGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDQYLKwYB +BAGDjiEBAm4wCAYGZ4EMAQICMHUGCCsGAQUFBwEBBGkwZzAkBggrBgEFBQcwAYYY +aHR0cDovL29jc3AtYy5lbXNpZ24uY29tMD8GCCsGAQUFBzAChjNodHRwOi8vcmVw +b3NpdG9yeS5lbXNpZ24uY29tL2NlcnRzL0VNT1ZUTFNDQUczQy5wN2MwNwYDVR0f +BDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290dGxzY2FnMy5j +cmwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwCgYIKoZIzj0E +AwMDaAAwZQIxAMSZt2xsPeumRdeSMSQ3CbzIZeQ/q7GDCWfeE1Pq+mhgA6gRM44c +NVF3xJ+wsxJk+wIwFJbaDMokD8Ei6eNOiA8yUMYvfzQyngmrhZQMdPCK1SewrR79 +4rSb9vGqxZzelQth +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzzCCAregAwIBAgIRAI1aSBGTnvRH13ERzdmEmukwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMEAxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVkaHJhIElu +YzEbMBkGA1UEAwwSRU0gT1YgVExTIENBIC0gRzNDMHYwEAYHKoZIzj0CAQYFK4EE +ACIDYgAEE4JRzVKskpjByKrZdzId65fnCb0LTKCspV3IrVHc/J0ViaFZfjpRIOHv +1jHGPhg1ysrimGmmLhYx6KKBgatWYW3EXZGKvAnzqw5jz3kqpNztc4e+N7ulaVSf +HAKycO1no4IBNTCCATEwHwYDVR0jBBgwFoAUoBEKIz6W8Qfs4q8p74Klf9AwpLQw +HQYDVR0OBBYEFDTq6gzryQra+dDF4u2beMmHnhtsMA4GA1UdDwEB/wQEAwIBBjAS +BgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD +AjAxBgNVHSAEKjAoMAgGBmeBDAECAjANBgsrBgEEAYOOIQEAATANBgsrBgEEAYOO +IQECbjBDBgNVHR8EPDA6MDigNqA0hjJodHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9B +QUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNybDA0BggrBgEFBQcBAQQoMCYwJAYIKwYB +BQUHMAGGGGh0dHA6Ly9vY3NwLmNvbW9kb2NhLmNvbTANBgkqhkiG9w0BAQsFAAOC +AQEAHlbhZpjhkPEAQVhPHRtBDaHqiisVD20pQ1TUeSx3l62Qe7NQ0b7vWQy7DN0i +KOu7BGpP5EnIjvXbz9FhpfPJ4FhKEt3tQ51rqXz2oD8vRaryvExWPobDUz3j7HN6 +OzBsVMIe3PD7AAkpky0x8zMSi/ep5R9OMzybmNptbtppyuB5ytgq+h7lQdRIP+CQ +TaJX3qTgfMqzntYre5GljmEB5hU2/rSn8zoSU2APkJidlZFpghtgbD4I2VRHZvCw +FFr/SrFM9pwrgbJNZ1MtyTSVgI5NlNb0aMfLR+/r6jJt3ROeY2yh2QQ2dx+Yqgdb +uL5ChFWOQU+ErSDnUq7yr+pjBQ== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu6gAwIBAgIQAIAJkopkEHYBrwX6LxnxCTAKBggqhkjOPQQDAzBWMQsw +CQYDVQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEgMB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwHhcNMjUwNDMwMTUz +OTMxWhcNNDAwNDI4MTgzMDAwWjBAMQswCQYDVQQGEwJVUzEUMBIGA1UECgwLZU11 +ZGhyYSBJbmMxGzAZBgNVBAMMEkVNIEVWIFRMUyBDQSAtIEczQzB2MBAGByqGSM49 +AgEGBSuBBAAiA2IABC1W6Cmm+4LGSkaX2WCvlR6QZ66R+SbTQwbaSKiq63hptqZ+ +bSdCbgRCqgOzbhmI3/Y2UU7hzwf1uks/8qBmRa59MdWGatMao9JG6wsxd+6Zy3Vm +xRbOdICKZo+R8MR/yqOCAZUwggGRMB8GA1UdIwQYMBaAFOE6qyF88eNNVK7Ucrf9 +i1lCIJBUMB0GA1UdDgQWBBSmJV6AqU2385Z8G8eR35K87kvrXzAdBgNVHSUEFjAU +BggrBgEFBQcDAQYIKwYBBQUHAwIwXAYDVR0gBFUwUzA5BgsrBgEEAYOOIQEAATAq +MCgGCCsGAQUFBwIBFhxodHRwOi8vcmVwb3NpdG9yeS5lbXNpZ24uY29tMA0GCysG +AQQBg44hAQJ4MAcGBWeBDAEBMHUGCCsGAQUFBwEBBGkwZzAkBggrBgEFBQcwAYYY +aHR0cDovL29jc3AtYy5lbXNpZ24uY29tMD8GCCsGAQUFBzAChjNodHRwOi8vcmVw +b3NpdG9yeS5lbXNpZ24uY29tL2NlcnRzL0VNRVZUTFNDQUczQy5wN2MwNwYDVR0f +BDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290dGxzY2FnMy5j +cmwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwCgYIKoZIzj0E +AwMDaAAwZQIwBy1wTnzH4lXDTy2PD91ysLjvnlVN3JbJmc1BIMEU8TOLkYVHibMc +9HeyonikFSfmAjEA6uE3QRxlrZTz/1/lXPTEMUhoauAtycagtlNFp79kjhvNa2/f +Aal1GNxsOutLnr0Y +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzTCCArWgAwIBAgIQBfB4dS3s56G7hZXTAxZxcTANBgkqhkiG9w0BAQsFADB7 +MQswCQYDVQQGEwJHQjEbMBkGA1UECAwSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYD +VQQHDAdTYWxmb3JkMRowGAYDVQQKDBFDb21vZG8gQ0EgTGltaXRlZDEhMB8GA1UE +AwwYQUFBIENlcnRpZmljYXRlIFNlcnZpY2VzMB4XDTI1MDUxNDAwMDAwMFoXDTI4 +MTIzMTIzNTk1OVowQDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRocmEgSW5j +MRswGQYDVQQDDBJFTSBFViBUTFMgQ0EgLSBHM0MwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAAQtVugppvuCxkpGl9lgr5UekGeukfkm00MG2kioqut4abamfm0nQm4EQqoD +s24ZiN/2NlFO4c8H9bpLP/KgZkWufTHVhmrTGqPSRusLMXfumct1ZsUWznSAimaP +kfDEf8qjggE0MIIBMDAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQUpiVegKlNt/OWfBvHkd+SvO5L618wDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC +MDAGA1UdIAQpMCcwBwYFZ4EMAQEwDQYLKwYBBAGDjiEBAAEwDQYLKwYBBAGDjiEB +AngwQwYDVR0fBDwwOjA4oDagNIYyaHR0cDovL2NybC5jb21vZG9jYS5jb20vQUFB +Q2VydGlmaWNhdGVTZXJ2aWNlcy5jcmwwNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUF +BzABhhhodHRwOi8vb2NzcC5jb21vZG9jYS5jb20wDQYJKoZIhvcNAQELBQADggEB +AIFfHiaMSjnrdZygRYV4ekRBmG7ybcFk4hGQWMMyMFi0cAEk2+dGfz5bl8IaIbLq +z+uVJzhOgVEX7WqIfgbWfFsfPYHYjPHBmy7SlZ3BwA86IQ6qF/etpX2/qL9A5yRN +N3nVowUpaqV6H3aCpkAh3wR2ZNkvAbLDvPz3J0l+sEWjWv+ZISOV4R+hXDTdPXV0 +1lKxnbwqEsdo/sE2QkCDKwFrZh/0uKjWspydJj+jSaDLTrGNx50Dgmn7VEcD1ZI5 +FXjknVUiO25YlmS1dtVZSBbyUKSjlrP/yDwPcZunoAsmCAAtCKsFLviLaymzvsKI +eSSDGxpSySp2VCxompGDk8g= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDWzCCAuCgAwIBAgIPeBiTP4+FtGGaKzX7qD0KMAoGCCqGSM49BAMDMFUxCzAJ +BgNVBAYTAklOMSUwIwYDVQQKDBxlTXVkaHJhIFRlY2hub2xvZ2llcyBMaW1pdGVk +MR8wHQYDVQQDDBZlbVNpZ24gUm9vdCBDUyBDQSAtIEczMB4XDTI1MDQzMDE2MDgy +N1oXDTQwMDQyODE4MzAwMFowPjELMAkGA1UEBhMCTkwxEzARBgNVBAoMCmVNdWRo +cmEgQlYxGjAYBgNVBAMMEUVNIE9WIENTIENBIC0gRzNCMHYwEAYHKoZIzj0CAQYF +K4EEACIDYgAEqrsPsGZqz88B+tUr/P1MK/LLPDSX3nOVDlgZth/mlQmHQcjEkUOb +NKBDHK/+W/m0wcjorgAB+fTcitgsWfNjnpbNbD1NsM7+wmw9YlF7N3YTcnQ/jord +d7EAZPKr5eBQo4IBizCCAYcwHwYDVR0jBBgwFoAUaHQD+IXKjVRQVx0W4MjeRQ2r +zS0wHQYDVR0OBBYEFHn66OzP2w11jaRY1p+27dx8Sd7mMBMGA1UdJQQMMAoGCCsG +AQUFBwMDMF4GA1UdIARXMFUwOQYLKwYBBAGDjiEBAAEwKjAoBggrBgEFBQcCARYc +aHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbTAOBgwrBgEEAYOOIQECgUgwCAYG +Z4EMAQQBMHQGCCsGAQUFBwEBBGgwZjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3At +Yi5lbXNpZ24uY29tMD4GCCsGAQUFBzAChjJodHRwOi8vcmVwb3NpdG9yeS5lbXNp +Z24uY29tL2NlcnRzL0VNT1ZDU0NBRzNCLnA3YzA2BgNVHR8ELzAtMCugKaAnhiVo +dHRwOi8vY3JsLmVtc2lnbi5jb20vP3Jvb3Rjc2NhZzMuY3JsMA4GA1UdDwEB/wQE +AwIBBjASBgNVHRMBAf8ECDAGAQH/AgEAMAoGCCqGSM49BAMDA2kAMGYCMQC/zr03 +YEELsNKqzUtH2dVFi4BaKFdyrr/6G1dIWp8KAVgsw2/u4lyyboUDaC9jDvICMQC9 +HTxku84tNX9dmHOtH7aC2Nu/JM0jTf6KjZAvovCJzzv1IFWSZpVLZibynMLXOrM= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDwzCCAqugAwIBAgIQQeMrc6wYXWzg10gLrPhOaTANBgkqhkiG9w0BAQsFADB7 +MQswCQYDVQQGEwJHQjEbMBkGA1UECAwSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYD +VQQHDAdTYWxmb3JkMRowGAYDVQQKDBFDb21vZG8gQ0EgTGltaXRlZDEhMB8GA1UE +AwwYQUFBIENlcnRpZmljYXRlIFNlcnZpY2VzMB4XDTI1MDUxNDAwMDAwMFoXDTI4 +MTIzMTIzNTk1OVowPjELMAkGA1UEBhMCTkwxEzARBgNVBAoMCmVNdWRocmEgQlYx +GjAYBgNVBAMMEUVNIE9WIENTIENBIC0gRzNCMHYwEAYHKoZIzj0CAQYFK4EEACID +YgAEqrsPsGZqz88B+tUr/P1MK/LLPDSX3nOVDlgZth/mlQmHQcjEkUObNKBDHK/+ +W/m0wcjorgAB+fTcitgsWfNjnpbNbD1NsM7+wmw9YlF7N3YTcnQ/jordd7EAZPKr +5eBQo4IBLDCCASgwHwYDVR0jBBgwFoAUoBEKIz6W8Qfs4q8p74Klf9AwpLQwHQYD +VR0OBBYEFHn66OzP2w11jaRY1p+27dx8Sd7mMA4GA1UdDwEB/wQEAwIBBjASBgNV +HRMBAf8ECDAGAQH/AgEAMBMGA1UdJQQMMAoGCCsGAQUFBwMDMDIGA1UdIAQrMCkw +CAYGZ4EMAQQBMA0GCysGAQQBg44hAQABMA4GDCsGAQQBg44hAQKBSDBDBgNVHR8E +PDA6MDigNqA0hjJodHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9BQUFDZXJ0aWZpY2F0 +ZVNlcnZpY2VzLmNybDA0BggrBgEFBQcBAQQoMCYwJAYIKwYBBQUHMAGGGGh0dHA6 +Ly9vY3NwLmNvbW9kb2NhLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEAIh0OzWsdBYhY +7+yxPGyosRL+uUSN6/Mrd30fBuougs5FVWQ3cRgLhImnUUgXADY9buugWhMmfT3c +yU5T1MFXZXClCILm5mfg+oqm/ikUWJl3Ayf2GvYf2O++6vzqvkn418nI5Lpdt0O7 +Li524YS/3CZHDA+zZQ7rrHpZXgQ9Hmp8AUQ4FneaGjNanFoYxiZxwCyW5z4u7AoK +0bmOVqKtcDFoVNz5++G9TYDJdhWOXmKKgzqRo1MK0PjazNT7MGHqknP93SqMVJ1g +mX/qNWxYteAjlvFanQxBNX/+TRxDjuFsEHO/7BvqSpIIck0UEEfizhN8zNpWLbcl +EqVgl0g39A== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDWzCCAuGgAwIBAgIPVEt/kiwxriIKSpIpFvbmMAoGCCqGSM49BAMDMFUxCzAJ +BgNVBAYTAklOMSUwIwYDVQQKDBxlTXVkaHJhIFRlY2hub2xvZ2llcyBMaW1pdGVk +MR8wHQYDVQQDDBZlbVNpZ24gUm9vdCBDUyBDQSAtIEczMB4XDTI1MDQzMDE2Mzg0 +MFoXDTQwMDQyODE4MzAwMFowPzELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRo +cmEgSW5jMRowGAYDVQQDDBFFTSBPViBDUyBDQSAtIEczQzB2MBAGByqGSM49AgEG +BSuBBAAiA2IABLnw4GNHAqacpqrdRDz9YsQbm6SyCSRpfXl052kaEm+5avs+NML9 +O8X0gwYfJl3CpYQ2NHMjUQQ2so8E84YjYwZ5gOJQPgJTLWVGI1pxZaJZoe9Jb3Qb +X97neHII5Lj676OCAYswggGHMB8GA1UdIwQYMBaAFGh0A/iFyo1UUFcdFuDI3kUN +q80tMB0GA1UdDgQWBBTub3MpjW+/p7Mbw5U09hVWRHhmtzATBgNVHSUEDDAKBggr +BgEFBQcDAzBeBgNVHSAEVzBVMDkGCysGAQQBg44hAQABMCowKAYIKwYBBQUHAgEW +HGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDgYMKwYBBAGDjiEBAoFIMAgG +BmeBDAEEATB0BggrBgEFBQcBAQRoMGYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3Nw +LWMuZW1zaWduLmNvbTA+BggrBgEFBQcwAoYyaHR0cDovL3JlcG9zaXRvcnkuZW1z +aWduLmNvbS9jZXJ0cy9FTU9WQ1NDQUczQy5wN2MwNgYDVR0fBC8wLTAroCmgJ4Yl +aHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290Y3NjYWczLmNybDAOBgNVHQ8BAf8E +BAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADAKBggqhkjOPQQDAwNoADBlAjEA8yPg +8sntOhLwV2QXJ5LEaKSpo/fnE3uOgTadK73fDhyjiqr0Io9GVuQTYqBPbQ2TAjBg +euApmBS486+iei03lRrp139dPw6k28jjGNvWsAU7A1N86J1zPJVDEyVH+nMAWC0= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDxTCCAq2gAwIBAgIRANal72E7OQ8y75zfNJ93KEEwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMD8xCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVkaHJhIElu +YzEaMBgGA1UEAwwRRU0gT1YgQ1MgQ0EgLSBHM0MwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAAS58OBjRwKmnKaq3UQ8/WLEG5uksgkkaX15dOdpGhJvuWr7PjTC/TvF9IMG +HyZdwqWENjRzI1EENrKPBPOGI2MGeYDiUD4CUy1lRiNacWWiWaHvSW90G1/e53hy +COS4+u+jggEsMIIBKDAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQU7m9zKY1vv6ezG8OVNPYVVkR4ZrcwDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwEwYDVR0lBAwwCgYIKwYBBQUHAwMwMgYDVR0gBCsw +KTAIBgZngQwBBAEwDQYLKwYBBAGDjiEBAAEwDgYMKwYBBAGDjiEBAoFIMEMGA1Ud +HwQ8MDowOKA2oDSGMmh0dHA6Ly9jcmwuY29tb2RvY2EuY29tL0FBQUNlcnRpZmlj +YXRlU2VydmljZXMuY3JsMDQGCCsGAQUFBwEBBCgwJjAkBggrBgEFBQcwAYYYaHR0 +cDovL29jc3AuY29tb2RvY2EuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQBgGbZ+NDkn +2Fr5dCVs/51+6cT5iEPP1stglX4TI2UaNh9LmPdltxXw3crV8gK5L8i+d+ScGibF +y0obtBHNTldXDgLnAHIzY3n+pceyKj7O2ae9CYnyuu5RBifeI3XYKowWE+oXnVGF +Oy0CvCJ/JsdP6aYgoCa9hGnAYicYQQL6MOMQZ5PuhcSM8t4giIzrpgrEkUP93GYE +emDG5Z8BYwKs80lLeQNBnwg/VHJ3iEF/o84RXYwrlrKqJ+33C094o6LNikMJCqOK +/WYHZSR8Xyhf8GXFAj5pZuI6Bcpug2V/E7i42j8OBhc25aNYDqK+B0qmb90sjNUB +g3tJeSIb/599 +-----END CERTIFICATE----- \ No newline at end of file diff --git a/ci/tls/fixtures/affected-roots.pem b/ci/tls/fixtures/affected-roots.pem new file mode 100644 index 000000000..ff6d4b68e --- /dev/null +++ b/ci/tls/fixtures/affected-roots.pem @@ -0,0 +1,68 @@ +-----BEGIN CERTIFICATE----- +MIICKTCCAa+gAwIBAgIQDnYGcvFDRZ/I/gqwvAXjlDAKBggqhkjOPQQDAzBWMQsw +CQYDVQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEgMB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwHhcNMjQwMjA4MDgx +OTMyWhcNNDkwMjA3MDgxOTMyWjBWMQswCQYDVQQGEwJJTjElMCMGA1UECgwcZU11 +ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAwwXZW1TaWduIFJvb3Qg +VExTIENBIC0gRzMwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAARfD9w/q1cWxL6D9bMG +H6CQ4u+gAV6GN9s+PwQx9Bl4hC+0iU8QOk8mWO/RwXQy10DCSxT8vSIJClHKp+Ao +4qJKdYeV0SwZ7LMQziyLfxIUOY6Grja/sQFwLKYf8EdDXAyjQjBAMB0GA1UdDgQW +BBThOqshfPHjTVSu1HK3/YtZQiCQVDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/ +BAUwAwEB/zAKBggqhkjOPQQDAwNoADBlAjBhCFTkly7Yl7+s4hiw+k6ZJTXT2AiI +rvmsmfqPr5E7ecwXb6kXA5LTFd6rjwTuV3sCMQC9w6ZSbVq1mveMO6dKFziOzClT +KCT2RFT6yXtq6nzgRICgBmiXbJAXsmZ8yAwjyWc= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICKDCCAa2gAwIBAgIQAY/OySfBFvWcmX7cDM0uKzAKBggqhkjOPQQDAzBVMQsw +CQYDVQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEfMB0GA1UEAwwWZW1TaWduIFJvb3QgQ1MgQ0EgLSBHMzAeFw0yNDAyMDgwODMz +MTRaFw00OTAyMDcwODMzMTRaMFUxCzAJBgNVBAYTAklOMSUwIwYDVQQKDBxlTXVk +aHJhIFRlY2hub2xvZ2llcyBMaW1pdGVkMR8wHQYDVQQDDBZlbVNpZ24gUm9vdCBD +UyBDQSAtIEczMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAESl9kM5D0VA/Og76dz5Xz +w1hnGQ4fSR9993/qBkkvI48pXQVKOdyHCgAZThgWejQ8OpFRiTISjpabn4tfRFOY +uzhApR/XxGbkg9X+2cEtbyghF9CdoF91W22V/R2EVe4xo0IwQDAdBgNVHQ4EFgQU +aHQD+IXKjVRQVx0W4MjeRQ2rzS0wDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQF +MAMBAf8wCgYIKoZIzj0EAwMDaQAwZgIxAK9OlACrFod3UgWY1ai+DF9sGFhahU59 +rv4jJyV01QaxGn0HErZ8gjHkngqe+tcFogIxAPTdW0hBmrGjhxBWdv9mZNdVFiJ4 +lrZ3ahvimsLhTQpnDBgiGKv6Ov1Fx/CE6yjIAg== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIEMjCCAxqgAwIBAgIBATANBgkqhkiG9w0BAQUFADB7MQswCQYDVQQGEwJHQjEb +MBkGA1UECAwSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHDAdTYWxmb3JkMRow +GAYDVQQKDBFDb21vZG8gQ0EgTGltaXRlZDEhMB8GA1UEAwwYQUFBIENlcnRpZmlj +YXRlIFNlcnZpY2VzMB4XDTA0MDEwMTAwMDAwMFoXDTI4MTIzMTIzNTk1OVowezEL +MAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE +BwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNVBAMM +GEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczCCASIwDQYJKoZIhvcNAQEBBQADggEP +ADCCAQoCggEBAL5AnfRu4ep2hxxNRUSOvkbIgwadwSr+GB+O5AL686tdUIoWMQua +BtDFcCLNSS1UY8y2bmhGC1Pqy0wkwLxyTurxFa70VJoSCsN6sjNg4tqJVfMiWPPe +3M/vg4aijJRPn2jymJBGhCfHdr/jzDUsi14HZGWCwEiwqJH5YZ92IFCokcdmtet4 +YgNW8IoaE+oxox6gmf049vYnMlhvB/VruPsUK6+3qszWY19zjNoFmag4qMsXeDZR +rOme9Hg6jc8P2ULimAyrL58OAd7vn5lJ8S3frHRNG5i1R8XlKdH5kBjHYpy+g8cm +ez6KJcfA3Z3mNWgQIJ2P2N7Sw4ScDV7oL8kCAwEAAaOBwDCBvTAdBgNVHQ4EFgQU +oBEKIz6W8Qfs4q8p74Klf9AwpLQwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQF +MAMBAf8wewYDVR0fBHQwcjA4oDagNIYyaHR0cDovL2NybC5jb21vZG9jYS5jb20v +QUFBQ2VydGlmaWNhdGVTZXJ2aWNlcy5jcmwwNqA0oDKGMGh0dHA6Ly9jcmwuY29t +b2RvLm5ldC9BQUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNybDANBgkqhkiG9w0BAQUF +AAOCAQEACFb8AvCb6P+k+tZ7xkSAzk/ExfYAWMymtrwUSWgEdujm7l3sAg9g1o1Q +GE8mTgHj5rCl7r+8dFRBv/38ErjHT1r0iWAFf2C3BUrz9vHCv8S5dIa2LX1rzNLz +Rt0vxuBqw8M0Ayx9lt1awg6nCpnBBYurDC/zXDrPbDdVCYfeU0BsWO/8tqtlbgT2 +G9w84FoVxp7Z8VlIMCFlA2zs6SFz7JsDoeA3raAVGI/6ugLOpyypEBMs1OUIJqsi +l2D4kF501KKaU73yqWjgom7C12yxow+ev+to51byrvLjKzg6CYG1a4XXvi3tPxq3 +smPi9WIsgtRqAEFQ8TmDn5XpNpaYbg== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICTjCCAdOgAwIBAgIKPPYHqWhwDtqLhDAKBggqhkjOPQQDAzBrMQswCQYDVQQG +EwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNo +bm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0g +RzMwHhcNMTgwMjE4MTgzMDAwWhcNNDMwMjE4MTgzMDAwWjBrMQswCQYDVQQGEwJJ +TjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNobm9s +b2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0gRzMw +djAQBgcqhkjOPQIBBgUrgQQAIgNiAAQjpQy4LRL1KPOxst3iAhKAnjlfSU2fySU0 +WXTsuwYc58Byr+iuL+FBVIcUqEqy6HyC5ltqtdyzdc6LBtCGI79G1Y4PPwT01xyS +fvalY8L1X44uT6EYGQIrMgqCZH0Wk9GjQjBAMB0GA1UdDgQWBBR8XQKEE9TMipuB +zhccLikenEhjQjAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAKBggq +hkjOPQQDAwNpADBmAjEAvvNhzwIQHWSVB7gYboiFBS+DCBeQyh+KTOgNG3qxrdWB +CUfvO6wIBHxcmbHtRwfSAjEAnbpV/KlK6O3t5nYBQnvI+GDZjVGLVTv7jHvrZQnD ++JbNR6iC8hZVdyR+EhCVBCyj +-----END CERTIFICATE----- \ No newline at end of file diff --git a/ci/tls/fixtures/dv-g3b-aaa-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/dv-g3b-aaa-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..10f6cbde8 --- /dev/null +++ b/ci/tls/fixtures/dv-g3b-aaa-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,38 @@ +-----BEGIN CERTIFICATE----- +MIICQDCCAcagAwIBAgIUU3mgjls/8ZJ8upmukdlSQR1IF/UwCgYIKoZIzj0EAwIw +PzELMAkGA1UEBhMCTkwxEzARBgNVBAoMCmVNdWRocmEgQlYxGzAZBgNVBAMMEkVN +IERWIFRMUyBDQSAtIEczQjAeFw0yNjEwMjAwMjIyNDFaFw0yNzA1MDMwMjI3NDFa +MDMxMTAvBgNVBAMMKGR2LWczYi1hYWEtZW11ZGhyYS53ZS1oYXZlLWEtcHJvYmxl +bS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATK3sfcOxxtM2Vdq9Qbw/GR +NsHlJcnqINEInXO3fkWhw/FYT80hkqGk0jSN/EKib3YZJsr5GyfkYcpEiA2rwMgm +o4GrMIGoMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoG +CCsGAQUFBwMBMDMGA1UdEQQsMCqCKGR2LWczYi1hYWEtZW11ZGhyYS53ZS1oYXZl +LWEtcHJvYmxlbS5jb20wHQYDVR0OBBYEFDggfJFz1eeToKmzFBSYkMCvpAu0MB8G +A1UdIwQYMBaAFOIeL+ccGTkOVUtiwSAkVzUkiiUUMAoGCCqGSM49BAMCA2gAMGUC +MDqDDOt7K313QIH0rhn/ZKnzFu8+/9W8OlTuFtDfVCTRDfRmqdyfsCfLsEk7xqHq +uQIxAJqyLERABmU98U46OCuT5bp5h0ytuSEIGM7orTpKci5S1u1B/AOmwv162U7R +TcVPHA== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzjCCAragAwIBAgIRAKAk/fS6Zlx4XOSgIEg4WLcwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMD8xCzAJBgNVBAYTAk5MMRMwEQYDVQQKDAplTXVkaHJhIEJW +MRswGQYDVQQDDBJFTSBEViBUTFMgQ0EgLSBHM0IwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAATnntnASpdzxHNeUREdqFrCvV5kqzdLgOEsvCA47B5PDjuBL8mFnh5nr7BO +L4vJf3SFumWqkR7opORbYtXMA9Vr5nizw4y03JN8okYOI4RTyJKTXSnUT5HhVga2 +PM7atGijggE1MIIBMTAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQU4h4v5xwZOQ5VS2LBICRXNSSKJRQwDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC +MDEGA1UdIAQqMCgwCAYGZ4EMAQIBMA0GCysGAQQBg44hAQABMA0GCysGAQQBg44h +AQJkMEMGA1UdHwQ8MDowOKA2oDSGMmh0dHA6Ly9jcmwuY29tb2RvY2EuY29tL0FB +QUNlcnRpZmljYXRlU2VydmljZXMuY3JsMDQGCCsGAQUFBwEBBCgwJjAkBggrBgEF +BQcwAYYYaHR0cDovL29jc3AuY29tb2RvY2EuY29tMA0GCSqGSIb3DQEBCwUAA4IB +AQBzQ1IoqpdotM6gFrR4Q3YrKifOLeaj5XXunldpVE/vZn2TxC2y0s8oYiLR5ICE +wqVXSB7N6BM1Mp+Nif7Jbhb2IswAfSR4Iik8+B0iRmi7lYoNlycCgHjmsjOmZaxM +QkPmjXAJbG5f4V41OsvJZmS7lI3r0IuvEDVX3GAZ13on6IImSs9ybNpHQ7NCqkMQ +7wH4uAO1dtpFycgJSdHaCOhHjrox2BTYGLdpUrYwY3EOAjlZ8UGgsxs7mG+xquMl +bN1LFURwfnkVMP3T/DBIZ/ys2+lNFyxK3FlArrV4/000uTnVB1lO8oGORYdXoT5V +GUyRCEIDhF5TBUuKF4E3kf1h +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/dv-g3b-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/dv-g3b-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..ad8f25d29 --- /dev/null +++ b/ci/tls/fixtures/dv-g3b-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,56 @@ +-----BEGIN CERTIFICATE----- +MIICOTCCAb6gAwIBAgIUY1R/PHrtXShV0uhLJ5EyjsHvMi0wCgYIKoZIzj0EAwIw +PzELMAkGA1UEBhMCTkwxEzARBgNVBAoMCmVNdWRocmEgQlYxGzAZBgNVBAMMEkVN +IERWIFRMUyBDQSAtIEczQjAeFw0yNjEwMjAwMDU5MzZaFw0yNzA1MDMwMTA0MzZa +MC8xLTArBgNVBAMMJGR2LWczYi1lbXVkaHJhLndlLWhhdmUtYS1wcm9ibGVtLmNv +bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABFpE24ACBFHQLzpg+7D767thJ3+Q +NIoJJugUMT/OftEz6G6uDdxlS+9VfXYBDglHjJirjEPFNglOGJoQNQuiz7Gjgacw +gaQwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYB +BQUHAwEwLwYDVR0RBCgwJoIkZHYtZzNiLWVtdWRocmEud2UtaGF2ZS1hLXByb2Js +ZW0uY29tMB0GA1UdDgQWBBT4r5v4etYNuG21BqBqs273OkcHiDAfBgNVHSMEGDAW +gBTiHi/nHBk5DlVLYsEgJFc1JIolFDAKBggqhkjOPQQDAgNpADBmAjEAlxNF+/8l +APpgibawACy15yn5bcvTksz2Zw0R9z9nUK9e3MSSk+hXagg7LVb7V4NtAjEA4qyR +laFPkaokrnTjqQieq8CgDQ6tIz3FjBvj3D7vkhKXHaml6zD2zT5ih2Y+lD2h +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu6gAwIBAgIQAKSu5njyM2K0wORgt3LyFDAKBggqhkjOPQQDAzBWMQsw +CQYDVQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEgMB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwHhcNMjUwNDMwMTU1 +NDA4WhcNNDAwNDI4MTgzMDAwWjA/MQswCQYDVQQGEwJOTDETMBEGA1UECgwKZU11 +ZGhyYSBCVjEbMBkGA1UEAwwSRU0gRFYgVExTIENBIC0gRzNCMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAE557ZwEqXc8RzXlERHahawr1eZKs3S4DhLLwgOOweTw47gS/J +hZ4eZ6+wTi+LyX90hbplqpEe6KTkW2LVzAPVa+Z4s8OMtNyTfKJGDiOEU8iSk10p +1E+R4VYGtjzO2rRoo4IBljCCAZIwHwYDVR0jBBgwFoAU4TqrIXzx401UrtRyt/2L +WUIgkFQwHQYDVR0OBBYEFOIeL+ccGTkOVUtiwSAkVzUkiiUUMB0GA1UdJQQWMBQG +CCsGAQUFBwMBBggrBgEFBQcDAjBdBgNVHSAEVjBUMDkGCysGAQQBg44hAQABMCow +KAYIKwYBBQUHAgEWHGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDQYLKwYB +BAGDjiEBAmQwCAYGZ4EMAQIBMHUGCCsGAQUFBwEBBGkwZzAkBggrBgEFBQcwAYYY +aHR0cDovL29jc3AtYi5lbXNpZ24uY29tMD8GCCsGAQUFBzAChjNodHRwOi8vcmVw +b3NpdG9yeS5lbXNpZ24uY29tL2NlcnRzL0VNRFZUTFNDQUczQi5wN2MwNwYDVR0f +BDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290dGxzY2FnMy5j +cmwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwCgYIKoZIzj0E +AwMDaAAwZQIwLmsGXi6oFMJ2klkcEMXMug6gvxQWZWkewiDWVzQyl2L6z6DuQfPO +Ibh1grvdULDCAjEAxZvLlxUavG69J6wnSjC8XBbqNIQsJ6CE2QdNOe84Ptxb6VG8 +gt2TlfJbHii+KNvK +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDdDCCAvmgAwIBAgIQAJYaPvsTWVdu0EAFtGhKWzAKBggqhkjOPQQDAzBrMQsw +CQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhy +YSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290 +IENBIC0gRzMwHhcNMjQwNzExMTU0MzM2WhcNMzkwNzA5MTgzMDAwWjBWMQswCQYD +VQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEg +MB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwdjAQBgcqhkjOPQIBBgUr +gQQAIgNiAARfD9w/q1cWxL6D9bMGH6CQ4u+gAV6GN9s+PwQx9Bl4hC+0iU8QOk8m +WO/RwXQy10DCSxT8vSIJClHKp+Ao4qJKdYeV0SwZ7LMQziyLfxIUOY6Grja/sQFw +LKYf8EdDXAyjggF1MIIBcTAfBgNVHSMEGDAWgBR8XQKEE9TMipuBzhccLikenEhj +QjAdBgNVHQ4EFgQU4TqrIXzx401UrtRyt/2LWUIgkFQwHQYDVR0lBBYwFAYIKwYB +BQUHAwEGCCsGAQUFBwMCMD0GA1UdIAQ2MDQwMgYEVR0gADAqMCgGCCsGAQUFBwIB +FhxodHRwOi8vcmVwb3NpdG9yeS5lbXNpZ24uY29tMHgGCCsGAQUFBwEBBGwwajAi +BggrBgEFBQcwAYYWaHR0cDovL29jc3AuZW1zaWduLmNvbTBEBggrBgEFBQcwAoY4 +aHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbS9jZXJ0cy9lbVNpZ25FQ0NSb290 +Q0FHMy5jcnQwMwYDVR0fBCwwKjAooCagJIYiaHR0cDovL2NybC5lbXNpZ24uY29t +P1Jvb3RDQUczLmNybDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB +ATAKBggqhkjOPQQDAwNpADBmAjEAt9CIpRGp46QHQYDUBnLKw+vvK0/h9vmilEAg +TroUl/anH4x2rXHqiCtBTBfgKDegAjEA8WpG1LTZdAIL0FSYqxXeREaeTSxEofM0 +1jJH3jGvCXC79LU9UPJ2o3TU+UIj2gMV +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/dv-g3c-aaa-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/dv-g3c-aaa-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..9ed0fd165 --- /dev/null +++ b/ci/tls/fixtures/dv-g3c-aaa-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,38 @@ +-----BEGIN CERTIFICATE----- +MIICQjCCAcegAwIBAgIUMH3z62Z6agEULBZqrfhpw9/ZpCAwCgYIKoZIzj0EAwIw +QDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRocmEgSW5jMRswGQYDVQQDDBJF +TSBEViBUTFMgQ0EgLSBHM0MwHhcNMjYxMDIwMDIyMjQxWhcNMjcwNTAzMDIyNzQx +WjAzMTEwLwYDVQQDDChkdi1nM2MtYWFhLWVtdWRocmEud2UtaGF2ZS1hLXByb2Js +ZW0uY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEAMPpHsQqEqIerrj/durO +EN7gkUVJSVgIPN6+VJ2sEGXDyqXAN1fnNzGuASP/4WEr0RIhht3cYvuUYp2SYofr +w6OBqzCBqDAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAK +BggrBgEFBQcDATAzBgNVHREELDAqgihkdi1nM2MtYWFhLWVtdWRocmEud2UtaGF2 +ZS1hLXByb2JsZW0uY29tMB0GA1UdDgQWBBT8CNQz4OLVnIwrQYZBF+++9jTCvzAf +BgNVHSMEGDAWgBSufhBcPCmWwahHJwVZ8eA91OUK8zAKBggqhkjOPQQDAgNpADBm +AjEAp3ZLdfBvKcZxgR2p8LZaxWzP6uB7zU/EZ9BA49Ds2P5ByYkRodwK5qcwt4J/ +VL/vAjEAnnxrcrDX7SzoJxuho604GBh6eyBLJLCdmcy+qb+LA3u5oxP/OjAzCA4x +v1kw6Tm4 +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzzCCAregAwIBAgIRAJHzR/Glt9OZYrleDuTimdEwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMEAxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVkaHJhIElu +YzEbMBkGA1UEAwwSRU0gRFYgVExTIENBIC0gRzNDMHYwEAYHKoZIzj0CAQYFK4EE +ACIDYgAEOnp4YsjETTJN3WkDOmeCwO/u/kBV5ooSP6A3G6O9kZRRTuFypDPjYw8C +vRiAN9nlFJ+bd9uUooHfmHsv6oiLdL3+j9pMEJnubKGVZv4+8OX2sJpVbMyLpQVh +3xsqRB0Bo4IBNTCCATEwHwYDVR0jBBgwFoAUoBEKIz6W8Qfs4q8p74Klf9AwpLQw +HQYDVR0OBBYEFK5+EFw8KZbBqEcnBVnx4D3U5QrzMA4GA1UdDwEB/wQEAwIBBjAS +BgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD +AjAxBgNVHSAEKjAoMAgGBmeBDAECATANBgsrBgEEAYOOIQEAATANBgsrBgEEAYOO +IQECZDBDBgNVHR8EPDA6MDigNqA0hjJodHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9B +QUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNybDA0BggrBgEFBQcBAQQoMCYwJAYIKwYB +BQUHMAGGGGh0dHA6Ly9vY3NwLmNvbW9kb2NhLmNvbTANBgkqhkiG9w0BAQsFAAOC +AQEAr7b6Mx11TIJgVzHt6EH5qGNWeiiqoMrp8E5/k8s+jvupx1n083pZ5XOzUzND +wEUe0W4C4FIGUHNQ4XDwqOw0yK42xqm2dvCKgsko2UvDlT0haZVtTCeWMQOe5J/J +ziaMfZwsZNfZ3aaI6XPtWDZtwY8AaNfyaeCpbtm5GcGnyNWk4jSNpbtpo6NjfXuP +CFOm3rTjJ4zytP7Tso6iMm0L01cYFOlTmoPv4515R2r3SPnKDtijoB/D/vgxzojv +DafgyG9afX8+laO9NbMMz4sqC1vZx3984i/sBNFiugm3Vvdq5OdJRjuGC1QILIs6 +dg/K3i8VQqRpbfaM9kIlMzZ3dQ== +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/dv-g3c-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/dv-g3c-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..e9de7026b --- /dev/null +++ b/ci/tls/fixtures/dv-g3c-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,56 @@ +-----BEGIN CERTIFICATE----- +MIICODCCAb+gAwIBAgIUbWvtwSNK/Qro223vAqyz323+VBAwCgYIKoZIzj0EAwIw +QDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRocmEgSW5jMRswGQYDVQQDDBJF +TSBEViBUTFMgQ0EgLSBHM0MwHhcNMjYxMDIwMDA1OTM2WhcNMjcwNTAzMDEwNDM2 +WjAvMS0wKwYDVQQDDCRkdi1nM2MtZW11ZGhyYS53ZS1oYXZlLWEtcHJvYmxlbS5j +b20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAScdBQpNUOOCcag6YEVFccNRSFe +UIl02iH53vDfoWPJFS005WzqF3CPDclB/kygP2gWF4pg/r5gPYdnI3/6Vdzro4Gn +MIGkMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoGCCsG +AQUFBwMBMC8GA1UdEQQoMCaCJGR2LWczYy1lbXVkaHJhLndlLWhhdmUtYS1wcm9i +bGVtLmNvbTAdBgNVHQ4EFgQUBj2yGO/TzDOE/u/6QeUvcW8y1iMwHwYDVR0jBBgw +FoAUrn4QXDwplsGoRycFWfHgPdTlCvMwCgYIKoZIzj0EAwIDZwAwZAIwBQOOQqG9 +ccdzM/7XIlXLtota1esALaLmgEN/ZweosBIvk4xabHcERZInWVIwO45NAjBos8Ue +NwDe1X3ahdK2lkxqBEoBMtUHJN18TnJKs2nK1gmXpMbmY5oKnAQQgCEZPA4= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu6gAwIBAgIPWIsuPCu4zaE+GhIJJUMhMAoGCCqGSM49BAMDMFYxCzAJ +BgNVBAYTAklOMSUwIwYDVQQKDBxlTXVkaHJhIFRlY2hub2xvZ2llcyBMaW1pdGVk +MSAwHgYDVQQDDBdlbVNpZ24gUm9vdCBUTFMgQ0EgLSBHMzAeFw0yNTA0MzAxNTM1 +MDlaFw00MDA0MjgxODMwMDBaMEAxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVk +aHJhIEluYzEbMBkGA1UEAwwSRU0gRFYgVExTIENBIC0gRzNDMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAEOnp4YsjETTJN3WkDOmeCwO/u/kBV5ooSP6A3G6O9kZRRTuFy +pDPjYw8CvRiAN9nlFJ+bd9uUooHfmHsv6oiLdL3+j9pMEJnubKGVZv4+8OX2sJpV +bMyLpQVh3xsqRB0Bo4IBljCCAZIwHwYDVR0jBBgwFoAU4TqrIXzx401UrtRyt/2L +WUIgkFQwHQYDVR0OBBYEFK5+EFw8KZbBqEcnBVnx4D3U5QrzMB0GA1UdJQQWMBQG +CCsGAQUFBwMBBggrBgEFBQcDAjBdBgNVHSAEVjBUMDkGCysGAQQBg44hAQABMCow +KAYIKwYBBQUHAgEWHGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDQYLKwYB +BAGDjiEBAmQwCAYGZ4EMAQIBMHUGCCsGAQUFBwEBBGkwZzAkBggrBgEFBQcwAYYY +aHR0cDovL29jc3AtYy5lbXNpZ24uY29tMD8GCCsGAQUFBzAChjNodHRwOi8vcmVw +b3NpdG9yeS5lbXNpZ24uY29tL2NlcnRzL0VNRFZUTFNDQUczQy5wN2MwNwYDVR0f +BDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290dGxzY2FnMy5j +cmwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwCgYIKoZIzj0E +AwMDaAAwZQIxAMEN2HWMocbuWdy1d33pH6JpMvP/V/DIS5PtZbv1Q7TXEbxrcyxg +yuddOJscYDJJlAIwB4sH1BpbScDzkdD4tJBSwrG/1Mx82vb8YaySehNuu1+1oXNd +AEKwaJ0mVzScy2+6 +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDdDCCAvmgAwIBAgIQAJYaPvsTWVdu0EAFtGhKWzAKBggqhkjOPQQDAzBrMQsw +CQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhy +YSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290 +IENBIC0gRzMwHhcNMjQwNzExMTU0MzM2WhcNMzkwNzA5MTgzMDAwWjBWMQswCQYD +VQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEg +MB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwdjAQBgcqhkjOPQIBBgUr +gQQAIgNiAARfD9w/q1cWxL6D9bMGH6CQ4u+gAV6GN9s+PwQx9Bl4hC+0iU8QOk8m +WO/RwXQy10DCSxT8vSIJClHKp+Ao4qJKdYeV0SwZ7LMQziyLfxIUOY6Grja/sQFw +LKYf8EdDXAyjggF1MIIBcTAfBgNVHSMEGDAWgBR8XQKEE9TMipuBzhccLikenEhj +QjAdBgNVHQ4EFgQU4TqrIXzx401UrtRyt/2LWUIgkFQwHQYDVR0lBBYwFAYIKwYB +BQUHAwEGCCsGAQUFBwMCMD0GA1UdIAQ2MDQwMgYEVR0gADAqMCgGCCsGAQUFBwIB +FhxodHRwOi8vcmVwb3NpdG9yeS5lbXNpZ24uY29tMHgGCCsGAQUFBwEBBGwwajAi +BggrBgEFBQcwAYYWaHR0cDovL29jc3AuZW1zaWduLmNvbTBEBggrBgEFBQcwAoY4 +aHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbS9jZXJ0cy9lbVNpZ25FQ0NSb290 +Q0FHMy5jcnQwMwYDVR0fBCwwKjAooCagJIYiaHR0cDovL2NybC5lbXNpZ24uY29t +P1Jvb3RDQUczLmNybDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB +ATAKBggqhkjOPQQDAwNpADBmAjEAt9CIpRGp46QHQYDUBnLKw+vvK0/h9vmilEAg +TroUl/anH4x2rXHqiCtBTBfgKDegAjEA8WpG1LTZdAIL0FSYqxXeREaeTSxEofM0 +1jJH3jGvCXC79LU9UPJ2o3TU+UIj2gMV +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/ev-g3b-aaa-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/ev-g3b-aaa-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..5a9b6a4d0 --- /dev/null +++ b/ci/tls/fixtures/ev-g3b-aaa-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,38 @@ +-----BEGIN CERTIFICATE----- +MIICQDCCAcagAwIBAgIUUYu3O8bpN1GPvCIHqWpT/FYUNDowCgYIKoZIzj0EAwIw +PzELMAkGA1UEBhMCTkwxEzARBgNVBAoMCmVNdWRocmEgQlYxGzAZBgNVBAMMEkVN +IEVWIFRMUyBDQSAtIEczQjAeFw0yNjEwMjAwMjIyNDFaFw0yNzA1MDMwMjI3NDFa +MDMxMTAvBgNVBAMMKGV2LWczYi1hYWEtZW11ZGhyYS53ZS1oYXZlLWEtcHJvYmxl +bS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASjDLpnVdmvXM6R3UB2o42a +1GnrYfxRXo7UII36mBl9mIS7p9MkAryhPdxitFHkgTrrbypVtzpydNtJIGGGXUwE +o4GrMIGoMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoG +CCsGAQUFBwMBMDMGA1UdEQQsMCqCKGV2LWczYi1hYWEtZW11ZGhyYS53ZS1oYXZl +LWEtcHJvYmxlbS5jb20wHQYDVR0OBBYEFEVBY1ecTN9bLMDl4ifdnN2WZL+WMB8G +A1UdIwQYMBaAFD7cINmJRpiHe4c/2IFHslwV2EcGMAoGCCqGSM49BAMCA2gAMGUC +MQCyvr9gktgmtsuTuFleFV+YExNNKLf3GZieuUprQcERrzh798oYKavTqZeYf9Kz +RhECMCVs1B7KPh7/lgHRly14Z8RJA8ApR7e2cRREW5uPKFOSDlZ/RIezxsfEzsQ4 +lAODeA== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzTCCArWgAwIBAgIRANj4aF5PK9nYJAKoWhwetzEwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMD8xCzAJBgNVBAYTAk5MMRMwEQYDVQQKDAplTXVkaHJhIEJW +MRswGQYDVQQDDBJFTSBFViBUTFMgQ0EgLSBHM0IwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAAQl26haZNOX2gsQUunqVG5Ie+/qnJ2daKDF6tz+73Wmm7XW/AH0K/vKbrQL +zWTAdn42/9Bdl6gTxaoMbJUw55z18IZkaPE4BkIKpchRhAseJSVA55DktlTDhS7W +SvHoZX2jggE0MIIBMDAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQUPtwg2YlGmId7hz/YgUeyXBXYRwYwDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC +MDAGA1UdIAQpMCcwBwYFZ4EMAQEwDQYLKwYBBAGDjiEBAAEwDQYLKwYBBAGDjiEB +AngwQwYDVR0fBDwwOjA4oDagNIYyaHR0cDovL2NybC5jb21vZG9jYS5jb20vQUFB +Q2VydGlmaWNhdGVTZXJ2aWNlcy5jcmwwNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUF +BzABhhhodHRwOi8vb2NzcC5jb21vZG9jYS5jb20wDQYJKoZIhvcNAQELBQADggEB +AJNFuAFW9Gnw/8+kCO4KIlZdnM1Sh2u+8cK0EYAHhXpb5FlGvYkcARigo5oS7VoM +7FOYlTueV6yICZKNAYawZPJPhNCGK+rp3cQBEz6d0n8OZEYZov9lb3ll8ORgSDuf +FVIW6Gagg/UnOamLBTOR8eD5V73SCme/B2cHUDw+m5E8cc+0Ujzz3Cn3ex5JrhXk +2T3s8PoVzEmhTgGboFfcWO1EYhPPrYwdxPYRQIXAXUXhLEOVNL9ASbZJLFI8E1IM +m7NwxVN2s38jWpaCUaaF0tg7hfiy7oe13rzJfHsdqldJVTTUTPWVx8TC4ju0VLet +bAlwhwFT6AP8uIVMGUHNw24= +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/ev-g3b-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/ev-g3b-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..00618de9c --- /dev/null +++ b/ci/tls/fixtures/ev-g3b-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,56 @@ +-----BEGIN CERTIFICATE----- +MIICNzCCAb6gAwIBAgIUPfthO0PYGAYKs9lQ4gp1IOkOr2MwCgYIKoZIzj0EAwIw +PzELMAkGA1UEBhMCTkwxEzARBgNVBAoMCmVNdWRocmEgQlYxGzAZBgNVBAMMEkVN +IEVWIFRMUyBDQSAtIEczQjAeFw0yNjEwMjAwMDU5MzZaFw0yNzA1MDMwMTA0MzZa +MC8xLTArBgNVBAMMJGV2LWczYi1lbXVkaHJhLndlLWhhdmUtYS1wcm9ibGVtLmNv +bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABPZPwlA3io/AX/pMwu0dNl9WMxrr +C9j/xMLHgG72cWVzoX62REmvp9zyXQ04kHP9/sW6KnCcm5ZZ5i4YoJbDPASjgacw +gaQwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYB +BQUHAwEwLwYDVR0RBCgwJoIkZXYtZzNiLWVtdWRocmEud2UtaGF2ZS1hLXByb2Js +ZW0uY29tMB0GA1UdDgQWBBSvX4QR4ERW5uNUaMq0yYzXCZf0ZjAfBgNVHSMEGDAW +gBQ+3CDZiUaYh3uHP9iBR7JcFdhHBjAKBggqhkjOPQQDAgNnADBkAjACy/uJR01M +/O9IEZyRHX1LSU28bmg542K0IX9jDRTrZXUqkDWfiZIL7xfnrRrBpHoCMFbBIaOa +WwWtFtDg9ZqQvktsWS950u5qfW1sChgWNya/E3IMKFgtoHm2xrZsmfwLSQ== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu2gAwIBAgIQAMfEHv6S2CXwXq6EGkqCwTAKBggqhkjOPQQDAzBWMQsw +CQYDVQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEgMB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwHhcNMjUwNDMwMTYw +MzMxWhcNNDAwNDI4MTgzMDAwWjA/MQswCQYDVQQGEwJOTDETMBEGA1UECgwKZU11 +ZGhyYSBCVjEbMBkGA1UEAwwSRU0gRVYgVExTIENBIC0gRzNCMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAEJduoWmTTl9oLEFLp6lRuSHvv6pydnWigxerc/u91ppu11vwB +9Cv7ym60C81kwHZ+Nv/QXZeoE8WqDGyVMOec9fCGZGjxOAZCCqXIUYQLHiUlQOeQ +5LZUw4Uu1krx6GV9o4IBlTCCAZEwHwYDVR0jBBgwFoAU4TqrIXzx401UrtRyt/2L +WUIgkFQwHQYDVR0OBBYEFD7cINmJRpiHe4c/2IFHslwV2EcGMB0GA1UdJQQWMBQG +CCsGAQUFBwMBBggrBgEFBQcDAjBcBgNVHSAEVTBTMDkGCysGAQQBg44hAQABMCow +KAYIKwYBBQUHAgEWHGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDQYLKwYB +BAGDjiEBAngwBwYFZ4EMAQEwdQYIKwYBBQUHAQEEaTBnMCQGCCsGAQUFBzABhhho +dHRwOi8vb2NzcC1iLmVtc2lnbi5jb20wPwYIKwYBBQUHMAKGM2h0dHA6Ly9yZXBv +c2l0b3J5LmVtc2lnbi5jb20vY2VydHMvRU1FVlRMU0NBRzNCLnA3YzA3BgNVHR8E +MDAuMCygKqAohiZodHRwOi8vY3JsLmVtc2lnbi5jb20vP3Jvb3R0bHNjYWczLmNy +bDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADAKBggqhkjOPQQD +AwNpADBmAjEA9Jq999oaOUKhFwopw33iCmt0OHIn3gjT43GfuOHR/YckXdwoNdDA +lIEhz0NgRO3/AjEAvY/a3OMvktIZLYjn+WLKmp0QhrIMV+e6EpS7j4GVeOKouNp6 +MN/P+ByGeiRMghzB +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDdDCCAvmgAwIBAgIQAJYaPvsTWVdu0EAFtGhKWzAKBggqhkjOPQQDAzBrMQsw +CQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhy +YSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290 +IENBIC0gRzMwHhcNMjQwNzExMTU0MzM2WhcNMzkwNzA5MTgzMDAwWjBWMQswCQYD +VQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEg +MB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwdjAQBgcqhkjOPQIBBgUr +gQQAIgNiAARfD9w/q1cWxL6D9bMGH6CQ4u+gAV6GN9s+PwQx9Bl4hC+0iU8QOk8m +WO/RwXQy10DCSxT8vSIJClHKp+Ao4qJKdYeV0SwZ7LMQziyLfxIUOY6Grja/sQFw +LKYf8EdDXAyjggF1MIIBcTAfBgNVHSMEGDAWgBR8XQKEE9TMipuBzhccLikenEhj +QjAdBgNVHQ4EFgQU4TqrIXzx401UrtRyt/2LWUIgkFQwHQYDVR0lBBYwFAYIKwYB +BQUHAwEGCCsGAQUFBwMCMD0GA1UdIAQ2MDQwMgYEVR0gADAqMCgGCCsGAQUFBwIB +FhxodHRwOi8vcmVwb3NpdG9yeS5lbXNpZ24uY29tMHgGCCsGAQUFBwEBBGwwajAi +BggrBgEFBQcwAYYWaHR0cDovL29jc3AuZW1zaWduLmNvbTBEBggrBgEFBQcwAoY4 +aHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbS9jZXJ0cy9lbVNpZ25FQ0NSb290 +Q0FHMy5jcnQwMwYDVR0fBCwwKjAooCagJIYiaHR0cDovL2NybC5lbXNpZ24uY29t +P1Jvb3RDQUczLmNybDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB +ATAKBggqhkjOPQQDAwNpADBmAjEAt9CIpRGp46QHQYDUBnLKw+vvK0/h9vmilEAg +TroUl/anH4x2rXHqiCtBTBfgKDegAjEA8WpG1LTZdAIL0FSYqxXeREaeTSxEofM0 +1jJH3jGvCXC79LU9UPJ2o3TU+UIj2gMV +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/ev-g3c-aaa-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/ev-g3c-aaa-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..a12e7a978 --- /dev/null +++ b/ci/tls/fixtures/ev-g3c-aaa-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,38 @@ +-----BEGIN CERTIFICATE----- +MIICQDCCAcegAwIBAgIUTMUrGzSU+0BySFdrN3ALZq9Spv8wCgYIKoZIzj0EAwIw +QDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRocmEgSW5jMRswGQYDVQQDDBJF +TSBFViBUTFMgQ0EgLSBHM0MwHhcNMjYxMDIwMDIyMjQyWhcNMjcwNTAzMDIyNzQy +WjAzMTEwLwYDVQQDDChldi1nM2MtYWFhLWVtdWRocmEud2UtaGF2ZS1hLXByb2Js +ZW0uY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEglClDbotLFFeY9SpryT4 +k958tvriY2DDnaPsmjQaecRhB6+L/8hLw6FMt+HT8SLvjIZnFY+AH92cBjedcNST +AKOBqzCBqDAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAK +BggrBgEFBQcDATAzBgNVHREELDAqgihldi1nM2MtYWFhLWVtdWRocmEud2UtaGF2 +ZS1hLXByb2JsZW0uY29tMB0GA1UdDgQWBBSVtGbn6xUT1iosUeaGA15Nq640aTAf +BgNVHSMEGDAWgBSmJV6AqU2385Z8G8eR35K87kvrXzAKBggqhkjOPQQDAgNnADBk +AjAg7b5bIK9X50QEX0U6G8fQh12BnFQ079Iluzd0Y2TJWCjtVXZi3nOciM8RzNKM +tZECMCBf0JOyMt8RNS93Wj8kYbWkCtoKoUrqx7G3JTfGReKci+DdTvkF8/3F6doi +9KB22Q== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzTCCArWgAwIBAgIQBfB4dS3s56G7hZXTAxZxcTANBgkqhkiG9w0BAQsFADB7 +MQswCQYDVQQGEwJHQjEbMBkGA1UECAwSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYD +VQQHDAdTYWxmb3JkMRowGAYDVQQKDBFDb21vZG8gQ0EgTGltaXRlZDEhMB8GA1UE +AwwYQUFBIENlcnRpZmljYXRlIFNlcnZpY2VzMB4XDTI1MDUxNDAwMDAwMFoXDTI4 +MTIzMTIzNTk1OVowQDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRocmEgSW5j +MRswGQYDVQQDDBJFTSBFViBUTFMgQ0EgLSBHM0MwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAAQtVugppvuCxkpGl9lgr5UekGeukfkm00MG2kioqut4abamfm0nQm4EQqoD +s24ZiN/2NlFO4c8H9bpLP/KgZkWufTHVhmrTGqPSRusLMXfumct1ZsUWznSAimaP +kfDEf8qjggE0MIIBMDAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQUpiVegKlNt/OWfBvHkd+SvO5L618wDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC +MDAGA1UdIAQpMCcwBwYFZ4EMAQEwDQYLKwYBBAGDjiEBAAEwDQYLKwYBBAGDjiEB +AngwQwYDVR0fBDwwOjA4oDagNIYyaHR0cDovL2NybC5jb21vZG9jYS5jb20vQUFB +Q2VydGlmaWNhdGVTZXJ2aWNlcy5jcmwwNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUF +BzABhhhodHRwOi8vb2NzcC5jb21vZG9jYS5jb20wDQYJKoZIhvcNAQELBQADggEB +AIFfHiaMSjnrdZygRYV4ekRBmG7ybcFk4hGQWMMyMFi0cAEk2+dGfz5bl8IaIbLq +z+uVJzhOgVEX7WqIfgbWfFsfPYHYjPHBmy7SlZ3BwA86IQ6qF/etpX2/qL9A5yRN +N3nVowUpaqV6H3aCpkAh3wR2ZNkvAbLDvPz3J0l+sEWjWv+ZISOV4R+hXDTdPXV0 +1lKxnbwqEsdo/sE2QkCDKwFrZh/0uKjWspydJj+jSaDLTrGNx50Dgmn7VEcD1ZI5 +FXjknVUiO25YlmS1dtVZSBbyUKSjlrP/yDwPcZunoAsmCAAtCKsFLviLaymzvsKI +eSSDGxpSySp2VCxompGDk8g= +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/ev-g3c-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/ev-g3c-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..88402867c --- /dev/null +++ b/ci/tls/fixtures/ev-g3c-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,56 @@ +-----BEGIN CERTIFICATE----- +MIICOTCCAb+gAwIBAgIUOcw5N4XGLiB/3GvB05bJuGoZPR0wCgYIKoZIzj0EAwIw +QDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRocmEgSW5jMRswGQYDVQQDDBJF +TSBFViBUTFMgQ0EgLSBHM0MwHhcNMjYxMDIwMDA1OTM3WhcNMjcwNTAzMDEwNDM3 +WjAvMS0wKwYDVQQDDCRldi1nM2MtZW11ZGhyYS53ZS1oYXZlLWEtcHJvYmxlbS5j +b20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQo7U02MAUO8EEMomXwIl+kSQzm +b+nvXKIZ/hC4rZ1GpXchv4SzTrV1SB/Qg+pD6OBEXbBBnPmQNkePNQTlujqRo4Gn +MIGkMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoGCCsG +AQUFBwMBMC8GA1UdEQQoMCaCJGV2LWczYy1lbXVkaHJhLndlLWhhdmUtYS1wcm9i +bGVtLmNvbTAdBgNVHQ4EFgQUqxe+7qS+MxNyioJZhQsL5MEEw6swHwYDVR0jBBgw +FoAUpiVegKlNt/OWfBvHkd+SvO5L618wCgYIKoZIzj0EAwIDaAAwZQIwC/CxSIov +wcar3sV98B8cL+QuR2kkJdLdXsFKzg/HDSJ1MOjqTGm924LB6r9nl0f7AjEAzcwr +WQOYY9eycqIz+LG2daYS6LOctj+CjoAk/CLugWPxGxp4Aerfau2P1z1h5jAA +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu6gAwIBAgIQAIAJkopkEHYBrwX6LxnxCTAKBggqhkjOPQQDAzBWMQsw +CQYDVQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEgMB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwHhcNMjUwNDMwMTUz +OTMxWhcNNDAwNDI4MTgzMDAwWjBAMQswCQYDVQQGEwJVUzEUMBIGA1UECgwLZU11 +ZGhyYSBJbmMxGzAZBgNVBAMMEkVNIEVWIFRMUyBDQSAtIEczQzB2MBAGByqGSM49 +AgEGBSuBBAAiA2IABC1W6Cmm+4LGSkaX2WCvlR6QZ66R+SbTQwbaSKiq63hptqZ+ +bSdCbgRCqgOzbhmI3/Y2UU7hzwf1uks/8qBmRa59MdWGatMao9JG6wsxd+6Zy3Vm +xRbOdICKZo+R8MR/yqOCAZUwggGRMB8GA1UdIwQYMBaAFOE6qyF88eNNVK7Ucrf9 +i1lCIJBUMB0GA1UdDgQWBBSmJV6AqU2385Z8G8eR35K87kvrXzAdBgNVHSUEFjAU +BggrBgEFBQcDAQYIKwYBBQUHAwIwXAYDVR0gBFUwUzA5BgsrBgEEAYOOIQEAATAq +MCgGCCsGAQUFBwIBFhxodHRwOi8vcmVwb3NpdG9yeS5lbXNpZ24uY29tMA0GCysG +AQQBg44hAQJ4MAcGBWeBDAEBMHUGCCsGAQUFBwEBBGkwZzAkBggrBgEFBQcwAYYY +aHR0cDovL29jc3AtYy5lbXNpZ24uY29tMD8GCCsGAQUFBzAChjNodHRwOi8vcmVw +b3NpdG9yeS5lbXNpZ24uY29tL2NlcnRzL0VNRVZUTFNDQUczQy5wN2MwNwYDVR0f +BDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290dGxzY2FnMy5j +cmwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwCgYIKoZIzj0E +AwMDaAAwZQIwBy1wTnzH4lXDTy2PD91ysLjvnlVN3JbJmc1BIMEU8TOLkYVHibMc +9HeyonikFSfmAjEA6uE3QRxlrZTz/1/lXPTEMUhoauAtycagtlNFp79kjhvNa2/f +Aal1GNxsOutLnr0Y +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDdDCCAvmgAwIBAgIQAJYaPvsTWVdu0EAFtGhKWzAKBggqhkjOPQQDAzBrMQsw +CQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhy +YSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290 +IENBIC0gRzMwHhcNMjQwNzExMTU0MzM2WhcNMzkwNzA5MTgzMDAwWjBWMQswCQYD +VQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEg +MB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwdjAQBgcqhkjOPQIBBgUr +gQQAIgNiAARfD9w/q1cWxL6D9bMGH6CQ4u+gAV6GN9s+PwQx9Bl4hC+0iU8QOk8m +WO/RwXQy10DCSxT8vSIJClHKp+Ao4qJKdYeV0SwZ7LMQziyLfxIUOY6Grja/sQFw +LKYf8EdDXAyjggF1MIIBcTAfBgNVHSMEGDAWgBR8XQKEE9TMipuBzhccLikenEhj +QjAdBgNVHQ4EFgQU4TqrIXzx401UrtRyt/2LWUIgkFQwHQYDVR0lBBYwFAYIKwYB +BQUHAwEGCCsGAQUFBwMCMD0GA1UdIAQ2MDQwMgYEVR0gADAqMCgGCCsGAQUFBwIB +FhxodHRwOi8vcmVwb3NpdG9yeS5lbXNpZ24uY29tMHgGCCsGAQUFBwEBBGwwajAi +BggrBgEFBQcwAYYWaHR0cDovL29jc3AuZW1zaWduLmNvbTBEBggrBgEFBQcwAoY4 +aHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbS9jZXJ0cy9lbVNpZ25FQ0NSb290 +Q0FHMy5jcnQwMwYDVR0fBCwwKjAooCagJIYiaHR0cDovL2NybC5lbXNpZ24uY29t +P1Jvb3RDQUczLmNybDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB +ATAKBggqhkjOPQQDAwNpADBmAjEAt9CIpRGp46QHQYDUBnLKw+vvK0/h9vmilEAg +TroUl/anH4x2rXHqiCtBTBfgKDegAjEA8WpG1LTZdAIL0FSYqxXeREaeTSxEofM0 +1jJH3jGvCXC79LU9UPJ2o3TU+UIj2gMV +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/ov-g3b-aaa-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/ov-g3b-aaa-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..ca1aa763c --- /dev/null +++ b/ci/tls/fixtures/ov-g3b-aaa-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,38 @@ +-----BEGIN CERTIFICATE----- +MIICPzCCAcagAwIBAgIUH0gWfBRnOiSjcduti/cukjDGAjIwCgYIKoZIzj0EAwIw +PzELMAkGA1UEBhMCTkwxEzARBgNVBAoMCmVNdWRocmEgQlYxGzAZBgNVBAMMEkVN +IE9WIFRMUyBDQSAtIEczQjAeFw0yNjEwMjAwMjIyNDJaFw0yNzA1MDMwMjI3NDJa +MDMxMTAvBgNVBAMMKG92LWczYi1hYWEtZW11ZGhyYS53ZS1oYXZlLWEtcHJvYmxl +bS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ3EfjVE+6fUm9gr7UoUv6N +YPttIdILR9OMZnAdTj+RWT1Z4fp7dpC5mat1gbIo4J6EDelcOQQz5/oGeB3gFJKw +o4GrMIGoMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoG +CCsGAQUFBwMBMDMGA1UdEQQsMCqCKG92LWczYi1hYWEtZW11ZGhyYS53ZS1oYXZl +LWEtcHJvYmxlbS5jb20wHQYDVR0OBBYEFKzQPp6gTBOWb0TBxZbkL5zsQn3oMB8G +A1UdIwQYMBaAFJvYZVGv5+csN60I7mkZ2b83hK4KMAoGCCqGSM49BAMCA2cAMGQC +MARKrRRBEWY2Ix1d80DGUvC7bWENP1Q9pf6BOGF4+84UiwV5+nAuht/+hdpAanWB +sQIwJF2dW8tpPN6lTm1kDerzG6yJAJOz4drotaTthMF2+efuv5W2FL7Dr8qZSd1z +201o +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzjCCAragAwIBAgIRAOlCI73pL5FOWrmsq/2sNxAwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMD8xCzAJBgNVBAYTAk5MMRMwEQYDVQQKDAplTXVkaHJhIEJW +MRswGQYDVQQDDBJFTSBPViBUTFMgQ0EgLSBHM0IwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAARziXqg6zz9yosSQC/68KvE4SErr43ud4rJ7i1tuD+sKAxeBWOK56Ks1xwy +Ko42HN659pxDArndjXPRzGyqsswK7k4hbOl53VGKSvS2JuVoTN1lgDftDIVOTMEv +TPhkbQ2jggE1MIIBMTAfBgNVHSMEGDAWgBSgEQojPpbxB+zirynvgqV/0DCktDAd +BgNVHQ4EFgQUm9hlUa/n5yw3rQjuaRnZvzeErgowDgYDVR0PAQH/BAQDAgEGMBIG +A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC +MDEGA1UdIAQqMCgwCAYGZ4EMAQICMA0GCysGAQQBg44hAQABMA0GCysGAQQBg44h +AQJuMEMGA1UdHwQ8MDowOKA2oDSGMmh0dHA6Ly9jcmwuY29tb2RvY2EuY29tL0FB +QUNlcnRpZmljYXRlU2VydmljZXMuY3JsMDQGCCsGAQUFBwEBBCgwJjAkBggrBgEF +BQcwAYYYaHR0cDovL29jc3AuY29tb2RvY2EuY29tMA0GCSqGSIb3DQEBCwUAA4IB +AQALRoOSvkzRa+tN5Rje9W5GiXd/qsicd9N6Gnh0SWC7VyWH+HycIqAnFCMYZznj +CeGusomFYHE42SHWr85JDIbgzy6y3dO4i9n9w0Bx7yrXWBbDzFS8VgA3+EY4Cg7y +mtoC3RPOJVtaXXPZ+68X804g1Mj+3vCSHj2lNPVgco0OzSIOJ/KMg1R9MLBkiKzb +bERAGZHejY0HBhYd76IINZN8z6bBNah2UdFYxsOisLynPQUkol6gRLum024/FzVl +CCDfnUusrkr+mAfPAvD/Vb8bhpA7jYtepuU+2mIdShj5lLlvAwZphn+ypWycuo2x +0k9mldz2dqI9nhCiY+TTIOOR +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/ov-g3b-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/ov-g3b-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..65e7cceda --- /dev/null +++ b/ci/tls/fixtures/ov-g3b-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,56 @@ +-----BEGIN CERTIFICATE----- +MIICODCCAb6gAwIBAgIUPXjC97k7buQHZ7p5ehDU8QNyrR4wCgYIKoZIzj0EAwIw +PzELMAkGA1UEBhMCTkwxEzARBgNVBAoMCmVNdWRocmEgQlYxGzAZBgNVBAMMEkVN +IE9WIFRMUyBDQSAtIEczQjAeFw0yNjEwMjAwMDU5MzdaFw0yNzA1MDMwMTA0Mzda +MC8xLTArBgNVBAMMJG92LWczYi1lbXVkaHJhLndlLWhhdmUtYS1wcm9ibGVtLmNv +bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABA1haD+95Albk0UN6YtDCPpqevTv +YUmEhsIVpb/hnhsbBlH0yLthSE2JLH14ywiQJXttoc/pDWC9eoICW6CJXL2jgacw +gaQwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYB +BQUHAwEwLwYDVR0RBCgwJoIkb3YtZzNiLWVtdWRocmEud2UtaGF2ZS1hLXByb2Js +ZW0uY29tMB0GA1UdDgQWBBQUhzc4s202Hn62G0srmgguYdY2MTAfBgNVHSMEGDAW +gBSb2GVRr+fnLDetCO5pGdm/N4SuCjAKBggqhkjOPQQDAgNoADBlAjEAoJ6d4zzA +xE349yGHHrwKZpVCC/HBFutcOpOfzQoe8ikbmaaBTdtKai5TEllwt3dBAjBeHGiX +VheDhJfewbei99cw1MfYB5tPwdfuY5pe1MJz0Tg9zJ4JgxBvF6LTT0OOXZ4= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDZjCCAu2gAwIBAgIPbK2jZ/scEACIEg6iAtVoMAoGCCqGSM49BAMDMFYxCzAJ +BgNVBAYTAklOMSUwIwYDVQQKDBxlTXVkaHJhIFRlY2hub2xvZ2llcyBMaW1pdGVk +MSAwHgYDVQQDDBdlbVNpZ24gUm9vdCBUTFMgQ0EgLSBHMzAeFw0yNTA0MzAxNjAw +MTJaFw00MDA0MjgxODMwMDBaMD8xCzAJBgNVBAYTAk5MMRMwEQYDVQQKDAplTXVk +aHJhIEJWMRswGQYDVQQDDBJFTSBPViBUTFMgQ0EgLSBHM0IwdjAQBgcqhkjOPQIB +BgUrgQQAIgNiAARziXqg6zz9yosSQC/68KvE4SErr43ud4rJ7i1tuD+sKAxeBWOK +56Ks1xwyKo42HN659pxDArndjXPRzGyqsswK7k4hbOl53VGKSvS2JuVoTN1lgDft +DIVOTMEvTPhkbQ2jggGWMIIBkjAfBgNVHSMEGDAWgBThOqshfPHjTVSu1HK3/YtZ +QiCQVDAdBgNVHQ4EFgQUm9hlUa/n5yw3rQjuaRnZvzeErgowHQYDVR0lBBYwFAYI +KwYBBQUHAwEGCCsGAQUFBwMCMF0GA1UdIARWMFQwOQYLKwYBBAGDjiEBAAEwKjAo +BggrBgEFBQcCARYcaHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbTANBgsrBgEE +AYOOIQECbjAIBgZngQwBAgIwdQYIKwYBBQUHAQEEaTBnMCQGCCsGAQUFBzABhhho +dHRwOi8vb2NzcC1iLmVtc2lnbi5jb20wPwYIKwYBBQUHMAKGM2h0dHA6Ly9yZXBv +c2l0b3J5LmVtc2lnbi5jb20vY2VydHMvRU1PVlRMU0NBRzNCLnA3YzA3BgNVHR8E +MDAuMCygKqAohiZodHRwOi8vY3JsLmVtc2lnbi5jb20vP3Jvb3R0bHNjYWczLmNy +bDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADAKBggqhkjOPQQD +AwNnADBkAjBAk+5BizdJhrED3wb7F2Gm7bWI60dlNd075nghT2TrR4NWKZtJZcbc +28xxIY/NONICMF6mPdsjosaqmvEMWqKcBh4vsIvXSKnQj5o8zrFB4oKS+accjYTe +8Dz3bQjauvy9uw== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDdDCCAvmgAwIBAgIQAJYaPvsTWVdu0EAFtGhKWzAKBggqhkjOPQQDAzBrMQsw +CQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhy +YSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290 +IENBIC0gRzMwHhcNMjQwNzExMTU0MzM2WhcNMzkwNzA5MTgzMDAwWjBWMQswCQYD +VQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEg +MB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwdjAQBgcqhkjOPQIBBgUr +gQQAIgNiAARfD9w/q1cWxL6D9bMGH6CQ4u+gAV6GN9s+PwQx9Bl4hC+0iU8QOk8m +WO/RwXQy10DCSxT8vSIJClHKp+Ao4qJKdYeV0SwZ7LMQziyLfxIUOY6Grja/sQFw +LKYf8EdDXAyjggF1MIIBcTAfBgNVHSMEGDAWgBR8XQKEE9TMipuBzhccLikenEhj +QjAdBgNVHQ4EFgQU4TqrIXzx401UrtRyt/2LWUIgkFQwHQYDVR0lBBYwFAYIKwYB +BQUHAwEGCCsGAQUFBwMCMD0GA1UdIAQ2MDQwMgYEVR0gADAqMCgGCCsGAQUFBwIB +FhxodHRwOi8vcmVwb3NpdG9yeS5lbXNpZ24uY29tMHgGCCsGAQUFBwEBBGwwajAi +BggrBgEFBQcwAYYWaHR0cDovL29jc3AuZW1zaWduLmNvbTBEBggrBgEFBQcwAoY4 +aHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbS9jZXJ0cy9lbVNpZ25FQ0NSb290 +Q0FHMy5jcnQwMwYDVR0fBCwwKjAooCagJIYiaHR0cDovL2NybC5lbXNpZ24uY29t +P1Jvb3RDQUczLmNybDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB +ATAKBggqhkjOPQQDAwNpADBmAjEAt9CIpRGp46QHQYDUBnLKw+vvK0/h9vmilEAg +TroUl/anH4x2rXHqiCtBTBfgKDegAjEA8WpG1LTZdAIL0FSYqxXeREaeTSxEofM0 +1jJH3jGvCXC79LU9UPJ2o3TU+UIj2gMV +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/ov-g3c-aaa-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/ov-g3c-aaa-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..1b159f54e --- /dev/null +++ b/ci/tls/fixtures/ov-g3c-aaa-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,38 @@ +-----BEGIN CERTIFICATE----- +MIICQTCCAcegAwIBAgIULuWnWW6kFV6QZxp2ls8r18NCjXkwCgYIKoZIzj0EAwIw +QDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRocmEgSW5jMRswGQYDVQQDDBJF +TSBPViBUTFMgQ0EgLSBHM0MwHhcNMjYxMDIwMDIyMjQyWhcNMjcwNTAzMDIyNzQy +WjAzMTEwLwYDVQQDDChvdi1nM2MtYWFhLWVtdWRocmEud2UtaGF2ZS1hLXByb2Js +ZW0uY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEb7+5g2YHNYwH2eQERrZc +TmVuf/RmvzsGGMSwXmZke6vn35Ut5HME7UOOU3Muy+BSfjfpo6fjL5KOs3Ndz67d +OKOBqzCBqDAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAK +BggrBgEFBQcDATAzBgNVHREELDAqgihvdi1nM2MtYWFhLWVtdWRocmEud2UtaGF2 +ZS1hLXByb2JsZW0uY29tMB0GA1UdDgQWBBQ7oBzq3jpTuvntbIkzMV12Ps3O0TAf +BgNVHSMEGDAWgBQ06uoM68kK2vnQxeLtm3jJh54bbDAKBggqhkjOPQQDAgNoADBl +AjEA/Y7AZ4M2MYbN5Od9tREaUfFjZKoOjczfIKPjKNMjtGxTdL9WUXvAT4QDgktn +/IJdAjAbORTkAXD5hggyG6K7p0MBz3lFZJb2l/LndZlrttJWBLP8QGrc44hrZZtK +Iq0d1dE= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDzzCCAregAwIBAgIRAI1aSBGTnvRH13ERzdmEmukwDQYJKoZIhvcNAQELBQAw +ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G +A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0yNTA1MTQwMDAwMDBaFw0y +ODEyMzEyMzU5NTlaMEAxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVkaHJhIElu +YzEbMBkGA1UEAwwSRU0gT1YgVExTIENBIC0gRzNDMHYwEAYHKoZIzj0CAQYFK4EE +ACIDYgAEE4JRzVKskpjByKrZdzId65fnCb0LTKCspV3IrVHc/J0ViaFZfjpRIOHv +1jHGPhg1ysrimGmmLhYx6KKBgatWYW3EXZGKvAnzqw5jz3kqpNztc4e+N7ulaVSf +HAKycO1no4IBNTCCATEwHwYDVR0jBBgwFoAUoBEKIz6W8Qfs4q8p74Klf9AwpLQw +HQYDVR0OBBYEFDTq6gzryQra+dDF4u2beMmHnhtsMA4GA1UdDwEB/wQEAwIBBjAS +BgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD +AjAxBgNVHSAEKjAoMAgGBmeBDAECAjANBgsrBgEEAYOOIQEAATANBgsrBgEEAYOO +IQECbjBDBgNVHR8EPDA6MDigNqA0hjJodHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9B +QUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNybDA0BggrBgEFBQcBAQQoMCYwJAYIKwYB +BQUHMAGGGGh0dHA6Ly9vY3NwLmNvbW9kb2NhLmNvbTANBgkqhkiG9w0BAQsFAAOC +AQEAHlbhZpjhkPEAQVhPHRtBDaHqiisVD20pQ1TUeSx3l62Qe7NQ0b7vWQy7DN0i +KOu7BGpP5EnIjvXbz9FhpfPJ4FhKEt3tQ51rqXz2oD8vRaryvExWPobDUz3j7HN6 +OzBsVMIe3PD7AAkpky0x8zMSi/ep5R9OMzybmNptbtppyuB5ytgq+h7lQdRIP+CQ +TaJX3qTgfMqzntYre5GljmEB5hU2/rSn8zoSU2APkJidlZFpghtgbD4I2VRHZvCw +FFr/SrFM9pwrgbJNZ1MtyTSVgI5NlNb0aMfLR+/r6jJt3ROeY2yh2QQ2dx+Yqgdb +uL5ChFWOQU+ErSDnUq7yr+pjBQ== +-----END CERTIFICATE----- diff --git a/ci/tls/fixtures/ov-g3c-emudhra.we-have-a-problem.com.pem b/ci/tls/fixtures/ov-g3c-emudhra.we-have-a-problem.com.pem new file mode 100644 index 000000000..81f460c9a --- /dev/null +++ b/ci/tls/fixtures/ov-g3c-emudhra.we-have-a-problem.com.pem @@ -0,0 +1,56 @@ +-----BEGIN CERTIFICATE----- +MIICOTCCAb+gAwIBAgIUXcJ4+VeNEICJ9JbBANtIyfP96EowCgYIKoZIzj0EAwIw +QDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2VNdWRocmEgSW5jMRswGQYDVQQDDBJF +TSBPViBUTFMgQ0EgLSBHM0MwHhcNMjYxMDIwMDA1OTM3WhcNMjcwNTAzMDEwNDM3 +WjAvMS0wKwYDVQQDDCRvdi1nM2MtZW11ZGhyYS53ZS1oYXZlLWEtcHJvYmxlbS5j +b20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATLEvRHdoPc0Z9ovgqlYmoKTHPU +Apwd6lAp0ou1G63SzuESyBzIW6Tl64CsKzlV9ggkZjX+L9/tOx97/1wmSTYvo4Gn +MIGkMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoGCCsG +AQUFBwMBMC8GA1UdEQQoMCaCJG92LWczYy1lbXVkaHJhLndlLWhhdmUtYS1wcm9i +bGVtLmNvbTAdBgNVHQ4EFgQUrytBb+px+b58Df+d5vP8GpTW+/wwHwYDVR0jBBgw +FoAUNOrqDOvJCtr50MXi7Zt4yYeeG2wwCgYIKoZIzj0EAwIDaAAwZQIwNdoOUOKz +MLV1OFEoMjBeUqvkQAwsajvVWu0A23qyyvYlosyMp8aFv0gxURW6Yj6DAjEAhe0z +kOQmmqb0eyhjh7weF4fHtwMtLi4jNFA6M/EfPTfkqE91MN9fSin5uhua5xhk +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDaDCCAu6gAwIBAgIPKWkmwiejoVJjkrGUgqUEMAoGCCqGSM49BAMDMFYxCzAJ +BgNVBAYTAklOMSUwIwYDVQQKDBxlTXVkaHJhIFRlY2hub2xvZ2llcyBMaW1pdGVk +MSAwHgYDVQQDDBdlbVNpZ24gUm9vdCBUTFMgQ0EgLSBHMzAeFw0yNTA0MzAxNTM3 +NDFaFw00MDA0MjgxODMwMDBaMEAxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtlTXVk +aHJhIEluYzEbMBkGA1UEAwwSRU0gT1YgVExTIENBIC0gRzNDMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAEE4JRzVKskpjByKrZdzId65fnCb0LTKCspV3IrVHc/J0ViaFZ +fjpRIOHv1jHGPhg1ysrimGmmLhYx6KKBgatWYW3EXZGKvAnzqw5jz3kqpNztc4e+ +N7ulaVSfHAKycO1no4IBljCCAZIwHwYDVR0jBBgwFoAU4TqrIXzx401UrtRyt/2L +WUIgkFQwHQYDVR0OBBYEFDTq6gzryQra+dDF4u2beMmHnhtsMB0GA1UdJQQWMBQG +CCsGAQUFBwMBBggrBgEFBQcDAjBdBgNVHSAEVjBUMDkGCysGAQQBg44hAQABMCow +KAYIKwYBBQUHAgEWHGh0dHA6Ly9yZXBvc2l0b3J5LmVtc2lnbi5jb20wDQYLKwYB +BAGDjiEBAm4wCAYGZ4EMAQICMHUGCCsGAQUFBwEBBGkwZzAkBggrBgEFBQcwAYYY +aHR0cDovL29jc3AtYy5lbXNpZ24uY29tMD8GCCsGAQUFBzAChjNodHRwOi8vcmVw +b3NpdG9yeS5lbXNpZ24uY29tL2NlcnRzL0VNT1ZUTFNDQUczQy5wN2MwNwYDVR0f +BDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbXNpZ24uY29tLz9yb290dGxzY2FnMy5j +cmwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwCgYIKoZIzj0E +AwMDaAAwZQIxAMSZt2xsPeumRdeSMSQ3CbzIZeQ/q7GDCWfeE1Pq+mhgA6gRM44c +NVF3xJ+wsxJk+wIwFJbaDMokD8Ei6eNOiA8yUMYvfzQyngmrhZQMdPCK1SewrR79 +4rSb9vGqxZzelQth +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDdDCCAvmgAwIBAgIQAJYaPvsTWVdu0EAFtGhKWzAKBggqhkjOPQQDAzBrMQsw +CQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhy +YSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290 +IENBIC0gRzMwHhcNMjQwNzExMTU0MzM2WhcNMzkwNzA5MTgzMDAwWjBWMQswCQYD +VQQGEwJJTjElMCMGA1UECgwcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEg +MB4GA1UEAwwXZW1TaWduIFJvb3QgVExTIENBIC0gRzMwdjAQBgcqhkjOPQIBBgUr +gQQAIgNiAARfD9w/q1cWxL6D9bMGH6CQ4u+gAV6GN9s+PwQx9Bl4hC+0iU8QOk8m +WO/RwXQy10DCSxT8vSIJClHKp+Ao4qJKdYeV0SwZ7LMQziyLfxIUOY6Grja/sQFw +LKYf8EdDXAyjggF1MIIBcTAfBgNVHSMEGDAWgBR8XQKEE9TMipuBzhccLikenEhj +QjAdBgNVHQ4EFgQU4TqrIXzx401UrtRyt/2LWUIgkFQwHQYDVR0lBBYwFAYIKwYB +BQUHAwEGCCsGAQUFBwMCMD0GA1UdIAQ2MDQwMgYEVR0gADAqMCgGCCsGAQUFBwIB +FhxodHRwOi8vcmVwb3NpdG9yeS5lbXNpZ24uY29tMHgGCCsGAQUFBwEBBGwwajAi +BggrBgEFBQcwAYYWaHR0cDovL29jc3AuZW1zaWduLmNvbTBEBggrBgEFBQcwAoY4 +aHR0cDovL3JlcG9zaXRvcnkuZW1zaWduLmNvbS9jZXJ0cy9lbVNpZ25FQ0NSb290 +Q0FHMy5jcnQwMwYDVR0fBCwwKjAooCagJIYiaHR0cDovL2NybC5lbXNpZ24uY29t +P1Jvb3RDQUczLmNybDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB +ATAKBggqhkjOPQQDAwNpADBmAjEAt9CIpRGp46QHQYDUBnLKw+vvK0/h9vmilEAg +TroUl/anH4x2rXHqiCtBTBfgKDegAjEA8WpG1LTZdAIL0FSYqxXeREaeTSxEofM0 +1jJH3jGvCXC79LU9UPJ2o3TU+UIj2gMV +-----END CERTIFICATE----- diff --git a/ci/tls/native_checks.py b/ci/tls/native_checks.py new file mode 100644 index 000000000..255166893 --- /dev/null +++ b/ci/tls/native_checks.py @@ -0,0 +1,44 @@ +"""Run native-verifier checks in an unmodified final image, offline.""" +import os +from pathlib import Path +import subprocess +import tempfile +from check_trust import HERE + + +def run_native(image, executable, *args, extra_mount=None): + command = ['docker', 'run', '--rm', '--network=none', + '-v', f'{HERE}:/audit:ro'] + if extra_mount: + command += ['-v', f'{extra_mount}:/control:ro'] + command += ['--entrypoint', executable, image, *args] + subprocess.run(command, check=True) + + +def node(image): + with tempfile.TemporaryDirectory(prefix='polis-tls-control-') as tmp: + path = Path(tmp) + openssl = os.environ.get('OPENSSL', 'openssl') + + def generate(*args): + result = subprocess.run([openssl, *args], cwd=path, capture_output=True, text=True) + if result.returncode: + raise ValueError(result.stderr) + + generate('req', '-x509', '-newkey', 'rsa:2048', '-nodes', '-days', '2', + '-subj', '/CN=Local trust test root', '-keyout', 'root.key', '-out', 'root.pem', + '-addext', 'basicConstraints=critical,CA:TRUE') + for name, subject, extensions, issuer in [ + ('intermediate', 'Local trust test intermediate', + 'basicConstraints=critical,CA:TRUE\nkeyUsage=critical,keyCertSign,cRLSign\n', 'root'), + ('leaf', 'localhost', + 'basicConstraints=critical,CA:FALSE\nsubjectAltName=DNS:localhost\nextendedKeyUsage=serverAuth\n', 'intermediate'), + ]: + (path / 'extensions').write_text(extensions) + generate('req', '-new', '-newkey', 'rsa:2048', '-nodes', '-subj', f'/CN={subject}', + '-keyout', f'{name}.key', '-out', f'{name}.csr') + generate('x509', '-req', '-in', f'{name}.csr', '-CA', f'{issuer}.pem', + '-CAkey', f'{issuer}.key', '-set_serial', '1', '-days', '2', + '-extfile', 'extensions', '-out', f'{name}.pem') + # Generated keys exist only in this temporary mount and are removed on exit. + run_native(image, 'node', '--expose-internals', '/audit/check-node.cjs', '/control', extra_mount=tmp) diff --git a/ci/tls/python.Dockerfile b/ci/tls/python.Dockerfile new file mode 100644 index 000000000..0424d1182 --- /dev/null +++ b/ci/tls/python.Dockerfile @@ -0,0 +1,6 @@ +ARG BASE +FROM ${BASE} +COPY delphi/requirements.lock /tmp/requirements.lock +RUN python -m pip install --no-cache-dir \ + $(grep -E '^(certifi|requests|httpx|botocore|boto3)==' /tmp/requirements.lock) \ + && rm /tmp/requirements.lock diff --git a/ci/tls/test_images.py b/ci/tls/test_images.py new file mode 100644 index 000000000..6fdaa0903 --- /dev/null +++ b/ci/tls/test_images.py @@ -0,0 +1,79 @@ +"""The default gate must build and audit final runtimes, not just base stages.""" +import os +from pathlib import Path +import subprocess +import tempfile +import unittest +from check_trust import HERE + + +class ImageMatrixTests(unittest.TestCase): + def capture(self, selection=None): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + log = root / 'commands.jsonl' + # Record argv without invoking Docker, Python packages, or a network. + for name in ('docker', 'python3'): + executable = root / name + executable.write_text('#!/bin/sh\nprintf "%s\\n" "$*" >> "$COMMAND_LOG"\n') + executable.chmod(0o755) + env = dict(os.environ, PATH=f'{tmp}:{os.environ["PATH"]}', COMMAND_LOG=str(log), TLS_IMAGE_TAG='trust-matrix') + env.pop('TLS_IMAGE_SELECTION', None) + if selection is not None: + env['TLS_IMAGE_SELECTION'] = selection + result = subprocess.run(['bash', str(HERE / 'check-images.sh')], env=env, capture_output=True, text=True) + return result, log.read_text().splitlines() if log.exists() else [] + + def test_default_builds_all_final_images(self): + result, commands = self.capture() + self.assertEqual(result.returncode, 0, result.stderr) + builds = [c for c in commands if c.startswith('build ')] + audits = [c for c in commands if c.startswith('ci/tls/check_image.py ')] + names = ['server', 'python', 'nginx', 'postgres', 'java', 'api', 'migrate', 'oidc', + 'coordinator', 'file-server', 'client-admin', 'client-participation', + 'client-report', 'probe-base', 'probe-worker'] + self.assertEqual(len(builds), len(names)) + self.assertEqual(len(audits), len(names)) + for name in names: + self.assertEqual(sum(c.split()[1] == f'trust-matrix-{name}' for c in audits), 1) + self.assertIn('build --pull --target prod -t trust-matrix-server -f server/Dockerfile .', builds) + self.assertTrue(any('--target final --build-context queue-rs=queue-rs' in c for c in builds)) + self.assertTrue(any('--target runtime -t trust-matrix-java math' in c for c in builds)) + self.assertTrue(any('-f server/Dockerfile-db server' in c for c in builds)) + self.assertIn('ci/tls/check_image.py trust-matrix-python --python --rds --jobs', audits) + self.assertFalse(any('--target base' in c or '--target trust' in c for c in builds)) + + def test_legacy_commentgraph_remains_selectable(self): + result, commands = self.capture('commentgraph') + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(commands, [ + 'build --pull -t trust-matrix-commentgraph delphi/umap_narrative/polismath_commentgraph', + 'ci/tls/check_image.py trust-matrix-commentgraph --python --rpm', + ]) + + def test_hosted_matrix_matches_required_default(self): + workflow = (HERE.parents[1] / '.github/workflows/tls-trust.yml').read_text() + matrix_line = next(line for line in workflow.splitlines() if line.strip().startswith('image: [')) + groups = matrix_line.split('[', 1)[1].split(']', 1)[0].split(', ') + self.assertNotIn('commentgraph', groups) + self.assertIn('probe', groups) + result, default_commands = self.capture() + self.assertEqual(result.returncode, 0, result.stderr) + hosted_commands = [] + for group in groups: + result, commands = self.capture(group) + self.assertEqual(result.returncode, 0, result.stderr) + hosted_commands.extend(commands) + self.assertEqual(hosted_commands, default_commands) + + def test_hosted_selection_is_bounded(self): + result, commands = self.capture('python') + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(len(commands), 2) + self.assertIn('--target final', commands[0]) + self.assertIn('--python --rds --jobs', commands[1]) + + def test_unknown_selection_fails_closed(self): + result, commands = self.capture('typo') + self.assertEqual(result.returncode, 2) + self.assertEqual(commands, []) diff --git a/ci/tls/test_probe_trust.py b/ci/tls/test_probe_trust.py new file mode 100644 index 000000000..df02df78d --- /dev/null +++ b/ci/tls/test_probe_trust.py @@ -0,0 +1,54 @@ +"""Probe blocklist selection must preserve unrelated trust and match policy.""" +import importlib.util +from pathlib import Path +import tempfile +import unittest +from check_trust import HERE, PEM, POLICY, affected_objects + +SPEC = importlib.util.spec_from_file_location( + 'probe_distrust', HERE.parent / 'probe_box/local/distrust-ca.py') +PROBE = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(PROBE) + + +class ProbeTrustTests(unittest.TestCase): + def test_fingerprints_match_all_policy_roots(self): + self.assertEqual(PROBE.BLOCKED, {root['sha256'] for root in POLICY['roots']}) + + def test_only_exact_roots_are_blocked_and_source_is_unchanged(self): + roots = (HERE / 'fixtures/affected-roots.pem').read_text() + unrelated = affected_objects()[0] + original = '# Autorité\n' + roots + '\n' + unrelated + with tempfile.TemporaryDirectory() as tmp: + bundle, destination = Path(tmp) / 'bundle.pem', Path(tmp) / 'blocklist' + bundle.write_text(original) + self.assertEqual(PROBE.block_roots(bundle, destination), PROBE.BLOCKED) + self.assertEqual(bundle.read_text(), original) + self.assertEqual(len(list(destination.iterdir())), 4) + self.assertEqual({p.read_text().strip() for p in destination.iterdir()}, set(PEM.findall(roots))) + before = {p.name: p.read_bytes() for p in destination.iterdir()} + PROBE.block_roots(bundle, destination) + self.assertEqual({p.name: p.read_bytes() for p in destination.iterdir()}, before) + bundle.write_text(unrelated) + self.assertEqual(PROBE.block_roots(bundle, destination), set()) + self.assertEqual({p.name: p.read_bytes() for p in destination.iterdir()}, before) + + def test_empty_bundle_fails_closed(self): + with tempfile.TemporaryDirectory() as tmp: + bundle = Path(tmp) / 'bundle.pem' + bundle.write_text('not a certificate') + with self.assertRaisesRegex(ValueError, 'empty or malformed'): + PROBE.block_roots(bundle, Path(tmp) / 'blocklist') + + def test_non_tls_parents_are_also_blocked(self): + roots = PEM.findall((HERE / 'fixtures/affected-roots.pem').read_text()) + with tempfile.TemporaryDirectory() as tmp: + source, destination = Path(tmp), Path(tmp) / 'blocklist' + for purpose, certs in zip(('tls', 'email', 'objsign'), (roots[:1], roots[1:3], roots[3:])): + (source / f'{purpose}-ca-bundle.pem').write_text('\n'.join(certs)) + PROBE.install_blocklist(source, destination) + self.assertEqual({p.stem.removeprefix('emudhra-') for p in destination.iterdir()}, PROBE.BLOCKED) + + +if __name__ == '__main__': + unittest.main() diff --git a/ci/tls/test_trust.py b/ci/tls/test_trust.py new file mode 100644 index 000000000..8096e5552 --- /dev/null +++ b/ci/tls/test_trust.py @@ -0,0 +1,79 @@ +"""Offline regression controls: empty, stale and alternate-path stores fail.""" +import hashlib +import ssl +import unittest +import tomllib +import tempfile +from pathlib import Path +from unittest.mock import patch +from check_trust import HERE, PEM, POLICY, audit_bundle, verify_chain, affected_objects, verify_object, audit_objects + + +class TrustTests(unittest.TestCase): + def test_empty_store_is_not_a_pass(self): + with self.assertRaisesRegex(ValueError, 'empty'): + audit_bundle('', 'empty') + + def test_each_affected_root_is_rejected(self): + roots = PEM.findall((HERE / 'fixtures/affected-roots.pem').read_text()) + self.assertEqual(len(roots), 4) + for root in roots: + with self.subTest(root=hashlib.sha256(ssl.PEM_cert_to_DER_cert(root)).hexdigest()): + with self.assertRaisesRegex(ValueError, 'trusts'): + audit_bundle(root, 'stale') + + def test_non_ascii_bundle_comments_do_not_hide_stale_trust(self): + roots = (HERE / 'fixtures/affected-roots.pem').read_text() + with self.assertRaisesRegex(ValueError, 'trusts'): + audit_bundle('# Autorité de certification\n' + roots, 'rpm-style') + + def test_chain_fixtures_are_accepted_by_the_old_roots(self): + chains = sorted((HERE / 'fixtures').glob('*we-have-a-problem.com.pem')) + self.assertEqual(len(chains), 12) + for chain in chains: + with self.subTest(chain=chain.name): + result = verify_chain(HERE / 'fixtures/affected-roots.pem', chain) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + + def test_exact_intermediate_identities_and_anchor_rejection(self): + for cert in affected_objects(): + with self.subTest(cert=hashlib.sha256(cert.encode()).hexdigest()): + with self.assertRaisesRegex(ValueError, 'trusts'): + audit_bundle(cert, 'affected-intermediate-as-anchor') + + def test_fixture_identity_changes_fail(self): + with patch.dict(POLICY, {'intermediates': POLICY['intermediates'][:-1]}): + with self.assertRaisesRegex(ValueError, 'sixteen'): + affected_objects() + + def test_all_objects_accepted_with_stale_roots_without_tls_eku(self): + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / 'object.pem' + for cert in affected_objects(): + path.write_text(cert) + result = verify_object(HERE / 'fixtures/affected-roots.pem', path) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + + def test_stale_store_fails_object_gate(self): + with self.assertRaisesRegex(ValueError, 'did not fail for distrust'): + audit_objects((HERE / 'fixtures/affected-roots.pem').read_text(), 'stale') + + def test_advisory_versions_are_locked(self): + root = HERE.parents[1] + cargo = tomllib.loads((root / 'polis-cli/Cargo.lock').read_text()) + versions = {p['name']: p['version'] for p in cargo['package']} + self.assertEqual(versions['webpki-roots'], '1.0.10') + self.assertEqual(versions['rustls-webpki'], '0.103.16') + uv = tomllib.loads((root / 'delphi/uv.lock').read_text()) + self.assertEqual(next(p['version'] for p in uv['package'] if p['name'] == 'certifi'), '2026.10.19') + self.assertIn('certifi==2026.10.19', (root / 'delphi/requirements.lock').read_text().splitlines()) + self.assertEqual(tomllib.loads((root / 'server/mise.toml').read_text())['tools']['node'], '22.23.4') + + def test_policy_includes_cross_signs(self): + self.assertEqual(len(POLICY['intermediates']), 16) + self.assertEqual(len({r['spki_sha256'] for r in POLICY['intermediates']}), 8) + self.assertIn('AAA Certificate Services', {r['name'] for r in POLICY['roots']}) + + +if __name__ == '__main__': + unittest.main() diff --git a/client-admin/Dockerfile b/client-admin/Dockerfile index 99ebf3bb3..386aaff5b 100644 --- a/client-admin/Dockerfile +++ b/client-admin/Dockerfile @@ -5,7 +5,8 @@ # the docker compose configuration. # Build from the repository root: docker build -f client-admin/Dockerfile . -FROM docker.io/node:24-alpine +FROM docker.io/node:24.22.1-alpine +RUN apk add --no-cache 'ca-certificates>=20261020-r0' # Set default NODE_ENV to production unless overridden at build time with --build-arg NODE_ENV=development ARG NODE_ENV diff --git a/client-participation-alpha/Dockerfile b/client-participation-alpha/Dockerfile index 6ef433c98..1c928990c 100644 --- a/client-participation-alpha/Dockerfile +++ b/client-participation-alpha/Dockerfile @@ -1,5 +1,6 @@ # syntax=docker/dockerfile:1.4 -FROM node:24-alpine +FROM node:24.22.1-alpine +RUN apk add --no-cache 'ca-certificates>=20261020-r0' WORKDIR /app ARG PUBLIC_SERVICE_URL diff --git a/client-participation/Dockerfile b/client-participation/Dockerfile index 7b04336ce..20bbbe9e7 100644 --- a/client-participation/Dockerfile +++ b/client-participation/Dockerfile @@ -5,7 +5,8 @@ # the docker compose configuration. # Build from the repository root: docker build -f client-participation/Dockerfile . -FROM docker.io/node:24-alpine +FROM docker.io/node:24.22.1-alpine +RUN apk add --no-cache 'ca-certificates>=20261020-r0' ARG EMBED_SERVICE_HOSTNAME ARG GA_TRACKING_ID diff --git a/client-report/Dockerfile b/client-report/Dockerfile index 57da5f035..6e3d785cc 100644 --- a/client-report/Dockerfile +++ b/client-report/Dockerfile @@ -5,7 +5,8 @@ # the docker compose configuration. # Build from the repository root: docker build -f client-report/Dockerfile . -FROM docker.io/node:24-alpine +FROM docker.io/node:24.22.1-alpine +RUN apk add --no-cache 'ca-certificates>=20261020-r0' # Set default NODE_ENV to production unless overridden at build time with --build-arg NODE_ENV=development ARG NODE_ENV diff --git a/coordinator-rs/deploy/Dockerfile b/coordinator-rs/deploy/Dockerfile index 32410f038..3743c36f0 100644 --- a/coordinator-rs/deploy/Dockerfile +++ b/coordinator-rs/deploy/Dockerfile @@ -1,5 +1,7 @@ -# Docker Official Images, pinned manifest lists; no package installation. +# Docker Official Images, pinned manifest lists; refresh builder trust before downloads. FROM rust:1.98.1-bookworm@sha256:93ce27a88655056a51dbdd8f5f2d7ddc071c7b0070fb288a37b5a285fc83971e AS build +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates=20250419~deb12u2 \ + && rm -rf /var/lib/apt/lists/* WORKDIR /build/coordinator-rs COPY coordinator-rs/Cargo.toml coordinator-rs/Cargo.lock coordinator-rs/rust-toolchain.toml ./ COPY coordinator-rs/src ./src @@ -7,9 +9,9 @@ COPY coordinator-rs/schemas ./schemas COPY server/postgres/migrations/000021_create_polis_coordinator.sql /build/server/postgres/migrations/000021_create_polis_coordinator.sql COPY coordinator-rs/build.rs coordinator-rs/migration.sql ./ RUN CARGO_BUILD_JOBS=2 cargo build --locked --release --bin coordinator-idle -# Preserve the existing reviewed RDS bundle pin; no live runtime download. +# Use the same pinned public RDS bundle as server/migrator; no runtime download. RUN curl --fail --location --proto '=https' --tlsv1.2 https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem -o /rds-ca.pem \ - && echo 'e5bb2084ccf45087bda1c9bffdea0eb15ee67f0b91646106e466714f9de3c7e3 /rds-ca.pem' | sha256sum --check + && echo '90a6f1a7978a1b1b096dca6c57511ca48d3b8cf052f8e704baf358f34ea2f21b /rds-ca.pem' | sha256sum --check # Copy only the executable and the pinned builder's OpenSSL runtime libraries. RUN mkdir /runtime-libs && cp -L /usr/lib/$(gcc -dumpmachine)/libssl.so.3 /usr/lib/$(gcc -dumpmachine)/libcrypto.so.3 /runtime-libs/ FROM debian:bookworm-slim@sha256:3783cc01769c7b2b1b83a5c5ad96c815348e28ed7da68e2e3687004faa906251 diff --git a/coordinator-rs/evidence/python-requirements.txt b/coordinator-rs/evidence/python-requirements.txt index 95cb6e2d6..d68f2679e 100644 --- a/coordinator-rs/evidence/python-requirements.txt +++ b/coordinator-rs/evidence/python-requirements.txt @@ -1,3 +1,4 @@ +certifi==2026.10.19 boto3==1.43.89 botocore==1.43.89 cloudpickle==3.1.2 diff --git a/delphi/Dockerfile b/delphi/Dockerfile index 34b4a2c88..484df3787 100644 --- a/delphi/Dockerfile +++ b/delphi/Dockerfile @@ -7,7 +7,7 @@ # The toolchain matches queue-rs/rust-toolchain.toml (1.98.1). FROM docker.io/library/rust:1.98.1-slim-bookworm AS polis-jobs RUN apt-get update \ - && apt-get install -y --no-install-recommends pkg-config libssl-dev \ + && apt-get install -y --no-install-recommends pkg-config libssl-dev ca-certificates=20250419~deb12u2 \ && rm -rf /var/lib/apt/lists/* WORKDIR /src COPY --from=queue-rs . . @@ -17,7 +17,12 @@ RUN --mount=type=cache,target=/src/target,id=delphi-polis-jobs-target \ && /polis-jobs --version # ---- Stage 1: Builder ---- - FROM python:3.12-slim AS builder + FROM python:3.12-slim-trixie AS trust +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates=20250419+deb13u1 \ + && rm -rf /var/lib/apt/lists/* + + FROM trust AS builder # Define a build argument to signal if we should install CPU-specific torch ARG USE_CPU_TORCH=false @@ -30,7 +35,7 @@ RUN --mount=type=cache,target=/src/target,id=delphi-polis-jobs-target \ # Install uv for faster package installation (~2x faster than pip) # Placed in /opt/uv (not /usr/local/bin) to avoid leaking into the final/prod image # via the blanket COPY --from=builder /usr/local/bin in Stage 2. - COPY --from=ghcr.io/astral-sh/uv:0.11.2 /uv /opt/uv/uv + COPY --from=ghcr.io/astral-sh/uv:0.13.4 /uv /opt/uv/uv ENV PATH="/opt/uv:$PATH" RUN apt-get update && \ @@ -90,7 +95,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \ (ls -lhR /usr/local/lib/python3.12/site-packages/torch/lib/*cuda* || echo "No CUDA libs in torch/lib.") # ---- Stage 2: Final ---- -FROM python:3.12-slim AS final +FROM trust AS final ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 diff --git a/delphi/pyproject.toml b/delphi/pyproject.toml index c7271319c..a6f407a60 100644 --- a/delphi/pyproject.toml +++ b/delphi/pyproject.toml @@ -9,6 +9,7 @@ description = "Mathematical analytics pipeline for Polis conversations" requires-python = ">=3.12,<3.13" # Pin to Python 3.12.x dependencies = [ + "certifi==2026.10.19", "numpy>=1.26.4,<2.0", "pandas>=2.1.4", "sqlalchemy>=2.0.36", diff --git a/delphi/requirements.lock b/delphi/requirements.lock index 2eee2b2c1..77380e9d6 100644 --- a/delphi/requirements.lock +++ b/delphi/requirements.lock @@ -29,7 +29,7 @@ botocore==1.34.162 # s3transfer bytecode==0.17.0 # via ddtrace -certifi==2025.11.12 +certifi==2026.10.19 # via # httpcore # httpx diff --git a/delphi/umap_narrative/polismath_commentgraph/pyproject.toml b/delphi/umap_narrative/polismath_commentgraph/pyproject.toml index 721a37d56..ec7e28993 100644 --- a/delphi/umap_narrative/polismath_commentgraph/pyproject.toml +++ b/delphi/umap_narrative/polismath_commentgraph/pyproject.toml @@ -14,6 +14,7 @@ requires-python = ">=3.10" # Install parent project in development mode # This gives us access to all dependencies including evoc dependencies = [ + "certifi==2026.10.19", # Core Lambda runtime dependencies (keep in sync with requirements.txt) "boto3>=1.26.0", "numpy>=1.20.0", diff --git a/delphi/umap_narrative/polismath_commentgraph/requirements.txt b/delphi/umap_narrative/polismath_commentgraph/requirements.txt index 93289df18..304a83f4e 100644 --- a/delphi/umap_narrative/polismath_commentgraph/requirements.txt +++ b/delphi/umap_narrative/polismath_commentgraph/requirements.txt @@ -1,3 +1,4 @@ +certifi==2026.10.19 # Core dependencies boto3>=1.26.0 numpy>=1.20.0 diff --git a/delphi/uv.lock b/delphi/uv.lock index cf572b7c3..c91a7eb3c 100644 --- a/delphi/uv.lock +++ b/delphi/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 3 +revision = 5 requires-python = "==3.12.*" resolution-markers = [ "sys_platform == 'win32'", @@ -275,11 +275,11 @@ wheels = [ [[package]] name = "certifi" -version = "2026.7.22" +version = "2026.10.19" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/a3/c2/24167ea9858356b47a87a50d39908bfdb72ceeefe0041586e704e5376b3a/certifi-2026.7.22.tar.gz", hash = "sha256:741e2c3b351ddf169a738da9f2c048608ff7f2c5cc02f1ebc6b118bb090d5d55", size = 138112, upload-time = "2026-07-22T03:35:12.644Z" } +sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/0b/a7/71ac2cff56fec219ed242bb11b8efb69fcc4bec75db06fb7bfe35de520e6/certifi-2026.7.22-py3-none-any.whl", hash = "sha256:62f22742b58a1a33014a2b6b706588a8d7e2a88ae7bd1a6ebe8c992928483775", size = 136983, upload-time = "2026-07-22T03:35:11.276Z" }, + { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" }, ] [[package]] @@ -667,6 +667,7 @@ dependencies = [ { name = "aws-lambda-powertools" }, { name = "aws-xray-sdk" }, { name = "boto3" }, + { name = "certifi" }, { name = "click" }, { name = "colorlog" }, { name = "datamapplot" }, @@ -739,6 +740,7 @@ requires-dist = [ { name = "aws-lambda-powertools", specifier = ">=2.15.0" }, { name = "aws-xray-sdk", specifier = ">=2.12.0" }, { name = "boto3", specifier = "==1.34.70" }, + { name = "certifi", specifier = "==2026.10.19" }, { name = "click", specifier = ">=8.0.0" }, { name = "click", specifier = ">=8.3.1" }, { name = "colorlog", specifier = ">=6.9.0" }, @@ -1030,8 +1032,8 @@ name = "httpcore2" version = "2.12.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "h11", marker = "sys_platform != 'emscripten'" }, - { name = "truststore", marker = "sys_platform != 'emscripten'" }, + { name = "h11" }, + { name = "truststore" }, ] sdist = { url = "https://files.pythonhosted.org/packages/be/ad/f4f0e57345f1870f3e8cb624e058d7eca6e5a27d33bcc3311d9b618734cd/httpcore2-2.12.0.tar.gz", hash = "sha256:9293522bba0aa7c4c8e9e3f040c16575bd8868e155a77fa30c7a9085a5eae648", size = 67548, upload-time = "2026-08-18T13:22:08.211Z" } wheels = [ @@ -2228,7 +2230,7 @@ name = "pexpect" version = "4.9.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "ptyprocess", marker = "sys_platform != 'emscripten' and sys_platform != 'win32'" }, + { name = "ptyprocess" }, ] sdist = { url = "https://files.pythonhosted.org/packages/42/92/cc564bf6381ff43ce1f4d06852fc19a2f11d180f23dc32d9588bee2f149d/pexpect-4.9.0.tar.gz", hash = "sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f", size = 166450, upload-time = "2023-11-25T09:07:26.339Z" } wheels = [ diff --git a/deploy/requirements.txt b/deploy/requirements.txt index 6179f113f..de9363af0 100644 --- a/deploy/requirements.txt +++ b/deploy/requirements.txt @@ -1 +1,2 @@ +certifi==2026.10.19 boto3>=1.26.0 \ No newline at end of file diff --git a/file-server/Dockerfile b/file-server/Dockerfile index a924b5bd1..0f83373e6 100644 --- a/file-server/Dockerfile +++ b/file-server/Dockerfile @@ -9,7 +9,8 @@ ######################## POLIS CLIENT ADMIN ######################## #FROM client-base AS client-admin # <- switch back to basing on client admin once we upgrade other clients -FROM docker.io/node:24-alpine AS client-admin +FROM docker.io/node:24.22.1-alpine AS client-admin +RUN apk add --no-cache 'ca-certificates>=20261020-r0' # Set default NODE_ENV to production unless overridden at build time with --build-arg NODE_ENV=development ARG NODE_ENV @@ -52,7 +53,8 @@ RUN npm run build:prod ##################### POLIS CLIENT PARTICIPATION ##################### -FROM docker.io/node:24-alpine AS client-participation +FROM docker.io/node:24.22.1-alpine AS client-participation +RUN apk add --no-cache 'ca-certificates>=20261020-r0' ARG EMBED_SERVICE_HOSTNAME ARG GA_TRACKING_ID @@ -94,7 +96,8 @@ RUN npm run build:prod ######################## POLIS CLIENT REPORT ######################## # FROM client-base AS client-report -FROM docker.io/node:24-alpine AS client-report +FROM docker.io/node:24.22.1-alpine AS client-report +RUN apk add --no-cache 'ca-certificates>=20261020-r0' # Set default NODE_ENV to production unless overridden at build time with --build-arg NODE_ENV=development ARG NODE_ENV @@ -145,7 +148,8 @@ RUN npm run build:prod ############################ FILE SERVER ############################ -FROM docker.io/node:24-alpine +FROM docker.io/node:24.22.1-alpine +RUN apk add --no-cache 'ca-certificates>=20261020-r0' # Set default NODE_ENV to production unless overridden at build time with --build-arg NODE_ENV=development ARG NODE_ENV diff --git a/file-server/nginx.Dockerfile b/file-server/nginx.Dockerfile index 9d26abecc..fcf3293ba 100644 --- a/file-server/nginx.Dockerfile +++ b/file-server/nginx.Dockerfile @@ -1,5 +1,11 @@ FROM docker.io/nginx:1.21.5-alpine +# Mozilla's October 2026 eMudhra advisory includes the Sectigo cross-sign path. +RUN apk add --no-cache ca-certificates \ + && sed -i -e 's|^mozilla/emSign_ECC_Root_CA_-_G3.crt|!&|' \ + -e 's|^mozilla/Comodo_AAA_Services_root.crt|!&|' /etc/ca-certificates.conf \ + && update-ca-certificates + # Copy config as template COPY nginx/nginx-ssl.site.default.conf /etc/nginx/conf.d/default.conf.template diff --git a/math/Dockerfile b/math/Dockerfile index 165206042..d95b3a5ca 100644 --- a/math/Dockerfile +++ b/math/Dockerfile @@ -1,4 +1,12 @@ -FROM docker.io/clojure:temurin-17-tools-deps +FROM docker.io/clojure:temurin-17-tools-deps AS trust +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \ + && sed -i -e 's|^mozilla/emSign_ECC_Root_CA_-_G3.crt|!&|' \ + -e 's|^mozilla/Comodo_AAA_Services_root.crt|!&|' /etc/ca-certificates.conf \ + && update-ca-certificates && rm -rf /var/lib/apt/lists/* +COPY distrust-ca.sh /tmp/distrust-ca.sh +RUN sh /tmp/distrust-ca.sh && rm /tmp/distrust-ca.sh + +FROM trust AS runtime WORKDIR /app COPY . . diff --git a/math/distrust-ca.sh b/math/distrust-ca.sh new file mode 100644 index 000000000..437951efc --- /dev/null +++ b/math/distrust-ca.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Remove the four alternate anchors identified in the October 2026 CA disclosure. +set -eu +listing=$(mktemp) +aliases=$(mktemp) +trap 'rm -f "$listing" "$aliases"' EXIT +list_blocked() { + keytool -J-Duser.language=en -list -v -cacerts -storepass changeit > "$listing" + grep -q '^Alias name:' "$listing" + awk ' + /^Alias name:/ {alias=substr($0,13)} + /SHA256:/ { + hash=$0; sub(/^.*SHA256: */,"",hash); gsub(/:/,"",hash) + if (hash == "86A1ECBA089C4A8D3BBE2734C612BA341D813E043CF9E8A862CD5C57A36BBE6B" || + hash == "D7A7A0FB5D7E2731D771E9484EBCDEF71D5F0C3E0A2948782BC83EE0EA699EF4" || + hash == "7DD78D5F4F13459A83DFF9ABBBA62EDBAF6F2D102BF257FD712F4D9F2746ED8D" || + hash == "F2EDAAFF3D9B701FB4D14C9F285F8C0BAD90FC3BCC1FA07D47F4718EDABA34A5") print alias + }' "$listing" +} +list_blocked > "$aliases" +while IFS= read -r alias; do + keytool -delete -cacerts -storepass changeit -alias "$alias" +done < "$aliases" +list_blocked > "$aliases" +test ! -s "$aliases" diff --git a/oidc-simulator/Dockerfile b/oidc-simulator/Dockerfile index 70b4d478e..9faa0f5f1 100644 --- a/oidc-simulator/Dockerfile +++ b/oidc-simulator/Dockerfile @@ -1,9 +1,9 @@ # syntax=docker/dockerfile:1.4 # Use an official Node.js runtime as a parent image -FROM node:24-slim +FROM node:24.22.1-bookworm-slim # Install curl for health checks, openssl for certificate generation, and create certificate directory -RUN apt-get update && apt-get install -y curl openssl && rm -rf /var/lib/apt/lists/* && \ +RUN apt-get update && apt-get install -y curl openssl ca-certificates=20250419~deb12u2 && rm -rf /var/lib/apt/lists/* && \ mkdir -p /root/.simulacrum/certs # Set the working directory in the container diff --git a/polis-cli/Cargo.lock b/polis-cli/Cargo.lock index 8a4c68e44..f209dd4bb 100644 --- a/polis-cli/Cargo.lock +++ b/polis-cli/Cargo.lock @@ -776,8 +776,11 @@ dependencies = [ "flate2", "polis-contracts", "reqwest", + "rustls-pki-types", + "rustls-webpki", "serde_json", "url", + "webpki-roots", ] [[package]] @@ -1003,9 +1006,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.15" +version = "0.103.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" dependencies = [ "ring", "rustls-pki-types", @@ -1528,9 +1531,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" dependencies = [ "rustls-pki-types", ] diff --git a/polis-cli/crates/polis-client/Cargo.toml b/polis-cli/crates/polis-client/Cargo.toml index 6913187bf..66d934099 100644 --- a/polis-cli/crates/polis-client/Cargo.toml +++ b/polis-cli/crates/polis-client/Cargo.toml @@ -9,3 +9,9 @@ serde_json.workspace = true reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "rustls-tls"] } url = "2" flate2 = "1" +# Root removal and intermediate-key distrust from the October 2026 CA advisory. +webpki-roots = "=1.0.10" +rustls-webpki = "=0.103.16" + +[dev-dependencies] +rustls-pki-types = { version = "1", features = ["std"] } diff --git a/polis-cli/crates/polis-client/tests/tls_roots.rs b/polis-cli/crates/polis-client/tests/tls_roots.rs new file mode 100644 index 000000000..90116ea27 --- /dev/null +++ b/polis-cli/crates/polis-client/tests/tls_roots.rs @@ -0,0 +1,74 @@ +#[test] +fn compromised_ca_paths_are_not_trust_anchors() { + use rustls_pki_types::{pem::PemObject, CertificateDer}; + let mut certificates: Vec<_> = CertificateDer::pem_slice_iter(include_bytes!( + "../../../../ci/tls/fixtures/affected-roots.pem" + )) + .map(|c| c.unwrap()) + .collect(); + certificates.extend( + CertificateDer::pem_slice_iter(include_bytes!( + "../../../../ci/tls/fixtures/affected-intermediates.pem" + )) + .map(|c| c.unwrap()), + ); + assert_eq!(certificates.len(), 20); + let blocked: Vec<_> = certificates + .iter() + .map(|c| webpki::anchor_from_trusted_cert(c).unwrap()) + .collect(); + assert!(webpki_roots::TLS_SERVER_ROOTS.len() > 100); + for anchor in webpki_roots::TLS_SERVER_ROOTS { + // Compare parsed SPKIs in the same representation. The anchor stores + // sequence contents, whereas published hashes cover the full DER SPKI. + assert!(!blocked + .iter() + .any(|bad| { bad.subject_public_key_info == anchor.subject_public_key_info })); + } +} + +#[test] +fn compromised_intermediates_are_blocked_even_with_old_custom_roots() { + use rustls_pki_types::{pem::PemObject, CertificateDer, UnixTime}; + use std::time::Duration; + let fixtures = + std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../ci/tls/fixtures"); + let root_pem = std::fs::read(fixtures.join("affected-roots.pem")).unwrap(); + let roots: Vec<_> = CertificateDer::pem_slice_iter(&root_pem) + .map(|c| c.unwrap()) + .collect(); + let anchors: Vec<_> = roots + .iter() + .map(|c| webpki::anchor_from_trusted_cert(c).unwrap()) + .collect(); + let mut count = 0; + for entry in std::fs::read_dir(&fixtures).unwrap() { + let path = entry.unwrap().path(); + if !path + .to_string_lossy() + .ends_with("we-have-a-problem.com.pem") + { + continue; + } + let pem = std::fs::read(&path).unwrap(); + let chain: Vec<_> = CertificateDer::pem_slice_iter(&pem) + .map(|c| c.unwrap()) + .collect(); + let leaf = webpki::EndEntityCert::try_from(&chain[0]).unwrap(); + let error = leaf + .verify_for_usage( + webpki::ALL_VERIFICATION_ALGS, + &anchors, + &chain[1..], + UnixTime::since_unix_epoch(Duration::from_secs(1792540800)), + webpki::KeyUsage::server_auth(), + None, + None, + ) + .err() + .expect("compromised chain must be rejected"); + assert_eq!(error, webpki::Error::CertDistrusted, "{}", path.display()); + count += 1; + } + assert_eq!(count, 12); +} diff --git a/queue-rs/polis-api/Dockerfile b/queue-rs/polis-api/Dockerfile index 25c336944..bf27513e2 100644 --- a/queue-rs/polis-api/Dockerfile +++ b/queue-rs/polis-api/Dockerfile @@ -4,7 +4,7 @@ # image has no way to fake the clock. FROM docker.io/library/rust:1.98.1-slim-trixie AS build RUN apt-get update \ - && apt-get install -y --no-install-recommends pkg-config libssl-dev \ + && apt-get install -y --no-install-recommends pkg-config libssl-dev ca-certificates=20250419+deb13u1 \ && rm -rf /var/lib/apt/lists/* WORKDIR /src COPY . . @@ -14,7 +14,7 @@ RUN cargo build --release --locked -p polis-api ${FEATURES:+--features "$FEATURE FROM docker.io/library/debian:trixie-slim RUN apt-get update \ - && apt-get install -y --no-install-recommends libssl3t64 ca-certificates \ + && apt-get install -y --no-install-recommends libssl3t64 ca-certificates=20250419+deb13u1 \ && rm -rf /var/lib/apt/lists/* COPY --from=build /polis-api /usr/local/bin/polis-api # As the server image's prod target: production unless built otherwise, and diff --git a/queue-rs/polis-migrate/Dockerfile b/queue-rs/polis-migrate/Dockerfile index 45eeed2d7..d16ac49e9 100644 --- a/queue-rs/polis-migrate/Dockerfile +++ b/queue-rs/polis-migrate/Dockerfile @@ -1,6 +1,6 @@ # Build from repository root. One binary for deploys and manual/local upgrades. FROM docker.io/library/rust:1.98.1-slim-bookworm AS build -RUN apt-get update && apt-get install -y --no-install-recommends pkg-config libssl-dev curl ca-certificates \ +RUN apt-get update && apt-get install -y --no-install-recommends pkg-config libssl-dev curl ca-certificates=20250419~deb12u2 \ && rm -rf /var/lib/apt/lists/* # Public RDS truststore retrieved over HTTPS 2026-10-09; checksum pins its bytes. RUN curl --fail --location --proto '=https' --tlsv1.2 https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem -o /rds-ca.pem \ @@ -9,7 +9,7 @@ WORKDIR /src COPY queue-rs/ ./ RUN cargo build --release --locked -p polis-migrate FROM docker.io/library/debian:bookworm-slim -RUN apt-get update && apt-get install -y --no-install-recommends libssl3 ca-certificates \ +RUN apt-get update && apt-get install -y --no-install-recommends libssl3 ca-certificates=20250419~deb12u2 \ && rm -rf /var/lib/apt/lists/* COPY --from=build /src/target/release/polis-migrate /usr/local/bin/polis-migrate COPY server/postgres/migrations /migrations diff --git a/server/Dockerfile b/server/Dockerfile index b1d5c63f4..7e69e0795 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -11,7 +11,7 @@ # For a dev build, use `--target dev`. # Should default to prod build, but you can also explicitly use `--target prod` -FROM docker.io/node:22-alpine as base +FROM docker.io/node:22.23.4-alpine as base ARG NODE_ENV @@ -19,7 +19,7 @@ WORKDIR /app # Install Python and necessary tools (including pip) -RUN apk add --no-cache python3 py3-pip ca-certificates +RUN apk add --no-cache python3 py3-pip 'ca-certificates>=20261020-r0' # Verified startup migration checks use the same public RDS CA pin as the # runner image. Deployments with another private CA can override this env. @@ -72,7 +72,7 @@ FROM base as prod ENV NODE_ENV ${NODE_ENV:-production} # Install OpenSSL and CA Certificates (CRITICAL for production) -RUN apk add --no-cache openssl ca-certificates +RUN apk add --no-cache openssl 'ca-certificates>=20261020-r0' RUN npm config set fetch-retries 5 && \ npm config set fetch-retry-mintimeout 20000 && \ diff --git a/server/Dockerfile-db b/server/Dockerfile-db index 3d1e57bda..445b43161 100644 --- a/server/Dockerfile-db +++ b/server/Dockerfile-db @@ -1,12 +1,12 @@ # Build with --build-context queue-rs=queue-rs (Compose supplies it). # New volumes use the same runner/history as every later deploy. FROM docker.io/library/rust:1.98.1-alpine AS migrate-build -RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static pkgconfig +RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static pkgconfig 'ca-certificates>=20261020-r0' WORKDIR /src COPY --from=queue-rs . . RUN cargo build --release --locked -p polis-migrate FROM postgres:17-alpine -RUN apk add --no-cache libssl3 ca-certificates +RUN apk add --no-cache libssl3 'ca-certificates>=20261020-r0' COPY --from=migrate-build /src/target/release/polis-migrate /usr/local/bin/polis-migrate COPY ./postgres/migrations /migrations COPY ./postgres/init-migrations.sh /docker-entrypoint-initdb.d/00-migrations.sh diff --git a/server/Dockerfile-pdb b/server/Dockerfile-pdb index f25052e88..84e84a7d9 100644 --- a/server/Dockerfile-pdb +++ b/server/Dockerfile-pdb @@ -1,5 +1,6 @@ # FROM postgis/postgis:17-3.5 FROM postgres:17-alpine +RUN apk add --no-cache 'ca-certificates>=20261020-r0' COPY init-db.sh /docker-entrypoint-initdb.d/init-db.sh RUN chmod +x /docker-entrypoint-initdb.d/init-db.sh diff --git a/server/characterization/Dockerfile b/server/characterization/Dockerfile index 3e33aa0be..074c4999e 100644 --- a/server/characterization/Dockerfile +++ b/server/characterization/Dockerfile @@ -1,9 +1,10 @@ FROM rust:1.98.1-bookworm AS migrate-build +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates=20250419~deb12u2 && rm -rf /var/lib/apt/lists/* WORKDIR /src COPY queue-rs/ . RUN cargo build --locked --release -p polis-migrate -FROM node:22-bookworm-slim -RUN apt-get update && apt-get install -y --no-install-recommends libssl3 ca-certificates && rm -rf /var/lib/apt/lists/* +FROM node:22.23.4-bookworm-slim +RUN apt-get update && apt-get install -y --no-install-recommends libssl3 ca-certificates=20250419~deb12u2 && rm -rf /var/lib/apt/lists/* COPY --from=migrate-build /src/target/release/polis-migrate /usr/local/bin/polis-migrate ENV POLIS_MIGRATE_BIN=/usr/local/bin/polis-migrate diff --git a/server/mise.toml b/server/mise.toml index 6a0493c69..b835fd398 100644 --- a/server/mise.toml +++ b/server/mise.toml @@ -1,2 +1,2 @@ [tools] -node = "22" +node = "22.23.4" From 196557177a2438c5ee28f70d4d644db7cb56b2e6 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Thu, 22 Oct 2026 20:46:30 -0700 Subject: [PATCH 25/30] client-admin: a failed seed CSV upload shows its error and re-enables the form (#3258) The bulk seed upload's rejection handler was never attached to the request, so a failed POST /api/v3/comments-bulk left the form on "Saving..." with nothing shown. It now dispatches the existing error action: the form leaves its loading state and shows the server's message, and a retry works. A component test covers success and failure. Co-authored-by: Claude Opus 5.5 --- client-admin/src/actions/index.js | 6 +- .../ModerateCommentSeed.upload.test.js | 122 ++++++++++++++++++ 2 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 client-admin/src/components/conversation-admin/ModerateCommentSeed.upload.test.js diff --git a/client-admin/src/actions/index.js b/client-admin/src/actions/index.js index 24d36ed31..3306c51cc 100644 --- a/client-admin/src/actions/index.js +++ b/client-admin/src/actions/index.js @@ -304,11 +304,11 @@ const postBulkSeedComments = (commentsCSV) => { export const handleBulkSeedCommentSubmit = (commentsCSV, cb) => { return (dispatch) => { dispatch(submitSeedCommentStart()) - return ( - postBulkSeedComments(commentsCSV).then((res) => { + return postBulkSeedComments(commentsCSV).then( + (res) => { if (cb) cb() return dispatch(submitSeedCommentPostSuccess(res)) - }), + }, (err) => dispatch(submitSeedCommentPostError(err)) ) } diff --git a/client-admin/src/components/conversation-admin/ModerateCommentSeed.upload.test.js b/client-admin/src/components/conversation-admin/ModerateCommentSeed.upload.test.js new file mode 100644 index 000000000..1ce636cc3 --- /dev/null +++ b/client-admin/src/components/conversation-admin/ModerateCommentSeed.upload.test.js @@ -0,0 +1,122 @@ +import { configureStore } from '@reduxjs/toolkit' +import { Provider } from 'react-redux' +import { act, fireEvent, render, screen, waitFor } from '@testing-library/react' +import { ThemeUIProvider } from 'theme-ui' + +import ModerateCommentsSeed from './ModerateCommentSeed' +import seedComments from '../../reducers/seed_comments' +import PolisNet from '../../util/net' +import theme from '../../theme' + +jest.mock('../../util/net', () => ({ + __esModule: true, + default: { polisPost: jest.fn() } +})) + +const csv = 'comment_text\nA seed comment for the upload test' + +const prepareUpload = async (onComplete) => { + const store = configureStore({ reducer: { seed_comments: seedComments } }) + render( + + + + + + ) + + const button = screen.getByTestId('upload-csv-button') + expect(button).toBeDisabled() + fireEvent.change(document.getElementById('csvFile'), { + target: { files: [new File([csv], 'seed-comments.csv', { type: 'text/csv' })] } + }) + await waitFor(() => expect(button).toBeEnabled()) + return { button, store } +} + +describe('seed CSV upload with real actions and reducer', () => { + beforeEach(() => { + jest.resetAllMocks() + }) + + it('shows the server error, re-enables submission, and allows a successful retry', async () => { + let rejectUpload + PolisNet.polisPost.mockReturnValueOnce( + new Promise((resolve, reject) => { + rejectUpload = reject + }) + ) + const onComplete = jest.fn() + const { button, store } = await prepareUpload(onComplete) + + fireEvent.click(button) + expect(button).toBeDisabled() + expect(button).toHaveTextContent('Saving...') + expect(PolisNet.polisPost).toHaveBeenCalledWith('/api/v3/comments-bulk', { + csv, + conversation_id: 'test-conversation', + is_seed: true + }) + + const responseText = 'The seed CSV could not be imported.' + await act(async () => { + rejectUpload({ status: 500, responseText }) + }) + + expect(screen.getByText(responseText)).toBeInTheDocument() + expect(button).toBeEnabled() + expect(button).toHaveTextContent('Submit') + expect(store.getState().seed_comments).toMatchObject({ + loading: false, + error: responseText, + success: false + }) + expect(onComplete).not.toHaveBeenCalled() + + PolisNet.polisPost.mockResolvedValueOnce({}) + fireEvent.click(button) + expect(screen.queryByText(responseText)).not.toBeInTheDocument() + await waitFor(() => expect(button).toHaveTextContent('Success!')) + expect(button).toBeEnabled() + expect(PolisNet.polisPost).toHaveBeenCalledTimes(2) + expect(onComplete).toHaveBeenCalledTimes(1) + }) + + it.each([true, false])( + 'completes a successful upload (callback provided: %s)', + async (withCallback) => { + let resolveUpload + PolisNet.polisPost.mockReturnValueOnce( + new Promise((resolve) => { + resolveUpload = resolve + }) + ) + const onComplete = withCallback ? jest.fn() : undefined + const { button, store } = await prepareUpload(onComplete) + + fireEvent.click(button) + expect(button).toBeDisabled() + expect(button).toHaveTextContent('Saving...') + if (onComplete) expect(onComplete).not.toHaveBeenCalled() + + await act(async () => { + resolveUpload({}) + }) + + expect(button).toHaveTextContent('Success!') + expect(button).toBeEnabled() + expect(store.getState().seed_comments).toMatchObject({ + loading: false, + error: false, + success: true + }) + if (onComplete) expect(onComplete).toHaveBeenCalledTimes(1) + } + ) +}) From 1f7a9908164d31d49932213c5b770370af57daad Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Sat, 24 Oct 2026 09:41:26 -0700 Subject: [PATCH 26/30] next comment: every eligible comment can be routed, not only the oldest 999 (#3261) Ordinary routing ordered a participant's eligible, unvoted comments by creation and kept the first 999 before the weighted draw, a default limit from 2013 meant for the comments list. In a conversation with more than 999 such comments, later ones could never be offered until the participant had voted on older ones. Node and the Rust route now draw the same weighted lottery over the ids of every eligible comment and then read only the chosen row, so a vote does not pull every candidate's text. The public comments list keeps its existing default. Node and Rust stay byte-identical for the same database state and draw. Co-authored-by: Claude Opus 5.5 --- queue-rs/polis-api/src/next_comment.rs | 93 +- .../next-comment-cap.pgtest.ts | 242 +++ server/__tests__/unit/initialComment.test.ts | 7 + .../unit/nextCommentTranslation.test.ts | 7 + .../unit/pcaLatestExistingHttp.test.ts | 4 + .../routing/expected-differences.json | 1334 +++++++++++++---- server/src/comment.ts | 71 +- server/src/nextComment.ts | 40 +- 8 files changed, 1419 insertions(+), 379 deletions(-) create mode 100644 server/__tests__/participation-pg/next-comment-cap.pgtest.ts diff --git a/queue-rs/polis-api/src/next_comment.rs b/queue-rs/polis-api/src/next_comment.rs index 942bc755b..a3e7a0d81 100644 --- a/queue-rs/polis-api/src/next_comment.rs +++ b/queue-rs/polis-api/src/next_comment.rs @@ -136,16 +136,11 @@ fn draw(req: &Request) -> f64 { let _ = req; rand::random::() } -fn select(rows: &[Js], priorities: Option<&Obj>, unit: f64) -> Result<(usize, f64)> { +fn select(tids: &[i32], priorities: Option<&Obj>, unit: f64) -> Result<(usize, f64)> { let mut cumulative = Vec::new(); let mut total = 0.0; - for row in rows { - let tid = row - .as_obj() - .and_then(|r| r.get("tid")) - .ok_or_else(|| anyhow::anyhow!("missing tid"))? - .to_js_string(); - let weight = match priorities.and_then(|p| p.get(&tid)) { + for tid in tids { + let weight = match priorities.and_then(|p| p.get(&tid.to_string())) { None | Some(Js::Null) | Some(Js::Bool(false)) => 1.0, Some(Js::Num(n)) if *n == 0.0 => 1.0, Some(Js::Num(n)) if n.is_finite() => *n, @@ -206,14 +201,16 @@ fn read( } else { q.without }; - // Preserve Node's created-only order, cap, and comment projection. No - // participant resolution runs here; initial eligibility retains Node's - // negative participant sentinel when reading existing votes. - let rows = c.query(&format!("select * from comments where zid=$1 AND active=true AND velocity>0 AND (($2::boolean AND mod=1) OR (NOT $2::boolean AND mod != {REJECTED_COMMENT_MOD})) AND NOT(tid=ANY($3::integer[])) AND ($4::integer IS NULL OR (tid=$4 AND tid NOT IN (select tid from votes_latest_unique where zid=$1 AND pid=$5))) AND ($6::integer IS NULL OR tid NOT IN (select tid from votes_latest_unique where zid=$1 AND pid=$6)) order by created limit 999"), &[&zid,&strict,&without,&q.initial,&pid.unwrap_or(ANONYMOUS_PARTICIPANT_ID),&pid])?; - let rows = rows + // Preserve Node's filters and created-only order. Like Node, read only the + // ids of every eligible comment (no row limit) and, after the draw, only + // the chosen comment's row. No participant resolution runs here; initial + // eligibility retains Node's negative participant sentinel when reading + // existing votes. + let tids = c.query(&format!("select tid from comments where zid=$1 AND active=true AND velocity>0 AND (($2::boolean AND mod=1) OR (NOT $2::boolean AND mod != {REJECTED_COMMENT_MOD})) AND NOT(tid=ANY($3::integer[])) AND ($4::integer IS NULL OR (tid=$4 AND tid NOT IN (select tid from votes_latest_unique where zid=$1 AND pid=$5))) AND ($6::integer IS NULL OR tid NOT IN (select tid from votes_latest_unique where zid=$1 AND pid=$6)) order by created"), &[&zid,&strict,&without,&q.initial,&pid.unwrap_or(ANONYMOUS_PARTICIPANT_ID),&pid])?; + let tids = tids .iter() - .map(comments::project) - .collect::>>()?; + .map(|r| r.try_get::<_, i32>(0)) + .collect::, _>>()?; // Node awaits its parallel math/count reads even when the candidate list // is empty. Preserve failure handoff instead of manufacturing an empty 200. let data = if q.initial.is_none() { @@ -221,14 +218,14 @@ fn read( } else { None }; - let counts = if q.initial.is_none() || !rows.is_empty() { + let counts = if q.initial.is_none() || !tids.is_empty() { let counts = c.query_one("WITH v AS (select * from votes_latest_unique where zid=$1 AND pid=$2), c AS (select * from get_visible_comments($1)), remaining AS (select count(*) AS n from c LEFT JOIN v ON c.tid=v.tid WHERE v.vote IS NULL), total AS (select count(*) AS n from c) SELECT remaining.n::integer,total.n::integer FROM remaining,total", &[&zid,&pid.or_else(|| q.initial.map(|_| ANONYMOUS_PARTICIPANT_ID))])?; Some((counts.try_get::<_, i32>(0)?, counts.try_get::<_, i32>(1)?)) } else { None }; let mut empty = Obj::new(); - if rows.is_empty() { + if tids.is_empty() { if let Some(pid) = pid { empty.set("currentPid", Js::Num(f64::from(pid))); } @@ -253,10 +250,16 @@ fn read( .and_then(Js::as_obj) .and_then(|o| o.get("comment-priorities")) .and_then(Js::as_obj); - let (i, r) = select(&rows, priorities, unit)?; + let (i, r) = select(&tids, priorities, unit)?; (i, Some(r)) }; - let mut selected = rows[index] + let row = c + .query_opt( + "select * from comments where zid=$1 and tid=$2", + &[&zid, &tids[index]], + )? + .ok_or_else(|| anyhow::anyhow!("selected comment missing"))?; + let mut selected = comments::project(&row)? .as_obj() .cloned() .ok_or_else(|| anyhow::anyhow!("invalid comment"))?; @@ -357,14 +360,11 @@ mod tests { } #[test] fn weighted_selection_preserves_zero_fallback_and_random_value() { - let rows = vec![ - js::parse(r#"{"tid":0}"#).unwrap(), - js::parse(r#"{"tid":1}"#).unwrap(), - ]; + let tids = [0, 1]; let p = js::parse(r#"{"0":0,"1":3}"#).unwrap(); - assert_eq!(select(&rows, p.as_obj(), 0.0).unwrap(), (0, 0.0)); - assert_eq!(select(&rows, p.as_obj(), 0.25).unwrap(), (1, 1.0)); - assert_eq!(select(&rows, None, 0.75).unwrap(), (1, 1.5)); + assert_eq!(select(&tids, p.as_obj(), 0.0).unwrap(), (0, 0.0)); + assert_eq!(select(&tids, p.as_obj(), 0.25).unwrap(), (1, 1.0)); + assert_eq!(select(&tids, None, 0.75).unwrap(), (1, 1.5)); } #[cfg(feature = "db-tests")] #[test] @@ -481,6 +481,47 @@ mod tests { c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) .unwrap(); } + #[cfg(feature = "db-tests")] + #[test] + fn ordinary_reads_draw_from_every_eligible_comment() { + let url = std::env::var("POLIS_API_TEST_DATABASE_URL").unwrap(); + let mut c = Client::connect(&url, postgres::NoTls).unwrap(); + let schema = format!("next_all_test_{}", std::process::id()); + c.batch_execute(&format!("CREATE SCHEMA {schema}; SET search_path={schema}; + CREATE TABLE zinvites(zid integer,zinvite text); CREATE TABLE conversations(zid integer,strict_moderation boolean); + CREATE TABLE comments(zid integer,tid integer,txt text,created bigint,quote_src_url text,is_seed boolean,is_meta boolean,lang text,pid integer,original_id uuid,active boolean,velocity real,mod integer); + CREATE TABLE votes_latest_unique(zid integer,pid integer,tid integer,vote integer); + CREATE TABLE math_main(zid integer,math_env text,math_tick bigint,data jsonb); + CREATE FUNCTION get_visible_comments(integer) RETURNS TABLE(tid integer) LANGUAGE SQL AS 'select tid from comments where zid=$1 AND active=true AND mod>=0'; + INSERT INTO zinvites VALUES(1,'large'); INSERT INTO conversations VALUES(1,false); + INSERT INTO comments SELECT 1,t,'generated '||t,1700000000000+t,null,false,false,'en',0,null,true,1,0 FROM generate_series(0,1199) t;")).unwrap(); + let mut next = |s: &str, unit: f64| { + read( + &mut c, + Query::parse(&request(s)).unwrap(), + "test", + unit, + &Priorities::new(10), + None, + ) + .unwrap() + .unwrap() + }; + // 1,200 equal weights: comments past the oldest 999 can be drawn. + let v = next("conversation_id=large", 0.9999); + let o = v.as_obj().unwrap(); + assert_eq!(o.get("tid"), Some(&Js::Num(1199.0))); + assert_eq!(o.get("txt"), Some(&Js::Str("generated 1199".into()))); + assert_eq!(o.get("randomN"), Some(&Js::Num(0.9999 * 1200.0))); + assert_eq!(o.get("remaining"), Some(&Js::Num(1200.0))); + assert_eq!(o.get("total"), Some(&Js::Num(1200.0))); + let v = next("conversation_id=large", 0.5); + assert_eq!(v.as_obj().unwrap().get("tid"), Some(&Js::Num(600.0))); + let v = next("conversation_id=large&without=1199", 0.9999); + assert_eq!(v.as_obj().unwrap().get("tid"), Some(&Js::Num(1198.0))); + c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) + .unwrap(); + } // A fixed CPU workload measures scheduling contention without calling any // database/read code. Thread CPU time calibrates its uncontended baseline // on this machine, so a read-path regression cannot move the threshold. diff --git a/server/__tests__/participation-pg/next-comment-cap.pgtest.ts b/server/__tests__/participation-pg/next-comment-cap.pgtest.ts new file mode 100644 index 000000000..2584711c6 --- /dev/null +++ b/server/__tests__/participation-pg/next-comment-cap.pgtest.ts @@ -0,0 +1,242 @@ +/** Ordinary next-comment routing draws from every eligible unvoted comment, + * not only the oldest 999. The plain comment list (GET /api/v3/comments with + * no limit) keeps its default of 999 rows, and its random ordering is + * unchanged. + * + * Generated data only. Needs DATABASE_URL (superuser, migrated); see + * scripts/test-delphi-result-reads.sh. + */ +import { Client } from "pg"; +import { getComments, getNextCommentCandidates } from "../../src/comment"; +import { + checkInitialComment, + getNextComment, + getNextTopicalComment, +} from "../../src/nextComment"; +import { + semanticToStorage, + storageToSemantic, +} from "../../src/votes/convention"; +import { onParticipationPools } from "../../src/db/participation-scope"; +import { + conversation, + postgres, + publish, + ENV, + SCOPE, +} from "../delphi-results-pg/support"; + +const ZID = 9650, + PID = 0, + COUNT = 1200; +const topicKey = "00000000-0000-4000-8000-000000009650#0#0"; +let db: Client; +const sequence = (start: number, count: number) => + Array.from({ length: count }, (_, i) => start + i); +const participating = (work: () => Promise): Promise => + new Promise((resolve, reject) => { + onParticipationPools(undefined, undefined, () => { + work().then(resolve, reject); + }); + }); +// The plain comment list, as GET /api/v3/comments reads it. +const listed = (extra = {}) => + participating(() => + getComments({ zid: ZID, not_voted_by_pid: PID, ...extra }) + ); +// The ordinary next-comment draw's candidates. +const routed = (extra = {}) => + participating(() => + getNextCommentCandidates({ zid: ZID, not_voted_by_pid: PID, ...extra }) + ); +const next = (without?: number[]) => + participating(() => getNextComment(ZID, PID, without)); +const ids = (rows: { tid: number }[]) => rows.map((r) => r.tid); +async function vote(first: number, last: number) { + const stored = semanticToStorage("agree"); + await db.query( + `INSERT INTO votes(zid,pid,tid,vote) + SELECT $1,$2,t,$3 FROM generate_series($4::int,$5::int) t`, + [ZID, PID, stored, first, last] + ); + const row = ( + await db.query( + "SELECT vote FROM votes_latest_unique WHERE zid=$1 AND pid=$2 AND tid=$3", + [ZID, PID, first] + ) + ).rows[0]; + expect(storageToSemantic(row.vote)).toBe("agree"); +} + +beforeAll(async () => { + process.env.TOPICAL_COMMENT_RATIO = "0"; + process.env.DELPHI_RESULT_BACKEND = "postgres"; + process.env.DELPHI_RESULT_ENV = ENV; + process.env.DELPHI_RESULT_SCOPE = SCOPE; + db = await postgres(); + await conversation(db, ZID); + await db.query( + "UPDATE conversations SET strict_moderation=false, prioritize_seed=false WHERE zid=$1", + [ZID] + ); + // Explicit monotonically increasing timestamps make the created order + // deterministic. Replica mode bypasses number allocation only for generated + // comments/participants, never for votes. + await db.query("SET session_replication_role = replica"); + try { + await db.query("DELETE FROM comments WHERE zid=$1", [ZID]); + await db.query( + "INSERT INTO participants(zid,pid,uid) VALUES($1,$2,$1) ON CONFLICT(zid,pid) DO NOTHING", + [ZID, PID] + ); + await db.query( + `INSERT INTO comments(zid,pid,uid,tid,created,txt,mod,active,velocity,is_seed) + SELECT $1,$2,$1,t,1700000000000::bigint+t,'generated comment ' || t,0,true,1,false + FROM generate_series(0,$3::int-1) t`, + [ZID, PID, COUNT] + ); + } finally { + await db.query("SET session_replication_role = origin"); + } + await publish(db, { + zid: ZID, + families: { + Delphi_CommentClustersLLMTopicNames: [ + { + conversation_id: { S: String(ZID) }, + topic_key: { S: topicKey }, + layer_id: { N: "0" }, + cluster_id: { N: "0" }, + }, + ], + Delphi_CommentHierarchicalClusterAssignments: sequence(1100, 100).map( + (t) => ({ + conversation_id: { S: String(ZID) }, + comment_id: { N: String(t) }, + layer0_cluster_id: { N: "0" }, + }) + ), + }, + }); + await db.query( + `INSERT INTO topic_agenda_selections(zid,pid,archetypal_selections,total_selections) + VALUES($1,$2,$3,1) ON CONFLICT(zid,pid) DO UPDATE SET archetypal_selections=EXCLUDED.archetypal_selections`, + [ZID, PID, JSON.stringify([{ topic_key: topicKey }])] + ); +}); +beforeEach(async () => { + await db.query("DELETE FROM votes WHERE zid=$1", [ZID]); + await db.query("DELETE FROM votes_latest_unique WHERE zid=$1", [ZID]); + await db.query("UPDATE comments SET is_seed=false WHERE zid=$1", [ZID]); + await db.query( + "UPDATE conversations SET prioritize_seed=false WHERE zid=$1", + [ZID] + ); +}); +afterEach(() => jest.restoreAllMocks()); +afterAll(async () => { + await db?.end(); +}); + +test("every eligible comment enters the ordinary draw; the plain list still stops at 999", async () => { + expect(ids(await routed())).toEqual(sequence(0, COUNT)); + expect(ids(await listed())).toEqual(sequence(0, 999)); + jest.spyOn(Math, "random").mockReturnValue(0.999999); + const last = await next(); + expect(last.tid).toBe(1199); + expect(last.remaining).toBe(COUNT); + expect(last.total).toBe(COUNT); + await vote(0, 0); + expect(ids(await routed())).toEqual(sequence(1, COUNT - 1)); + expect((await next()).tid).toBe(1199); + jest.spyOn(Math, "random").mockReturnValue(0); + expect((await next()).tid).toBe(1); + await vote(1, 1198); + expect(ids(await routed())).toEqual([1199]); + expect((await next()).tid).toBe(1199); + await vote(1199, 1199); + expect(await routed()).toEqual([]); + expect(await next()).toBeNull(); + process.stdout.write( + "DRAW: fresh=0..1199 (near-1 draw 1199); after 1 vote=1..1199; plain list=0..998\n" + ); +}); + +test("the offered comment has the plain list's columns and key order", async () => { + jest.spyOn(Math, "random").mockReturnValue(0.5); + const offered = (await next()) as unknown as Record; + expect(offered.tid).toBe(600); + expect(offered.randomN).toBe(0.5 * COUNT); + const [row] = await participating(() => + getComments({ zid: ZID, tids: [600] }) + ); + expect(Object.keys(offered)).toEqual([ + ...Object.keys(row), + "randomN", + "remaining", + "total", + "translations", + ]); + for (const key of Object.keys(row)) { + expect(offered[key]).toEqual((row as Record)[key]); + } +}); + +test("random ordering of the plain list happens before its 999 default", async () => { + const a = ids(await listed({ random: true })); + const b = ids(await listed({ random: true })); + expect(a).toHaveLength(999); + expect(a.some((t) => t >= 999)).toBe(true); + expect([...a].sort()).not.toEqual([...b].sort()); + await vote(0, 200); + expect(ids(await listed({ random: true })).sort((x, y) => x - y)).toEqual( + sequence(201, 999) + ); +}); + +test("topical selection reaches its topic; exhaustion falls back to every eligible comment", async () => { + const topical = () => participating(() => getNextTopicalComment(ZID, PID)); + const first = await topical(); + expect(first.tid).toBeGreaterThanOrEqual(1100); + await vote(1100, 1198); + expect((await topical()).tid).toBe(1199); + await vote(1199, 1199); + jest.spyOn(Math, "random").mockReturnValue(0.999999); + expect((await topical()).tid).toBe(1099); + process.stdout.write( + `TOPICAL: fresh=${first.tid}; after 99 topical votes=1199; after exhaustion fallback=1099\n` + ); +}); + +test("seed-first random order of the plain list is unchanged", async () => { + await db.query("UPDATE conversations SET prioritize_seed=true WHERE zid=$1", [ + ZID, + ]); + await db.query("UPDATE comments SET is_seed=true WHERE zid=$1 AND tid<1000", [ + ZID, + ]); + expect((await listed({ random: true })).every((r) => r.tid < 1000)).toBe( + true + ); + expect((await listed({ random: true, limit: 1 }))[0].tid).toBeLessThan(1000); + await vote(0, 1); + const window = await listed({ random: true }); + expect(window).toHaveLength(999); + expect(window.filter((r) => r.tid >= 1000)).toHaveLength(1); + // The ordinary draw has no seed-first order: it is created order, weighted. + expect(ids(await routed())).toEqual(sequence(2, COUNT - 2)); +}); + +test("without excludes before the draw and an initial tid is offered directly", async () => { + const without = sequence(0, 201); + expect(ids(await routed({ withoutTids: without }))).toEqual( + sequence(201, 999) + ); + jest.spyOn(Math, "random").mockReturnValue(0); + expect((await next(without)).tid).toBe(201); + const initial = await participating(() => + checkInitialComment(ZID, PID, 1199) + ); + expect(initial.status).toBe("eligible"); + expect(initial.comment.tid).toBe(1199); +}); diff --git a/server/__tests__/unit/initialComment.test.ts b/server/__tests__/unit/initialComment.test.ts index a9a07397f..3b9183804 100644 --- a/server/__tests__/unit/initialComment.test.ts +++ b/server/__tests__/unit/initialComment.test.ts @@ -7,6 +7,13 @@ const mockQuery = jest.fn(); const mockCounts = jest.fn(); jest.mock("../../src/comment", () => ({ getComments: mockComments, + // The ordinary draw's candidate ids and chosen row come from the same + // fixture rows as the plain list. + getNextCommentCandidates: (params: unknown) => mockComments(params), + getNextCommentRow: async (zid: number, tid: number) => + ((await mockComments({ zid, tids: [tid] })) as { tid: number }[]).find( + (row) => row.tid === tid + ), getNumberOfCommentsRemaining: mockCounts, translateAndStoreComment: jest.fn(), })); diff --git a/server/__tests__/unit/nextCommentTranslation.test.ts b/server/__tests__/unit/nextCommentTranslation.test.ts index 4fac54a87..6032fceee 100644 --- a/server/__tests__/unit/nextCommentTranslation.test.ts +++ b/server/__tests__/unit/nextCommentTranslation.test.ts @@ -50,6 +50,13 @@ jest.mock("../../src/routes/comments", () => ({})); jest.mock("../../src/comment", () => ({ ...jest.requireActual("../../src/comment"), getComments: mockComments, + // The ordinary draw's candidate ids and chosen row come from the same + // fixture rows as the plain list. + getNextCommentCandidates: (params: unknown) => mockComments(params), + getNextCommentRow: async (zid: number, tid: number) => + ((await mockComments({ zid, tids: [tid] })) as { tid: number }[]).find( + (row) => row.tid === tid + ), getNumberOfCommentsRemaining: async () => [{ total: 1, remaining: 1 }], })); diff --git a/server/__tests__/unit/pcaLatestExistingHttp.test.ts b/server/__tests__/unit/pcaLatestExistingHttp.test.ts index 4a9a6412e..8adb80c7a 100644 --- a/server/__tests__/unit/pcaLatestExistingHttp.test.ts +++ b/server/__tests__/unit/pcaLatestExistingHttp.test.ts @@ -87,6 +87,10 @@ const COMMENTS = [ jest.mock("../../src/comment", () => ({ __esModule: true, getComments: () => Promise.resolve(COMMENTS.map((c) => ({ ...c }))), + getNextCommentCandidates: () => + Promise.resolve(COMMENTS.map((c) => ({ tid: c.tid }))), + getNextCommentRow: (_zid: number, tid: number) => + Promise.resolve({ ...COMMENTS.find((c) => c.tid === tid) }), getNumberOfCommentsRemaining: () => Promise.resolve([{ total: 2, remaining: 2 }]), translateAndStoreComment: (c: unknown) => Promise.resolve(c), diff --git a/server/characterization/routing/expected-differences.json b/server/characterization/routing/expected-differences.json index 74357851b..bf520aa5e 100644 --- a/server/characterization/routing/expected-differences.json +++ b/server/characterization/routing/expected-differences.json @@ -3,8 +3,8 @@ { "case": "ordinary/owner-current", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -85,9 +85,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -135,8 +135,8 @@ { "case": "ordinary/owner-all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": null, "sql": [ @@ -157,8 +157,7 @@ "after": { "value": null, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" @@ -168,15 +167,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 5, + "postgresStatements": 4, "dynamoCalls": 0 } }, { "case": "topical/owner-all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": null, "sql": [ @@ -228,15 +227,13 @@ "after": { "value": null, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;", @@ -270,15 +267,15 @@ "draws": [ 0.625 ], - "postgresStatements": 13, + "postgresStatements": 11, "dynamoCalls": 2 } }, { "case": "ordinary/owner-seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 5", @@ -347,9 +344,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -385,8 +382,8 @@ { "case": "topical/owner-seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 5", @@ -480,13 +477,13 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -543,8 +540,8 @@ { "case": "ordinary/owner-seeds-only", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": null, "sql": [ @@ -565,8 +562,7 @@ "after": { "value": null, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" @@ -576,15 +572,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 5, + "postgresStatements": 4, "dynamoCalls": 0 } }, { "case": "topical/owner-seeds-only", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": null, "sql": [ @@ -636,15 +632,13 @@ "after": { "value": null, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;", @@ -678,15 +672,15 @@ "draws": [ 0.625 ], - "postgresStatements": 13, + "postgresStatements": 11, "dynamoCalls": 2 } }, { "case": "ordinary/large-math-cold", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -767,9 +761,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -817,8 +811,8 @@ { "case": "ordinary/large-math-expired", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -899,9 +893,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -949,8 +943,8 @@ { "case": "ordinary/no-topics", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -1031,9 +1025,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -1081,8 +1075,8 @@ { "case": "topical/no-topics", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -1165,10 +1159,10 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -1217,8 +1211,8 @@ { "case": "ordinary/current-job", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -1299,9 +1293,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -1349,8 +1343,8 @@ { "case": "ordinary/older-job-deleted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -1431,9 +1425,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -1481,8 +1475,8 @@ { "case": "topical/older-job-deleted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -1574,10 +1568,10 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -1635,8 +1629,8 @@ { "case": "ordinary/older-job-retained", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -1717,9 +1711,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -1767,8 +1761,8 @@ { "case": "ordinary/empty-picks", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -1849,9 +1843,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -1899,8 +1893,8 @@ { "case": "topical/empty-picks", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -1983,10 +1977,10 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -2035,8 +2029,8 @@ { "case": "ordinary/duplicate-picks", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -2117,9 +2111,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -2167,8 +2161,8 @@ { "case": "ordinary/overlapping-layers", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -2249,9 +2243,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -2299,8 +2293,8 @@ { "case": "ordinary/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": null, "sql": [ @@ -2321,8 +2315,7 @@ "after": { "value": null, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" @@ -2332,15 +2325,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 5, + "postgresStatements": 4, "dynamoCalls": 0 } }, { "case": "topical/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": null, "sql": [ @@ -2392,15 +2385,13 @@ "after": { "value": null, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;", @@ -2434,15 +2425,15 @@ "draws": [ 0.625 ], - "postgresStatements": 13, + "postgresStatements": 11, "dynamoCalls": 2 } }, { "case": "ordinary/topical-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 5", @@ -2511,9 +2502,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -2549,8 +2540,8 @@ { "case": "topical/topical-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 5", @@ -2644,13 +2635,13 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -2707,8 +2698,8 @@ { "case": "ordinary/moderated-out", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 5", @@ -2777,9 +2768,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -2815,8 +2806,8 @@ { "case": "topical/moderated-out", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 5", @@ -2910,13 +2901,13 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -2973,8 +2964,8 @@ { "case": "ordinary/strict", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -3043,9 +3034,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" = 1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" = 1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -3081,8 +3072,8 @@ { "case": "ordinary/inactive-muted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -3155,9 +3146,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -3197,8 +3188,8 @@ { "case": "ordinary/seed-first", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -3279,9 +3270,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -3329,8 +3320,8 @@ { "case": "ordinary/seed-no-priority", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -3411,9 +3402,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -3461,8 +3452,8 @@ { "case": "ordinary/oldest-window", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged All 1005 eligible comments enter the ordinary draw, not only the oldest 999: the same fixed draw (0.625 of the total weight) now chooses tid 794 (randomN 315946.875 of 505515) instead of tid 789 (312187.5 of 499500); the statements change as in the other ordinary cases.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 789", @@ -7500,24 +7491,24 @@ }, "after": { "value": { - "txt": "Generated statement 789", - "tid": 789, - "created": "1700000000789", + "txt": "Generated statement 794", + "tid": 794, + "created": "1700000000794", "quote_src_url": null, "is_seed": false, "is_meta": false, "lang": "en", "pid": 0, "original_id": null, - "randomN": 312187.5, + "randomN": 315946.875, "remaining": 1005, "total": 1005, "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -11523,6 +11514,30 @@ { "tid": 998, "weight": 999 + }, + { + "tid": 999, + "weight": 1000 + }, + { + "tid": 1000, + "weight": 1001 + }, + { + "tid": 1001, + "weight": 1002 + }, + { + "tid": 1002, + "weight": 1003 + }, + { + "tid": 1003, + "weight": 1004 + }, + { + "tid": 1004, + "weight": 1005 } ] } @@ -11537,8 +11552,8 @@ { "case": "ordinary/without", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 5", @@ -11607,9 +11622,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"tid\" NOT IN (0, 2, 4))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"tid\" NOT IN (0, 2, 4))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -11645,8 +11660,8 @@ { "case": "topical/without", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 5", @@ -11740,13 +11755,13 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"tid\" NOT IN (0, 2, 4))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"tid\" NOT IN (0, 2, 4))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"tid\" NOT IN (0, 2, 4))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -11803,8 +11818,8 @@ { "case": "ordinary/translation-hit", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -11906,10 +11921,10 @@ ] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "select * from comment_translations where zid = ($1) and tid = ($2);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -11957,8 +11972,8 @@ { "case": "ordinary/translation-miss", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -12061,11 +12076,11 @@ ] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "insert into comment_translations (zid, tid, txt, lang, src) values ($1, $2, $3, $4, $5) on conflict (zid, tid, src, lang) do update set txt = excluded.txt, modified = now_as_millis() returning *;", "select * from comment_translations where zid = ($1) and tid = ($2);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -12113,8 +12128,8 @@ { "case": "ordinary/translation-off", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -12196,10 +12211,10 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "select * from comment_translations where zid = ($1) and tid = ($2);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -12247,8 +12262,8 @@ { "case": "ordinary/math-absent", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 3", @@ -12329,9 +12344,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -12379,8 +12394,8 @@ { "case": "ordinary/math-generation-zero", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -12461,9 +12476,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -12511,8 +12526,8 @@ { "case": "ordinary/math-cache-expired", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -12593,9 +12608,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -12643,8 +12658,8 @@ { "case": "ordinary/math-old-generation", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -12725,9 +12740,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -12775,8 +12790,8 @@ { "case": "ordinary/assignment-pagination", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -12857,9 +12872,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -12907,8 +12922,8 @@ { "case": "ordinary/topic-store-error", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -12989,9 +13004,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -13039,8 +13054,8 @@ { "case": "topical/topic-store-error", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -13132,10 +13147,10 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -13193,8 +13208,8 @@ { "case": "ordinary/assignment-store-error", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -13275,9 +13290,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -13325,8 +13340,8 @@ { "case": "topical/assignment-store-error", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -13425,10 +13440,10 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -13493,8 +13508,8 @@ { "case": "ordinary/anonymous", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -13575,9 +13590,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = -1))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = -1))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -13625,8 +13640,8 @@ { "case": "topical/anonymous", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -13708,9 +13723,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = -1))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = -1))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -13759,8 +13774,8 @@ { "case": "ordinary/empty-conversation", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": null, "sql": [ @@ -13781,8 +13796,7 @@ "after": { "value": null, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" @@ -13792,15 +13806,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 5, + "postgresStatements": 4, "dynamoCalls": 0 } }, { "case": "topical/empty-conversation", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": null, "sql": [ @@ -13844,10 +13858,8 @@ "after": { "value": null, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", @@ -13878,15 +13890,15 @@ "draws": [ 0.625 ], - "postgresStatements": 10, + "postgresStatements": 8, "dynamoCalls": 2 } }, { "case": "ordinary/zero-priority", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 3", @@ -13967,9 +13979,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -14017,8 +14029,8 @@ { "case": "ordinary/new-comment-after-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "txt": "Generated statement 4", @@ -14099,9 +14111,9 @@ "translations": [] }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -14149,8 +14161,8 @@ { "case": "http/ordinary/owner/GET/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14209,9 +14221,9 @@ } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -14247,8 +14259,8 @@ { "case": "http/ordinary/owner/GET/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14281,14 +14293,13 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 5, + "postgresStatements": 4, "dynamoCalls": 0, "mathBytes": 0 } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" @@ -14298,15 +14309,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 5, + "postgresStatements": 4, "dynamoCalls": 0 } }, { "case": "http/ordinary/owner/GET/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14365,9 +14376,9 @@ } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -14403,8 +14414,8 @@ { "case": "http/ordinary/owner/POST/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14465,9 +14476,9 @@ }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", @@ -14501,8 +14512,8 @@ { "case": "http/ordinary/owner/POST/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14541,15 +14552,14 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 9, + "postgresStatements": 8, "dynamoCalls": 0, "mathBytes": 0 } }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "insert into event_ptpt_no_more_comments (zid, pid, votes_placed) values ($1, $2, (select count(*) from votes where zid = ($1) and pid = ($2)))", "select * from conversations where zid = ($1);", @@ -14562,15 +14572,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 9, + "postgresStatements": 8, "dynamoCalls": 0 } }, { "case": "http/ordinary/owner/POST/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14631,9 +14641,9 @@ }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", @@ -14667,8 +14677,8 @@ { "case": "http/ordinary/second/GET/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14739,9 +14749,9 @@ } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -14789,8 +14799,8 @@ { "case": "http/ordinary/second/GET/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14823,14 +14833,13 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 7\n}", "beforeDeferred": { - "postgresStatements": 5, + "postgresStatements": 4, "dynamoCalls": 0, "mathBytes": 0 } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" @@ -14840,15 +14849,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 5, + "postgresStatements": 4, "dynamoCalls": 0 } }, { "case": "http/ordinary/second/GET/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -14919,9 +14928,9 @@ } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -14969,8 +14978,8 @@ { "case": "http/ordinary/second/POST/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -15043,9 +15052,9 @@ }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", @@ -15091,8 +15100,8 @@ { "case": "http/ordinary/second/POST/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -15131,15 +15140,14 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 7\n}", "beforeDeferred": { - "postgresStatements": 9, + "postgresStatements": 8, "dynamoCalls": 0, "mathBytes": 0 } }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", "insert into event_ptpt_no_more_comments (zid, pid, votes_placed) values ($1, $2, (select count(*) from votes where zid = ($1) and pid = ($2)))", "select * from conversations where zid = ($1);", @@ -15152,15 +15160,15 @@ "translations": 0, "pools": [], "draws": [], - "postgresStatements": 9, + "postgresStatements": 8, "dynamoCalls": 0 } }, { "case": "http/ordinary/second/POST/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -15233,9 +15241,9 @@ }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", @@ -15281,8 +15289,8 @@ { "case": "http/topical/owner/GET/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -15366,13 +15374,13 @@ } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -15429,8 +15437,8 @@ { "case": "http/topical/owner/GET/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -15494,21 +15502,19 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 13, + "postgresStatements": 11, "dynamoCalls": 2, "mathBytes": 0 } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;", @@ -15542,15 +15548,15 @@ "draws": [ 0.625 ], - "postgresStatements": 13, + "postgresStatements": 11, "dynamoCalls": 2 } }, { "case": "http/topical/owner/GET/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -15634,13 +15640,13 @@ } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" ], @@ -15697,8 +15703,8 @@ { "case": "http/topical/owner/POST/seeds", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -15784,13 +15790,13 @@ }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (1=1)) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", @@ -15845,8 +15851,8 @@ { "case": "http/topical/owner/POST/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -15916,22 +15922,20 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 0\n}", "beforeDeferred": { - "postgresStatements": 17, + "postgresStatements": 15, "dynamoCalls": 2, "mathBytes": 0 } }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (1=1)) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "insert into event_ptpt_no_more_comments (zid, pid, votes_placed) values ($1, $2, (select count(*) from votes where zid = ($1) and pid = ($2)))", "select * from conversations where zid = ($1);", @@ -15968,15 +15972,15 @@ "draws": [ 0.625 ], - "postgresStatements": 17, + "postgresStatements": 15, "dynamoCalls": 2 } }, { "case": "http/topical/owner/POST/large-math", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -16062,13 +16066,13 @@ }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 0))))) AND (1=1)) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", "select * from conversations where zid = ($1);", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "update participants set last_interaction = now_as_millis(), nsli = 0 where zid = ($1) and uid = ($2);", @@ -16123,8 +16127,8 @@ { "case": "http/topical/second/GET/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged", - "ruling": "ruled:2026-10-18 cost only, same choice and response bytes in every case", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -16188,21 +16192,19 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 7\n}", "beforeDeferred": { - "postgresStatements": 13, + "postgresStatements": 11, "dynamoCalls": 2, "mathBytes": 0 } }, "sql": [ - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE ((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "select math_tick, data->'comment-priorities' as priorities from math_main where zid = ($1) and math_env = ($2);", "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;", @@ -16236,15 +16238,15 @@ "draws": [ 0.625 ], - "postgresStatements": 13, + "postgresStatements": 11, "dynamoCalls": 2 } }, { "case": "http/topical/second/POST/all-voted", "status": "ruled", - "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged.", - "ruling": "ruled:2026-10-21 counts and activity derived at read; the vote path no longer recounts; response bytes unchanged", + "reason": "the vote path reads comment priorities from a tick-keyed cache; the whole-row read is gone; response bytes unchanged Two fewer SQL statements: the participant recount and the conversation-modified UPDATE are gone; the notification UPDATE is issued immediately rather than deferred; response bytes unchanged. Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", "before": { "value": { "status": 200, @@ -16314,22 +16316,20 @@ "contentType": "application/json; charset=utf-8", "text": "{\n \"currentPid\": 7\n}", "beforeDeferred": { - "postgresStatements": 17, + "postgresStatements": 15, "dynamoCalls": 2, "mathBytes": 0 } }, "sql": [ "INSERT INTO votes (pid, zid, tid, vote, weight_x_32767, high_priority, created) VALUES ($1, $2, $3, $4, $5, $6, default) RETURNING *;", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", - "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", "SELECT \"comments\".* FROM \"comments\" WHERE (((((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" IN (0, 2, 4))) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (1=1)) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY is_seed desc, random() LIMIT 1", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", - "SELECT * FROM conversations WHERE zid = ($1);", "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", "insert into event_ptpt_no_more_comments (zid, pid, votes_placed) values ($1, $2, (select count(*) from votes where zid = ($1) and pid = ($2)))", "select * from conversations where zid = ($1);", @@ -16366,7 +16366,7 @@ "draws": [ 0.625 ], - "postgresStatements": 17, + "postgresStatements": 15, "dynamoCalls": 2 } }, @@ -16641,6 +16641,692 @@ "postgresStatements": 7, "dynamoCalls": 2 } + }, + { + "case": "ordinary/stale-in-process", + "status": "ruled", + "reason": "Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", + "before": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 4, + "dynamoCalls": 0 + }, + "after": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 4, + "dynamoCalls": 0 + } + }, + { + "case": "ordinary/large-math-warm", + "status": "ruled", + "reason": "Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", + "before": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 4, + "dynamoCalls": 0 + }, + "after": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 4, + "dynamoCalls": 0 + } + }, + { + "case": "ordinary/math-cache-warm", + "status": "ruled", + "reason": "Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", + "before": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 4, + "dynamoCalls": 0 + }, + "after": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 4, + "dynamoCalls": 0 + } + }, + { + "case": "ordinary/no-assignments", + "status": "ruled", + "reason": "Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", + "before": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 4, + "dynamoCalls": 0 + }, + "after": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT * FROM conversations WHERE zid = ($1);", + "select * from comments where zid = ($1) and tid = ($2);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625 + ], + "postgresStatements": 4, + "dynamoCalls": 0 + } + }, + { + "case": "topical/no-assignments", + "status": "ruled", + "reason": "Ordinary next-comment routing reads only the ids of every eligible comment (no LIMIT 999) with one conversations read fewer, then, when a comment is chosen, only that comment's row; same candidates, choice and response bytes.", + "ruling": "ruled:2026-10-23 next-comment routing draws from every eligible comment, not only the oldest 999", + "before": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".* FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\" LIMIT 999", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [ + { + "TableName": "Delphi_CommentClustersLLMTopicNames", + "KeyConditionExpression": "conversation_id = :cid AND topic_key = :tk", + "ExpressionAttributeValues": { + ":cid": "1", + ":tk": "job#0#1" + } + }, + { + "TableName": "Delphi_CommentHierarchicalClusterAssignments", + "KeyConditionExpression": "conversation_id = :cid", + "ExpressionAttributeValues": { + ":cid": "1" + } + } + ], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625, + 0.625 + ], + "postgresStatements": 5, + "dynamoCalls": 2 + }, + "after": { + "value": { + "txt": "Generated statement 4", + "tid": 4, + "created": "1700000000004", + "quote_src_url": null, + "is_seed": false, + "is_meta": false, + "lang": "en", + "pid": 0, + "original_id": null, + "randomN": 13.125, + "remaining": 6, + "total": 6, + "translations": [] + }, + "sql": [ + "SELECT \"comments\".\"tid\" FROM \"comments\" WHERE (((((\"comments\".\"zid\" = 1) AND (\"comments\".\"tid\" NOT IN (SELECT \"votes_latest_unique\".\"tid\" FROM \"votes_latest_unique\" WHERE ((\"votes_latest_unique\".\"zid\" = 1) AND (\"votes_latest_unique\".\"pid\" = 7))))) AND (\"comments\".\"active\" = TRUE)) AND (\"comments\".\"mod\" <> -1)) AND (\"comments\".\"velocity\" > 0)) ORDER BY \"comments\".\"created\"", + "SELECT * FROM conversations WHERE zid = ($1);", + "SELECT archetypal_selections, delphi_job_id FROM topic_agenda_selections WHERE zid = ($1) AND pid = ($2) LIMIT 1;", + "select * from comments where zid = ($1) and tid = ($2);", + "with v as (select * from votes_latest_unique where zid = ($1) and pid = ($2)), c as (select * from get_visible_comments($1)), remaining as (select count(*) as remaining from c left join v on c.tid = v.tid where v.vote is null), total as (select count(*) as total from c) select cast(remaining.remaining as integer), cast(total.total as integer), cast(($2) as integer) as pid from remaining, total;" + ], + "dynamo": [ + { + "TableName": "Delphi_CommentClustersLLMTopicNames", + "KeyConditionExpression": "conversation_id = :cid AND topic_key = :tk", + "ExpressionAttributeValues": { + ":cid": "1", + ":tk": "job#0#1" + } + }, + { + "TableName": "Delphi_CommentHierarchicalClusterAssignments", + "KeyConditionExpression": "conversation_id = :cid", + "ExpressionAttributeValues": { + ":cid": "1" + } + } + ], + "mathBytes": 0, + "translations": 0, + "pools": [ + { + "path": "ordinary", + "candidates": [ + { + "tid": 0, + "weight": 1 + }, + { + "tid": 1, + "weight": 2 + }, + { + "tid": 2, + "weight": 3 + }, + { + "tid": 3, + "weight": 4 + }, + { + "tid": 4, + "weight": 5 + }, + { + "tid": 5, + "weight": 6 + } + ] + } + ], + "draws": [ + 0.625, + 0.625 + ], + "postgresStatements": 5, + "dynamoCalls": 2 + } } ] } diff --git a/server/src/comment.ts b/server/src/comment.ts index 2a7ee5176..942961f13 100644 --- a/server/src/comment.ts +++ b/server/src/comment.ts @@ -169,6 +169,21 @@ function getCommentsCount(o: GetCommentsParams): Promise { }); } +// The columns a plain (non-moderation) comment list returns, in response +// order. uid is read here and removed before anything is returned. +const PLAIN_LIST_COLUMNS = [ + "txt", + "tid", + "created", + "uid", + "quote_src_url", + "is_seed", + "is_meta", + "lang", + "pid", + "original_id", +]; + function getComments(o: GetCommentsParams): Promise { const commentListPromise = o.moderation ? _getCommentsForModerationList(o as any) @@ -177,18 +192,7 @@ function getComments(o: GetCommentsParams): Promise { return Promise.all([convPromise, commentListPromise]) .then(function (a: [any, CommentRow[]]) { let rows: CommentRow[] = a[1]; - const cols = [ - "txt", - "tid", - "created", - "uid", - "quote_src_url", - "is_seed", - "is_meta", - "lang", - "pid", - "original_id", - ]; + const cols = [...PLAIN_LIST_COLUMNS]; if (o.moderation) { if (!o.participantVisibleOnly) { cols.push("velocity"); @@ -376,6 +380,9 @@ function _getCommentsList(o: { random: any; limit: any; offset?: any; + // Next-comment routing (getNextCommentCandidates): read only tid, and every + // matching comment rather than the default first 999. + candidateIdsOnly?: boolean; }): Promise { return MPromise( "_getCommentsList", @@ -385,7 +392,9 @@ function _getCommentsList(o: { ) { getConversationInfo(o.zid).then(function (conv: ConversationInfo) { let q = SQL.sql_comments - .select(SQL.sql_comments.star()) + .select( + o.candidateIdsOnly ? SQL.sql_comments.tid : SQL.sql_comments.star() + ) .where(SQL.sql_comments.zid.equals(o.zid)); if (!_.isUndefined(o.tids)) { q = q.and(SQL.sql_comments.tid.in(o.tids)); @@ -430,7 +439,7 @@ function _getCommentsList(o: { } if (!_.isUndefined(o.limit)) { q = q.limit(o.limit); - } else { + } else if (!o.candidateIdsOnly) { q = q.limit(999); // Default limit for backward compatibility } if (!_.isUndefined(o.offset)) { @@ -452,6 +461,38 @@ function _getCommentsList(o: { ) as Promise; } +/** + * Next-comment routing's candidates: the id of every comment the plain list + * would offer this participant (the same moderation, vote, `without`, active + * and velocity filters, in the same created order), with no row limit. Only + * ids are read: the weighted draw needs nothing else, and the chosen comment's + * row is read afterwards with getNextCommentRow. The plain list keeps its + * default of 999 rows. + */ +function getNextCommentCandidates(o: { + zid: number; + not_voted_by_pid: number; + withoutTids?: Array; +}): Promise> { + return _getCommentsList({ ...o, candidateIdsOnly: true } as any); +} + +/** One comment's row, with the columns and key order of the plain list. */ +async function getNextCommentRow( + zid: number, + tid: number +): Promise { + const rows = (await pg.queryP( + "select * from comments where zid = ($1) and tid = ($2);", + [zid, tid] + )) as CommentRow[]; + if (!rows.length) return undefined; + return _.pick( + rows[0], + PLAIN_LIST_COLUMNS.filter((c) => c !== "uid") + ) as CommentRow; +} + function getNumberOfCommentsRemaining(zid: number, pid: number): Promise { return pg.queryP( "with " + @@ -600,6 +641,8 @@ export { getComment, getComments, getCommentsCount, + getNextCommentCandidates, + getNextCommentRow, getNumberOfCommentsRemaining, translateAndStoreComment, }; diff --git a/server/src/nextComment.ts b/server/src/nextComment.ts index 48ea6ff3b..db92ebf38 100644 --- a/server/src/nextComment.ts +++ b/server/src/nextComment.ts @@ -10,9 +10,10 @@ import Config from "./config"; import logger from "./utils/logger"; import pg from "./db/pg-query"; import { - CommentRow, CommentTranslationRow, getComments, + getNextCommentCandidates, + getNextCommentRow, getNumberOfCommentsRemaining, translateAndStoreComment, } from "./comment"; @@ -65,8 +66,12 @@ async function getNextPrioritizedComment( withoutTids, }); - const [comments, latestPriorities, remainingRows] = (await Promise.all([ - getComments(params as GetCommentsParams), + const [candidates, latestPriorities, remainingRows] = (await Promise.all([ + // Every eligible unvoted comment enters the draw, not only the oldest + // 999 the plain comment list returns. Only their ids are read here. + getNextCommentCandidates( + params as Parameters[0] + ), // The latest committed generation's priorities, NOT `getPca(zid, 0)`. A // literal 0 asks for something strictly newer than generation 0, and // generation 0 is a conversation's real first generation, so the old call @@ -79,12 +84,12 @@ async function getNextPrioritizedComment( getLatestCommentPriorities(zid), getNumberOfCommentsRemaining(zid, pid), ])) as [ - CommentRow[], + NextCommentCandidate[], CommentPriorities | undefined, Array<{ total: number; remaining: number }> ]; - if (!comments || comments.length === 0) { + if (!candidates || candidates.length === 0) { return null; } if (!remainingRows || remainingRows.length === 0) { @@ -96,10 +101,13 @@ async function getNextPrioritizedComment( const totalCount = Number(remainingRows[0].total); const remainingCount = Number(remainingRows[0].remaining); - const selectedRow = selectProbabilistically( - comments, - commentPriorities - ) as unknown as GetCommentsParams; + const chosen = selectProbabilistically(candidates, commentPriorities); + // Only the chosen comment's row is read, with the plain list's columns. + const row = chosen && (await getNextCommentRow(zid, chosen.tid)); + const selectedRow = (row && { + ...row, + randomN: chosen.randomN, + }) as unknown as GetCommentsParams; selectedRow.remaining = remainingCount; selectedRow.total = totalCount; return selectedRow; @@ -140,16 +148,18 @@ export async function checkInitialComment( return { status: "eligible" as const, comment }; } +type NextCommentCandidate = { tid: number; randomN?: number }; + function selectProbabilistically( - comments: CommentRow[], + comments: NextCommentCandidate[], priorities: Record -): CommentRow { +): NextCommentCandidate { // Here we go through all of the comments we might select for the user and add their priority values const lookup = _.reduce( comments, ( - o: { lastCount: number; lookup: Array<[number, CommentRow]> }, - comment: CommentRow + o: { lastCount: number; lookup: Array<[number, NextCommentCandidate]> }, + comment: NextCommentCandidate ) => { // If we like, we can use nTotal and nRemaining here to figure out how much we should emphasize the // priority, potentially. Maybe we end up with different classes of priorities lists for this purpose? @@ -168,9 +178,9 @@ function selectProbabilistically( // simple to reason about all other things being equal. const result = _.find( lookup.lookup, - (x: [number, CommentRow]) => x[0] > randomN + (x: [number, NextCommentCandidate]) => x[0] > randomN ); - const c = result?.[1] as CommentRow; + const c = result?.[1] as NextCommentCandidate; if (c) { c.randomN = randomN; } From 8f2d038e6294f8cbf0a6855ed8a54cf664a9991b Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Sat, 24 Oct 2026 09:42:09 -0700 Subject: [PATCH 27/30] comments: a typed contract for POST /api/v3/comments with 153 recorded cases (#3256) * comments: a typed contract for POST /api/v3/comments with 153 recorded cases The contract in polis-contracts names the request, every response Node produces for POST /api/v3/comments on this pin, the durable-before-response boundaries and the vote convention the author's explicit vote speaks through. The characterization harness records and replays 153 serial cases and four concurrent ones against unchanged Node with zero differences: anonymous, standard, OIDC first use, XID, Treevite and owner/moderator identities; first and repeat membership; absent, null, empty, long and duplicate text; closed and strictly moderated conversations; the comment number held to commit under concurrency; and the moderation email to the owner and site moderators, captured by a local SES endpoint with an explicit expected-attempt policy. A separate declared observation profile waits out the language-detection budget for the timeout cases only. A golden guard keeps product and recordings from changing together, and a plan for qualifying a second writer is written down. No served behaviour changes. Co-Authored-By: Claude Opus 5.5 * comments: recorder artifact paths are safe for upload; an unused argument is marked A recorded case whose id contains a quote wrote a directory name the artifact upload refuses; case directories are now percent-escaped reversibly. The upload action is pinned by commit like the other workflows, and the control's unused argument is named for the linter. No recording changes. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .github/workflows/polis-cli-ci.yml | 2 + .../workflows/post-comments-recordings.yml | 53 + ci/post_comments_golden_guard.sh | 45 + docs/post-comments-writer-qualification.md | 131 + queue-rs/polis-contracts/src/lib.rs | 1 + queue-rs/polis-contracts/src/post_comments.rs | 481 + server/characterization/cli.cjs | 11 +- server/characterization/entry.cjs | 4 + server/characterization/observe.cjs | 6 +- .../characterization/post-comments/README.md | 96 + .../post-comments/admission.cjs | 46 + .../post-comments/admission.test.cjs | 21 + .../post-comments/artifact-path.cjs | 11 + .../post-comments/artifact-path.test.cjs | 36 + .../characterization/post-comments/check.sh | 38 + .../post-comments/compose.yml | 19 + .../post-comments/concurrent.cjs | 67 + .../post-comments/contract-cases.json | 944 + .../post-comments/control.cjs | 64 + .../post-comments/expected-differences.json | 1 + .../golden/additional/cases.json | 5858 +++ .../post-comments/golden/cases.json | 35433 ++++++++++++++++ .../post-comments/golden/concurrent.json | 613 + .../golden/default-timeout-observation.json | 170 + .../post-comments/golden/disabled/cases.json | 277 + .../post-comments/observation.cjs | 37 + .../post-comments/observation.test.cjs | 46 + server/characterization/post-comments/run.cjs | 218 + server/characterization/post-comments/ses.cjs | 22 + 29 files changed, 44746 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/post-comments-recordings.yml create mode 100644 ci/post_comments_golden_guard.sh create mode 100644 docs/post-comments-writer-qualification.md create mode 100644 queue-rs/polis-contracts/src/post_comments.rs create mode 100644 server/characterization/post-comments/README.md create mode 100644 server/characterization/post-comments/admission.cjs create mode 100644 server/characterization/post-comments/admission.test.cjs create mode 100644 server/characterization/post-comments/artifact-path.cjs create mode 100644 server/characterization/post-comments/artifact-path.test.cjs create mode 100644 server/characterization/post-comments/check.sh create mode 100644 server/characterization/post-comments/compose.yml create mode 100644 server/characterization/post-comments/concurrent.cjs create mode 100644 server/characterization/post-comments/contract-cases.json create mode 100644 server/characterization/post-comments/control.cjs create mode 100644 server/characterization/post-comments/expected-differences.json create mode 100644 server/characterization/post-comments/golden/additional/cases.json create mode 100644 server/characterization/post-comments/golden/cases.json create mode 100644 server/characterization/post-comments/golden/concurrent.json create mode 100644 server/characterization/post-comments/golden/default-timeout-observation.json create mode 100644 server/characterization/post-comments/golden/disabled/cases.json create mode 100644 server/characterization/post-comments/observation.cjs create mode 100644 server/characterization/post-comments/observation.test.cjs create mode 100644 server/characterization/post-comments/run.cjs create mode 100644 server/characterization/post-comments/ses.cjs diff --git a/.github/workflows/polis-cli-ci.yml b/.github/workflows/polis-cli-ci.yml index 0a5759282..7f41056c4 100644 --- a/.github/workflows/polis-cli-ci.yml +++ b/.github/workflows/polis-cli-ci.yml @@ -9,6 +9,7 @@ on: - 'polis-cli/**' - 'ci/tls/**' - 'queue-rs/polis-contracts/**' + - 'server/characterization/post-comments/contract-cases.json' - 'server/__tests__/fixtures/vote-declaration/**' - 'scripts/test-polis-cli.sh' - 'scripts/build-polis-cli-release.py' @@ -21,6 +22,7 @@ on: - 'polis-cli/**' - 'ci/tls/**' - 'queue-rs/polis-contracts/**' + - 'server/characterization/post-comments/contract-cases.json' - 'server/__tests__/fixtures/vote-declaration/**' - 'scripts/test-polis-cli.sh' - 'scripts/build-polis-cli-release.py' diff --git a/.github/workflows/post-comments-recordings.yml b/.github/workflows/post-comments-recordings.yml new file mode 100644 index 000000000..e2f675cfc --- /dev/null +++ b/.github/workflows/post-comments-recordings.yml @@ -0,0 +1,53 @@ +name: POST comments recordings +on: + pull_request: + branches: [edge, stable] + paths: ['server/**', 'queue-rs/polis-contracts/**', 'ci/post_comments_golden_guard.sh', '.github/workflows/post-comments-recordings.yml'] + push: + branches: [edge] + paths: ['server/**', 'queue-rs/polis-contracts/**', 'ci/post_comments_golden_guard.sh', '.github/workflows/post-comments-recordings.yml'] + workflow_dispatch: +permissions: + contents: read +concurrency: + group: post-comments-${{ github.ref }} + cancel-in-progress: true +jobs: + recordings: + runs-on: ubuntu-24.04 + timeout-minutes: 30 + env: + COMPOSE_PROJECT_NAME: post-comments-ci + POLIS_RECOVERY_PG_PORT: '56441' + P027_HTTP_PORT: '56442' + P027_CONTROL_PORT: '56443' + P027_SERVER_IMAGE: post-comments-server + P027_POSTGRES_IMAGE: post-comments-postgres + P027_OIDC_IMAGE: post-comments-oidc + P027_FILE_SERVER_IMAGE: post-comments-files + P027_SOURCE_COMMIT: ${{ github.sha }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + - name: Protect the recorded behavior and its comparison rules + if: github.event_name == 'pull_request' + run: sh ci/post_comments_golden_guard.sh "origin/${{ github.base_ref }}" + - name: Build dependencies before starting the sealed network + run: | + docker build --target prod --build-arg NODE_ENV=production -t "$P027_SERVER_IMAGE" -f server/Dockerfile . + docker build --build-context queue-rs=queue-rs -t "$P027_POSTGRES_IMAGE" -f server/Dockerfile-db server + docker build -t "$P027_OIDC_IMAGE" oidc-simulator + docker build -t "$P027_FILE_SERVER_IMAGE" --build-arg NODE_ENV=production --build-arg AUTH_AUDIENCE=users --build-arg AUTH_CLIENT_ID=dev-client-id --build-arg AUTH_ISSUER=https://localhost:3000/ --build-arg AUTH_NAMESPACE=https://pol.is/ --build-arg EMBED_SERVICE_HOSTNAME=localhost --build-arg GIT_HASH=characterization -f file-server/Dockerfile . + - name: Replay comments and concurrent writers + run: bash server/characterization/post-comments/check.sh + - name: Preserve all outcomes, including failed oracles + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: post-comments-recordings + path: server/characterization/artifacts/comments-ci* + - name: Remove the owned stack + if: always() + run: docker compose -f server/characterization/compose.yml -f server/characterization/post-comments/compose.yml down -v --remove-orphans diff --git a/ci/post_comments_golden_guard.sh b/ci/post_comments_golden_guard.sh new file mode 100644 index 000000000..65857d690 --- /dev/null +++ b/ci/post_comments_golden_guard.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# Recordings and their inputs/comparison rules must never change alongside +# serving code. Expected differences are literal changes with a ruling; a +# golden refresh must absorb them and leave the entries empty. Shared recorder +# modules are guarded too, so another profile cannot hide a comment difference. +# Usage: sh ci/post_comments_golden_guard.sh origin/edge +set -eu +base="$1" +dir="server/characterization/post-comments" +expected="$dir/expected-differences.json" +changed=$(git diff --name-only "$base"...HEAD) +status=0 + +recorded=$(printf '%s\n' "$changed" | + grep -E '^server/characterization/|^ci/post_comments_golden_guard\.sh$|^\.github/workflows/post-comments-recordings\.yml$' | + grep -v '^server/characterization/post-comments/expected-differences\.json$' || true) +code=$(printf '%s\n' "$changed" | + grep -E '^server/(src/|app\.ts$|index\.ts$|package\.json$|package-lock\.json$|postgres/)|^delphi/umap_narrative/reset_conversation\.py$' || true) +if [ -n "$recorded" ] && [ -n "$code" ]; then + echo "::error::The post-comments recordings, their harness inputs or comparison rules change together with the code they record. Re-record in its own PR from edge, or add a named entry to $expected. Recording-side files changed:" + printf '%s\n' "$recorded" + echo "Code changed:" + printf '%s\n' "$code" + status=1 +fi + +if printf '%s\n' "$changed" | grep -Eq "^$dir/(golden/|contract-cases\.json$)" && + ! python3 -c 'import json,sys; sys.exit(0 if json.load(open(sys.argv[1]))["entries"] == [] else 1)' "$expected"; then + echo "::error::The recordings are re-recorded while $expected still has entries. A re-record on edge absorbs them: empty the file in the same PR." + status=1 +fi + +case "$base" in + edge | */edge) + pending=$(python3 -c 'import json,sys; print("\n".join(e.get("case","?") for e in json.load(open(sys.argv[1]))["entries"] if e.get("ruling") == "pending"))' "$expected") + if [ -n "$pending" ]; then + echo "::error::$expected has entries still pending a ruling; a pull request to edge cannot merge until each is ruled (\"ruled:\"):" + printf '%s\n' "$pending" + status=1 + fi + ;; +esac + +[ "$status" -eq 0 ] && echo "post-comments guard: ok (recordings and rules vs code, re-record vs entries, rulings)." +exit "$status" diff --git a/docs/post-comments-writer-qualification.md b/docs/post-comments-writer-qualification.md new file mode 100644 index 000000000..6051ad8e2 --- /dev/null +++ b/docs/post-comments-writer-qualification.md @@ -0,0 +1,131 @@ +# Qualifying simultaneous Node and Rust comment writers + +Plan only. No Rust writer, gateway rule, deployment authorization or claim of +mixed-writer execution accompanies this document. Baseline Node source: +`19873803fa2b84ddca841a50cfb57009650554de`. + +Use disposable generated databases migrated by the real runner, isolated HTTP +processes, distinct application names and connections, and the shared vote +convention modules. Each input has a unique generated text marker. Never mirror +one participant request to both writers as a parity technique. Run Node-only, +Rust-only and alternating Node/Rust phases from independent identical fixtures. +Persist ordered response bytes, auth bindings, raw and latest vote rows, comments, +participants, participant counts, notification tasks, process errors and database +lock observations. Report configuration and source/image hashes with results. + +## Admission and durable boundaries + +Choose one serving authority before hybrid authentication, since first-use OIDC +can provision an account. Unsupported identities or response branches go wholly +to Node before any mutation. Exercise pid zero, standard users, first-use OIDC, +existing and new XID, request-XID precedence, Treevite existing members/refusals, +owner and site moderator. Verify the response identity against the durable +membership, including cold/warm caches, removed membership and rotated codes. +A signed pid is not by itself a database membership check. Preserve or obtain an +explicit decision on every discrepancy; do not insert stricter eligibility as a +side effect of the port. + +Comments commit before the optional author vote. No supplied vote means zero +history and latest-vote rows, including for seeds. Each supplied semantic choice +must produce exactly one history row and one matching latest row under the +configured storage convention, zero weight and false high_priority. Apply both +convention configurations; do not rewrite numbers in assertions. Unknown fields +must not override uid/pid/tid/lang/weight. Check the exact baseline parsing and +response decoder for each identity. Closed conversations reject; duplicate-text +checking precedes the closed check. Strict moderation affects visibility and +notifications; ordinary submissions remain active and unmoderated, while owner +and site-moderator submissions are approved. Only moderators can set is_seed. + +Inject a failed author vote after the comment INSERT has committed. Assert one +comment, no vote, the exact 500 body, and 409 on a same-text retry with no new +comment or vote. Separately lose the HTTP response after both writes commit, +kill the writer by its owned PID after commit, and lose a COMMIT acknowledgement. +Assert no automatic gateway retry, no dispatch to the other writer, no invented +success receipt and no missing durable input. Record the ambiguous client result +separately from stored facts. Deliberate new text is a new operation; do not +confuse it with transport retry. A different receipt/atomicity contract requires +a separately approved change, never a baseline refresh. + +## Statement allocation and conflicting writes + +The shared authority is `tid_auto`, migration 000042: transaction advisory lock +`(873791984,zid)` and MAX(tid)+1. Every writer inserts with NULL tid and reads the +returned value. Keep default READ COMMITTED and the real triggers enabled. + +1. Node inserts text A inside an explicitly held transaction. Observe its + granted transaction advisory lock, then start Rust text B on the same zid. + Confirm B is waiting on that key with no response. Commit A; B must commit + with tid A+1. Repeat reversing writers and rolling A back: B must receive + A's uncommitted number. After either outcome, no lock remains owned by A. +2. Start 12 simultaneous unique-text submissions to one conversation, six per + writer, through the full HTTP/auth chains. Repeat for existing members and + concurrent first joins. Every valid input returns 200, each marker exists + once, assigned tids are distinct and form the contiguous allocated interval, + every `(zid,pid)` reference exists and each response tid/pid matches its row. + Do not assume request order equals allocation order. No 409 allocator + collision, lost comment, deadlock or leaked advisory lock is acceptable. +3. Submit identical text concurrently from both writers. Exactly one comment is + durable, one request returns 200 and the other 409; an explicit author vote + belongs only to the winning author. Repeat trimmed duplicate text, distinct + letter case, closed conversation and strict moderation. Check text-key + SQLSTATE 23505 independently from tid-key 23505 (which is not text conflict). +4. Hold a tid transaction for conversation A while submitting to conversation B. + B completes within the participation budget without acquiring A's advisory + lock. Include imports using the same allocator, with bounded short batches. + Record row locks as well: different lock keys alone do not prove isolation. +5. Mix comment author votes, direct votes and import latest-state refresh for + the same participant/comment. History remains append-only. The latest rule + is last executed insert, not MAX(created); test equal and backdated clocks, + retained latest weight and changed/repeated choices. Exercise both languages + in both lock orders. Check full keys and semantic values, not counts alone. +6. Race close/open and moderation with submissions. Record the exact Node + read-before-write windows, including close between comment and author vote. + Keep source behavior as evidence; obtain a decision before changing atomicity. + Verify participant_count equals the allocator's result and that notification + last_interaction/nsli work cannot reject an already committed submission. + Do not invent comment_count/vote_count/modified updates absent at this pin. + +Participant allocation is a separate shared lock contract. Pin the actually +installed participant trigger, including session-lock release and error-client +discard behavior. Test failed/skipped inserts and duplicate joins with both +writers; require one `(zid,uid)` membership and no retained session lock after +client discard. Do not assume a proposed future allocator migration is installed. + +## Participation under slow work + +Retain the guards and budgets from +`server/__tests__/integration/participation-under-load.test.ts:1-108` and +`server/__tests__/delphi-results-pg/concurrency.pgtest.ts:1-97` unchanged. +For each Node-only, Rust-only and mixed phase, start 12 participants each issuing +one comment, one vote and one nextComment concurrently. Each must return 200 +within 5000 ms; 10000 ms is the unanswered-request cutoff, not a widened pass +budget. Match every submitted marker and semantic vote to durable rows. + +Run independently and together: eight parked export requests; twelve report +loads; all general read/write, export, agent-exchange and result pool connections +occupied; unresolved identity-management, translation and topic providers; math +and bounded imports on the same and different conversations. Use database-side +holds on actual statements and confirmed provider waiters, not a fixed sleep. +Sample only after every slow request has reached its hold. No slow request may +hold a participation connection. For long model requests, park exactly +RESULT_SNAPSHOT_POOL_MAX requests after snapshot release, then require checked-out +snapshot connections = 0 and idle-in-transaction snapshots = 0 before calling +nextComment. Its selected tids must equal the quiet baseline. Release holds in +finally blocks and require all owned requests to drain and all connections to +return. The translation fallback's configured timeout is part of the measured +budget; it does not grant permission to widen the participation budget. + +The pinned participation suite explicitly labels existing waits with +`test.failing` (`participation-under-load.test.ts:36-43,760-769`). Preserve that +baseline classification and report each expected failure separately: a green +suite containing those cases is not proof that every request met the budget. +Future qualification requires the actual per-request latency and durability +assertions above. The separate comments provider-timeout recording profile has +a 10000 ms observation deadline solely to capture the eventual fallback; it +must never be used to pass this 5000 ms participation gate. + +Record request latency and database/provider wait evidence together. Any failed, +rejected or missing vote/comment, starvation, unresolved process error, lock leak, +or unexplained byte/state difference fails qualification. Never skip, quarantine, +reduce participants/parked work, widen timeouts or re-record an unexplained +failure to make the result green. A failed guard is a finding requiring a decision. diff --git a/queue-rs/polis-contracts/src/lib.rs b/queue-rs/polis-contracts/src/lib.rs index ca852abf5..1e600e116 100644 --- a/queue-rs/polis-contracts/src/lib.rs +++ b/queue-rs/polis-contracts/src/lib.rs @@ -34,6 +34,7 @@ pub mod ops_page; pub mod ops_whoami; pub mod other_conversations_page; pub mod participation_read; +pub mod post_comments; pub mod post_votes; pub mod recent_activity; pub mod recent_started; diff --git a/queue-rs/polis-contracts/src/post_comments.rs b/queue-rs/polis-contracts/src/post_comments.rs new file mode 100644 index 000000000..c62c51a50 --- /dev/null +++ b/queue-rs/polis-contracts/src/post_comments.rs @@ -0,0 +1,481 @@ +//! POST /api/v3/comments as served by Node. Contract only; no writer/admission. +//! +//! Source pin: 19873803fa2b84ddca841a50cfb57009650554de. +//! server/app.ts:799-815: reserved participation pools, optional hybrid auth, +//! CID/XID parsing, membership creation, txt/vote/is_seed parsing, token injection, +//! handler. OIDC provisioning and participant creation can commit before invalid +//! text is refused; parser failures precede token injection. Body fields only: +//! no moveToBody, so query strings and caller pid/uid/tid/lang are not inputs. +//! +//! routes/comments.ts:371-633: empty trimmed text is 400; uid/pid resolution +//! (which can hit user.ts's cache) precedes duplicate text checking, which precedes +//! the active-conversation check. Owner/site moderator statements start approved; +//! other statements start active with mod=0, even in strict moderation. is_seed +//! is honored only for moderators. Language detection precedes insertion: +//! comment.ts:563-595 validates provider language/confidence, with bounded failure +//! fallback to null/null, also used when translation is disabled. +//! +//! DURABLE BOUNDARIES: comments INSERT commits before an explicit author vote +//! (routes/comments.ts:491-518). There is NO implicit/default vote, for either +//! seeds or participant statements. votesPost converts wire through the shared +//! convention module (routes/votes.ts:75-99); history and latest projection commit +//! together (000006_update_votes_rule.sql:6-26), separately from the comment. +//! A failed author vote can return 500 with the comment already durable. Retrying +//! that text returns 409; never proxy-retry after mutation may have begun. +//! +//! The tid BEFORE trigger allocates MAX(tid)+1 from zero under transaction lock +//! (873791984,zid), held to COMMIT/ROLLBACK, shared by all writers +//! (000042_tid_auto_transaction_lock.sql:49-66). No private allocator is valid. +//! Participant admission separately updates participant_count in the pid trigger +//! (000000_initial.sql:891-911). This handler does not update comment_count, +//! vote_count or conversations.modified at this pin; do not infer bookkeeping +//! from the older vote handler. The response contains no nextComment. +//! +//! Notification count/recipient reads are awaited and failures swallowed; +//! email promises are detached (routes/comments.ts:521-540,781-824). Non-strict +//! task upsert and participant last_interaction/nsli updates are best effort on +//! the notification pool (comments.ts:295-299,547; server-helpers.ts:442-449), +//! not durability conditions for 200. Slow work must never own participation +//! connections. This contract changes no pool, lock, route or serving behavior. +//! +//! Decoder includes production finalhandler bodies, not gateway responses or +//! development stack traces; identity resolution is not simulated by parse_fields. +use crate::post_votes::{boolean, integer, string, InvalidField}; +use crate::votes::{StorageConvention, VoteChoice}; +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +pub const PATH: &str = "/api/v3/comments"; +pub const CONTRACT: &str = "post-comments/1"; + +/// Unknown fields are ignored. Null/absent optional values remain missing. +#[derive(Debug, Clone, Default, Deserialize, Serialize)] +pub struct Request { + pub conversation_id: Option, + pub xid: Option, + pub txt: Option, + pub vote: Option, + pub is_seed: Option, +} +#[derive(Debug, Clone, PartialEq)] +pub struct ParsedFields { + /// UTF-16 length checked before trimming ASCII spaces. Empty is parsed; + /// handler later returns polis_err_param_missing_txt (parameter.ts:195-214). + pub txt: String, + pub vote: Option, + pub is_seed: Option, +} +impl Request { + /// Route-local parsing after membership, in registration order. CID and + /// XID parsing/auth have already happened. Reuses exact Node parsing helpers. + pub fn parse_fields(&self) -> Result { + let txt = self + .txt + .as_ref() + .and_then(|v| string(v, 997)) + .ok_or(InvalidField("txt"))?; + let vote = match self.vote.as_ref().filter(|v| !v.is_null()) { + None => None, + Some(v) => { + let raw = integer(v).ok_or(InvalidField("vote"))?; + Some( + [VoteChoice::Agree, VoteChoice::Disagree, VoteChoice::Pass] + .into_iter() + .find(|choice| raw == f64::from(choice.wire())) + .ok_or(InvalidField("vote"))?, + ) + } + }; + let is_seed = match self.is_seed.as_ref().filter(|v| !v.is_null()) { + None => None, + Some(v) => Some(boolean(v).ok_or(InvalidField("is_seed"))?), + }; + Ok(ParsedFields { txt, vote, is_seed }) + } +} +/// Only an explicitly supplied author choice produces a vote, even for seeds. +pub fn author_vote(choice: Option) -> Option { + choice.map(|v| StorageConvention::CURRENT.encode(v)) +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Auth { + pub token: String, + pub token_type: String, + pub expires_in: u64, +} +impl Auth { + /// server/src/auth/ensure-participant.ts:667–671. + fn validate(&self) -> Result<(), String> { + if self.token_type != "Bearer" || self.expires_in != 31_536_000 { + return Err("invalid issued auth metadata".into()); + } + Ok(()) + } +} +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Success { + pub tid: i32, + #[serde(rename = "currentPid")] + pub current_pid: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option, +} +/// Auth injection also occurs on handler failJson responses. +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Failure { + pub error: String, + pub message: String, + pub status: u16, + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option, +} +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct AuthFailure { + pub error: String, + pub details: String, +} +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct AccountFailure { + pub error: String, + pub message: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub retry_after: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub details: Option, +} +#[derive(Debug)] +pub enum Response { + Success(Success), + Failure(Failure), + AuthFailure(AuthFailure), + AccountFailure(AccountFailure), + /// Express production finalhandler; middleware errors are not failJson. + Text { + status: u16, + body: Vec, + }, +} +impl Response { + pub fn decode(status: u16, body: &[u8]) -> Result { + if status == 200 { + let result: Success = serde_json::from_slice(body).map_err(|e| e.to_string())?; + reject_null_optionals(body, &["auth"])?; + if let Some(auth) = &result.auth { + auth.validate()?; + } + return Ok(Self::Success(result)); + } + if body == b"Bad Request\n" && status == 400 + || body == b"Internal Server Error\n" && status == 500 + || body == b"Payload Too Large\n" && status == 413 + || body == b"Unsupported Media Type\n" && status == 415 + || body == b"Please use HTTPS when submitting data." && status == 400 + { + return Ok(Self::Text { + status, + body: body.to_vec(), + }); + } + if status == 401 { + if let Ok(value) = serde_json::from_slice::(body) { + if value.error == "Invalid authentication token" + || value.error == "Invalid token format" + && value.details == "Token does not match any supported JWT type" + { + return Ok(Self::AuthFailure(value)); + } + } + } + if let Ok(value) = serde_json::from_slice::(body) { + reject_null_optionals(body, &["details", "retry_after"])?; + if ACCOUNT_ERRORS.iter().any(|(s, code, message)| { + *s == status && *code == value.error && *message == value.message + }) && (status == 429 && value.retry_after == Some(1) + || status != 429 && value.retry_after.is_none()) + && (value.details.is_none() + || matches!( + value.error.as_str(), + "user_creation_failed" | "authentication_error" + )) + { + return Ok(Self::AccountFailure(value)); + } + } + let result: Failure = serde_json::from_slice(body).map_err(|e| e.to_string())?; + reject_null_optionals(body, &["auth"])?; + if result.status != status + || result.message != result.error + || !ERRORS + .iter() + .chain(HANDLER_ERRORS) + .any(|(s, c, _)| *s == status && *c == result.error) + { + return Err("unrecognized POST comments error".into()); + } + if let Some(auth) = &result.auth { + // server/app.ts:811-814: only handler failures can carry auth. + if !HANDLER_ERRORS + .iter() + .any(|(_, code, _)| *code == result.error) + { + return Err("auth is unavailable before the token injector".into()); + } + auth.validate()?; + } + Ok(Self::Failure(result)) + } + pub fn bytes(&self) -> serde_json::Result> { + match self { + Self::Success(v) => serde_json::to_vec(v), + Self::Failure(v) => serde_json::to_vec(v), + Self::AuthFailure(v) => serde_json::to_vec(v), + Self::AccountFailure(v) => serde_json::to_vec(v), + Self::Text { body, .. } => Ok(body.clone()), + } + } +} +fn reject_null_optionals(body: &[u8], fields: &[&str]) -> Result<(), String> { + let value: Value = serde_json::from_slice(body).map_err(|e| e.to_string())?; + if fields + .iter() + .any(|field| value.get(field).is_some_and(Value::is_null)) + { + return Err("Node omits absent optional response fields".into()); + } + Ok(()) +} +/// Middleware failJson errors. Parameter parse errors use the production text +/// finalhandler; a valid empty string reaches the handler's JSON refusal. +pub const ERRORS: &[(u16, &str, &str)] = &[ + (400, "polis_err_misc", "utils/parameter.ts:149"), + ( + 401, + "polis_err_treevite_auth_required", + "auth/ensure-participant.ts:698", + ), + ( + 403, + "polis_err_xid_required", + "auth/ensure-participant.ts:683", + ), + ( + 403, + "polis_err_xid_not_allowed", + "auth/ensure-participant.ts:690", + ), +]; +/// Source-traced handler variants; SQL faults are explicitly labeled in the +/// recordings. A duplicate allocator key is generic 500, never a text conflict +/// (routes/comments.ts:109-127). The missing-uid guard is defensive: successful +/// createIfMissing middleware supplies uid before invoking this handler. +pub const HANDLER_ERRORS: &[(u16, &str, &str)] = &[ + (400, "polis_err_param_missing_txt", "routes/comments.ts:379"), + (400, "polis_err_missing_uid", "routes/comments.ts:386"), + ( + 409, + "polis_err_post_comment_duplicate", + "routes/comments.ts:455,571", + ), + ( + 403, + "polis_err_conversation_is_closed", + "routes/comments.ts:466", + ), + ( + 500, + "polis_err_post_comment_participant_race_condition", + "routes/comments.ts:590,607", + ), + ( + 500, + "polis_err_post_comment_constraint_violation", + "routes/comments.ts:619", + ), + (500, "polis_err_post_comment", "routes/comments.ts:630"), +]; +/// server/src/auth/jwt-middleware.ts:104–160. Only the two 500 branches may +/// include details, and only in DEV_MODE. decode accepts both configuration +/// modes; it does not assert which mode produced a particular response. +pub const ACCOUNT_ERRORS: &[(u16, &str, &str)] = &[ + ( + 429, + "too_many_requests", + "Authentication system is experiencing high load. Please try again in a moment.", + ), + ( + 400, + "invalid_user_data", + "User account is missing required information (email).", + ), + ( + 429, + "authentication_conflict", + "Authentication system encountered a temporary conflict. Please try again.", + ), + ( + 500, + "user_creation_failed", + "Failed to create or map user account", + ), + ( + 500, + "authentication_error", + "An unexpected authentication error occurred", + ), +]; + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + fn parse(value: Value) -> Result { + serde_json::from_value::(value) + .unwrap() + .parse_fields() + } + #[test] + fn recorded_response_bytes_round_trip() { + let rows: Value = serde_json::from_str(include_str!( + "../../../server/characterization/post-comments/contract-cases.json" + )) + .unwrap(); + assert_eq!(rows.as_array().unwrap().len(), 157); + for row in rows.as_array().unwrap() { + assert_eq!(row["recording_oracle_pass"], true); + let body = row["body"].as_str().unwrap(); + let response = + Response::decode(row["status"].as_u64().unwrap() as u16, body.as_bytes()) + .unwrap_or_else(|e| panic!("{}: {e}", row["case"])); + assert_eq!( + response.bytes().unwrap(), + body.as_bytes(), + "{}", + row["case"] + ); + } + } + + #[test] + fn text_utf16_length_precedes_ascii_trimming() { + for text in ["", " ", "\t", "Generated"] { + assert_eq!( + parse(json!({"txt":text})).unwrap().txt, + text.trim_matches(' ') + ); + } + assert!(parse(json!({"txt":"x".repeat(997)})).is_ok()); + assert!(parse(json!({"txt":"x".repeat(998)})).is_err()); + assert!(parse(json!({"txt":"😀".repeat(499)})).is_err()); + assert!(parse(json!({"txt":"😀".repeat(498)+"x"})).is_ok()); + for value in [Value::Null, json!(false), json!(17), json!([]), json!({})] { + assert_eq!(parse(json!({"txt":value})), Err(InvalidField("txt"))); + } + } + #[test] + fn author_vote_has_no_default_and_uses_convention() { + assert_eq!(author_vote(None), None); + for choice in [VoteChoice::Agree, VoteChoice::Disagree, VoteChoice::Pass] { + let p = parse(json!({"txt":"Generated", "vote":format!(" {}tail", choice.wire()), "is_seed":"ON"})).unwrap(); + assert_eq!(p.vote, Some(choice)); + assert_eq!(p.is_seed, Some(true)); + assert_eq!( + author_vote(p.vote), + Some(StorageConvention::CURRENT.encode(choice)) + ); + } + assert_eq!( + parse(json!({"txt":"Generated","vote":null,"is_seed":null})) + .unwrap() + .vote, + None + ); + assert_eq!( + parse(json!({"txt":"Generated","vote":2,"is_seed":"bad"})), + Err(InvalidField("vote")) + ); + assert_eq!( + parse(json!({"txt":"Generated","is_seed":" true "})), + Err(InvalidField("is_seed")) + ); + assert_eq!( + parse(json!({"txt":"Generated","is_seed":2})) + .unwrap() + .is_seed, + Some(true) + ); + } + #[test] + fn strict_success_and_error_variants() { + let body = br#"{"tid":0,"currentPid":0}"#; + assert_eq!(Response::decode(200, body).unwrap().bytes().unwrap(), body); + for body in [ + br#"{"tid":0,"currentPid":0,"nextComment":null}"#.as_slice(), + br#"{"tid":0,"currentPid":0,"auth":null}"#, + br#"{"currentPid":0}"#, + ] { + assert!(Response::decode(200, body).is_err()); + } + for (status, code, _) in ERRORS.iter().chain(HANDLER_ERRORS) { + let body = format!(r#"{{"error":"{code}","message":"{code}","status":{status}}}"#); + assert_eq!( + Response::decode(*status, body.as_bytes()) + .unwrap() + .bytes() + .unwrap(), + body.as_bytes() + ); + assert!(Response::decode(404, body.as_bytes()).is_err()); + } + assert!(Response::decode( + 500, + br#"{"error":"polis_err_vote","message":"polis_err_vote","status":500}"# + ) + .is_err()); + } + + #[test] + fn strict_account_auth_and_production_text_variants() { + for (status, error, message) in ACCOUNT_ERRORS { + let mut body = json!({"error":error,"message":message}); + if *status == 429 { + body["retry_after"] = json!(1); + } + assert!(Response::decode(*status, &serde_json::to_vec(&body).unwrap()).is_ok()); + body["unexpected"] = json!(true); + assert!(Response::decode(*status, &serde_json::to_vec(&body).unwrap()).is_err()); + body.as_object_mut().unwrap().remove("unexpected"); + body["retry_after"] = Value::Null; + assert!(Response::decode(*status, &serde_json::to_vec(&body).unwrap()).is_err()); + } + let body = br#"{"error":"Invalid token format","details":"Token does not match any supported JWT type"}"#; + assert!(Response::decode(401, body).is_ok()); + assert!(Response::decode(403, body).is_err()); + assert!(Response::decode( + 401, + br#"{"error":"Invalid token format","details":"unexpected"}"# + ) + .is_err()); + for (status, body) in [ + (400, "Bad Request\n"), + (500, "Internal Server Error\n"), + (413, "Payload Too Large\n"), + (415, "Unsupported Media Type\n"), + (400, "Please use HTTPS when submitting data."), + ] { + assert_eq!( + Response::decode(status, body.as_bytes()) + .unwrap() + .bytes() + .unwrap(), + body.as_bytes() + ); + assert!(Response::decode(404, body.as_bytes()).is_err()); + } + } +} diff --git a/server/characterization/cli.cjs b/server/characterization/cli.cjs index e425d0f57..182fd6bc3 100644 --- a/server/characterization/cli.cjs +++ b/server/characterization/cli.cjs @@ -287,10 +287,13 @@ async function runCase(c, tokens, tables, normalizer) { } } async function observeCase(c, tokens, tables, normalizer) { + const observation = c.observationProfile === undefined + ? { oracle } + : require("./post-comments/observation.cjs").observation(c); await get("/begin?seed=" + c.seed + "&case=" + encodeURIComponent(c.caseId)); const before = await snapshot(tables), obsBefore = await get("/state"); - const response = await send(c.request, tokens); + const response = await send(c.request, tokens, observation.deadlineMs); readContext.phase = "after-request"; // Capture delayed 100 ms writes, then demand quiescence; do not treat an arbitrary delay as proof. await wait(200); @@ -425,9 +428,11 @@ async function observeCase(c, tokens, tables, normalizer) { jwts: issued, jwtMinted: (obsAfter.jwtIssues || 0) - (obsBefore.jwtIssues || 0), }; - const o = oracle(response, processErrors, c.case === "proxy-tail"); + const o = observation.oracle(response, processErrors, c.case === "proxy-tail"); try { - assertAttempts(effects.outbound); + if (process.env.P027_COMMENTS_PROFILE === "1" && c.caseId.startsWith("post-comments/")) + require("./post-comments/admission.cjs").assertCommentsAttempts(effects.outbound, c.notificationPolicy); + else assertAttempts(effects.outbound); } catch (e) { o.pass = false; o.failures.push(e.message); diff --git a/server/characterization/entry.cjs b/server/characterization/entry.cjs index d50474f85..5cf2168d6 100644 --- a/server/characterization/entry.cjs +++ b/server/characterization/entry.cjs @@ -16,6 +16,9 @@ process.env.JWT_PUBLIC_KEY = pair.publicKey; const votesProfile = process.env.P027_VOTES_PROFILE === "1" ? require("./votes/control.cjs").install(state, pair) : null; +const commentsProfile = process.env.P027_COMMENTS_PROFILE === "1" + ? require("./post-comments/control.cjs").install(state) + : null; function files(dir = process.cwd()) { const result = {}; function visit(p) { @@ -95,6 +98,7 @@ async function main() { res.setHeader("content-type", "application/json"); try { if (votesProfile && await votesProfile(req, res)) return; + if (commentsProfile && await commentsProfile(req, res)) return; if (req.url.startsWith("/begin?")) { const seed = new URL(req.url, "http://localhost").searchParams.get( "seed" diff --git a/server/characterization/observe.cjs b/server/characterization/observe.cjs index f0f33b232..71fdf77dd 100644 --- a/server/characterization/observe.cjs +++ b/server/characterization/observe.cjs @@ -18,6 +18,7 @@ const allowed = new Set([ "127.0.0.1", "::1", ]); +if (process.env.P027_COMMENTS_PROFILE === "1") allowed.add("comments-ses"); const state = (global.__p027 = { outbound: [], process: [], @@ -117,7 +118,8 @@ function recordProcess(event) { } function check(host, port, protocol, method, path) { host = String(host || "localhost").replace(/^\[|\]$/g, ""); - const blocked = !allowed.has(host); + const blocked = !allowed.has(host) || + (host === "comments-ses" && Number(port) !== 8025); const attempt = { host, port: Number(port), @@ -235,7 +237,7 @@ net.Socket.prototype.connect = function (...args) { if (o.path) throw Error("P027 Unix sockets forbidden in application process"); // Raw TCP, including fetch/undici and SDK transports, cannot bypass the host allowlist. const host = o.host || "localhost"; - if (!allowed.has(host)) check(host, o.port, "tcp"); + if (!allowed.has(host) || host === "comments-ses") check(host, o.port, "tcp"); return connect.apply(this, args); }; for (const event of ["unhandledRejection", "uncaughtExceptionMonitor"]) diff --git a/server/characterization/post-comments/README.md b/server/characterization/post-comments/README.md new file mode 100644 index 000000000..23158d3c0 --- /dev/null +++ b/server/characterization/post-comments/README.md @@ -0,0 +1,96 @@ +# POST comments characterization + +This profile calls unchanged Node through its real authentication, participant, +parsing, convention and SQL paths. It defines a contract and recordings, not a +Rust writer or migration authorization. Source pin: +`19873803fa2b84ddca841a50cfb57009650554de`. + +The main serial profile captures 129 cases. Together with 23 additional +seed/account cases, the disabled-provider case and four concurrent responses, +157 completed responses are preserved in `contract-cases.json` and strictly +decoded/re-encoded by polis-contracts. Each CI replay starts from a fresh fixture. + +Standard bearer first join starts with a generated user and no membership; its +repeat must reuse the same pid without another participant. Absent and null text +are separate cases: each returns exact `Bad Request\n` bytes after creating one +participant, without a comment or attached token. Empty text remains a distinct +handler error. The site-recipient case associates the page with both the owner +and an emailed site moderator. Exactly two SDK and HTTP messages must match the +complete templates; the owner appears in both SELECT branches and is deduplicated +by UNION. Existing owner-only cases remain in the matrix. + +The `language-timeout` case explicitly declares the separate +`post-comments-provider-timeout/1` observation profile: a 10000 ms sender/oracle +deadline, above Node's unchanged 5000 ms detection budget. This captures the +actual fallback response and its durable effects. It is **not** a participation +latency qualification. The default sender/oracle retains its 2000 ms deadline; +every other case and all participation guards are unchanged. The profile rejects +use on any other case, method or route, or outside the sealed comments harness. +Its metadata is retained and compared in every recording. Completion, process +errors, effect settling and outbound admission remain mandatory. + +The earlier default-observer failure remains in +`golden/default-timeout-observation.json`: the HTTP observer aborted before Node's +fallback, while a comment later committed. It is historical evidence, separate +from the approved eventual-response baseline. Comparing the new capture with +the original 125-case corpus found only this declared observation difference; +the other 124 cases were identical under the existing wire/effect comparator. +No serving behavior or expected-differences entry was changed to absorb it. + +`concurrent.cjs` records two requests queued behind the actual tid transaction +lock, with both pre-insert reads completed while the first writer is uncommitted. +Unique texts return 200/200 with two rows; identical text returns 200/409 with one +row. Both pairs replayed exactly. Order is established by observed allocator +waiters, not arbitrary delays. No serving SQL or Node handler is replaced. + +`control.cjs` injects named SQL failures and controls the Translate SDK boundary, +as the existing comment-stored-first test does. The real detectLanguage parser, +validation, timeout and fallback run. Normal cases use a null-result provider +fixture; success/error/malformed/timeout are separately named. A separate +`COMMENTS_LANGUAGE_DISABLED=1` driver with `POST_COMMENTS_TRANSLATION=false` +server configuration checks the truly disabled branch. No real provider identity, +credentials or provider calls are used; the generated credential document is `{}`. + +The SES capture is an HTTP server on the sealed compose network. It cannot +forward mail. Each case declares count, recipient class and exact subject/body +policy before execution. SDK and HTTP payloads must match that policy; the +ordinary outbound assertion handles every other attempt unchanged. Only the +comments profile may connect to comments-ses:8025. Unrelated services, cloud +transports, wrong ports/paths, templates and recipients fail admission. The +emulator retains the received messages as an additional witness. + +`run.cjs` retains each response, ordered wire evidence, database effects, process +errors, provider attempts and assertion failures, then continues the matrix. +Failed response delivery is not interpreted as rollback. An injected author-vote +failure yields 500 after one comment commits; the identical-text retry is 409 and +does not repair the missing vote. Every valid vote uses the shared convention +module, including test expectations; there is no default author or seed vote. + +Replay uses the existing characterization comparator and verified JWT symbols, +not JSON-body-only equality. Timing, chunk boundaries and standard transport +metadata are excluded under that existing policy. Expected changes use the +existing collective-statement literal expected-differences mechanism (the same +rules as vote-path): one exact case/find/replace, why and explicit ruling, no +unknown case, pending ruling or silent broad mask. The entries file is empty. +No observed difference has been approved or masked. + +Use the dedicated compose overlay with a unique project and ports. Seed and +restart Node/DynamoDB before each run and wait for readiness from the sealed +driver. Node source stays mounted from the pinned tree. Commands from the repo: + +```sh +node --test characterization/post-comments/admission.test.cjs +node characterization/post-comments/run.cjs /artifacts/comments-record +node characterization/post-comments/concurrent.cjs /artifacts/comments-concurrent +# Fresh seed/restart/readiness before replay: +node characterization/post-comments/run.cjs /artifacts/comments-replay /artifacts/comments-record +node characterization/post-comments/concurrent.cjs /artifacts/comments-concurrent-replay /artifacts/comments-concurrent +``` + +Run Node commands in the compose driver with working directory /app. Full wire +and effect evidence belongs in the recording artifacts; contract-cases.json is +only the complete response-body codec fixture, not a substitute for that corpus. +The hosted workflow runs `bash server/characterization/post-comments/check.sh`. +The golden guard prevents recording/rule changes together with serving changes; +its existing literal expected-differences mechanism is exercised by the CI entrypoint. +See `docs/post-comments-writer-qualification.md` for the mixed-writer plan. diff --git a/server/characterization/post-comments/admission.cjs b/server/characterization/post-comments/admission.cjs new file mode 100644 index 000000000..008c18314 --- /dev/null +++ b/server/characterization/post-comments/admission.cjs @@ -0,0 +1,46 @@ +"use strict"; +const assert = require("node:assert/strict"); +const { assertAttempts } = require("../admission.cjs"); +function message(recipient, count, conversationId) { + const text = `${count} ${count === 1 ? "Statement is" : "Statements are"} waiting for your review here: https://pol.is/m/${conversationId}\n\nThank you for using Polis.`; + return { + Destination: { ToAddresses: [recipient] }, + Content: { Simple: { + Subject: { Charset: "UTF-8", Data: `Waiting for review (conversation ${conversationId})` }, + Body: { + Html: { Charset: "UTF-8", Data: `${text} +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
` }, + Text: { Charset: "UTF-8", Data: `${text} - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.` }, + }, + } }, + FromEmailAddress: "sender@example.invalid", + }; +} +function assertCommentsAttempts(attempts, policy) { + assert.ok(policy, "every case declares a notification policy"); + assert.equal(policy.template, "comment-moderation"); + assert.equal(policy.count, policy.recipients.length); + for (const recipient of policy.recipients) + assert.ok(["owner", "site-moderator"].includes(recipient.class)); + const sdk = attempts.filter(a => a.service === "SESv2"); + const local = attempts.filter(a => a.host === "comments-ses"); + assertAttempts(attempts.filter(a => a.service !== "SESv2" && a.host !== "comments-ses")); + assert.equal(sdk.length, policy.count, "SES command count"); + const http = local.filter(a => a.protocol === "http"); + assert.equal(http.length, policy.count, "SES transport count"); + assert.ok(local.filter(a => a.protocol === "tcp").length <= policy.count, "no extra raw sockets"); + for (const a of local) { + assert.equal(a.port, 8025); assert.equal(a.blocked, false); + assert.ok(["http", "tcp"].includes(a.protocol)); + if (a.protocol === "http") { + assert.equal(a.method, "POST"); assert.equal(a.path, "/v2/email/outbound-emails"); + assert.equal(a.termination, "end"); + } + } + const expected = policy.recipients.map(r => message(r.address, policy.pending, policy.conversationId)); + const key = x => JSON.stringify(x.Destination); + const sort = xs => xs.sort((a,b) => key(a).localeCompare(key(b))); + for (const a of sdk) { assert.equal(a.command, "SendEmailCommand"); assert.equal(a.termination, "end"); } + assert.deepEqual(sort(sdk.map(a=>a.input)), sort([...expected]), "exact SES template and recipient"); + assert.deepEqual(sort(http.map(a=>a.body)), sort([...expected]), "exact captured HTTP payload"); +} +module.exports = { assertCommentsAttempts, message }; diff --git a/server/characterization/post-comments/admission.test.cjs b/server/characterization/post-comments/admission.test.cjs new file mode 100644 index 000000000..85137f3c4 --- /dev/null +++ b/server/characterization/post-comments/admission.test.cjs @@ -0,0 +1,21 @@ +"use strict"; +const test = require("node:test"); +const assert = require("node:assert/strict"); +const {assertCommentsAttempts, message} = require("./admission.cjs"); +const policy = {template:"comment-moderation",count:1,pending:2,conversationId:"2generated",recipients:[{class:"owner",address:"Generated "}]}; +const input=message(policy.recipients[0].address,2,policy.conversationId); +const attempts=[{service:"SESv2",command:"SendEmailCommand",input,termination:"end"},{host:"comments-ses",port:8025,protocol:"http",method:"POST",path:"/v2/email/outbound-emails",body:input,blocked:false,termination:"end"}]; +test("only the declared template and recipient are admitted",()=>assertCommentsAttempts(attempts,policy)); +test("zero attempts is an explicit policy",()=>assertCommentsAttempts([],{...policy,count:0,recipients:[]})); +for(const [name,edit] of [ + ["extra command",a=>a.push(a[0])], + ["wrong recipient",a=>a[0].input.Destination.ToAddresses=["other@example.invalid"]], + ["wrong template",a=>a[0].input.Content.Simple.Subject.Data="wrong"], + ["cloud transport",a=>a[1].host="email.us-east-1.amazonaws.com"], + ["wrong local port",a=>a[1].port=8026], + ["wrong local path",a=>a[1].path="/anything"], + ["failed transport",a=>a[1].termination="connection_error"], + ["other service",a=>a.push({service:"SQS"})], +])test(name+" is refused",()=>{const a=structuredClone(attempts);edit(a);assert.throws(()=>assertCommentsAttempts(a,policy));}); +test("missing policy is refused",()=>assert.throws(()=>assertCommentsAttempts([],undefined))); +test("raw sockets without a declared send are refused",()=>assert.throws(()=>assertCommentsAttempts([{host:"comments-ses",port:8025,protocol:"tcp",blocked:false}],{...policy,count:0,recipients:[]}))); diff --git a/server/characterization/post-comments/artifact-path.cjs b/server/characterization/post-comments/artifact-path.cjs new file mode 100644 index 000000000..aaf658cba --- /dev/null +++ b/server/characterization/post-comments/artifact-path.cjs @@ -0,0 +1,11 @@ +"use strict"; + +// Encode only filesystem names; case IDs and recording contents stay unchanged. +// decodeURIComponent reverses this mapping, including literal percent escapes. +function artifactDirectory(name) { + return encodeURIComponent(name).replace(/[.!'()*]/g, (character) => + "%" + character.charCodeAt(0).toString(16).toUpperCase() + ); +} + +module.exports = { artifactDirectory }; diff --git a/server/characterization/post-comments/artifact-path.test.cjs b/server/characterization/post-comments/artifact-path.test.cjs new file mode 100644 index 000000000..448765b5a --- /dev/null +++ b/server/characterization/post-comments/artifact-path.test.cjs @@ -0,0 +1,36 @@ +"use strict"; + +const assert = require("node:assert/strict"); +const test = require("node:test"); +const { artifactDirectory } = require("./artifact-path.cjs"); + +test("the quoted invalid-vote case has an upload-safe directory", () => { + const name = '100-vote-invalid-"bad"'; + assert.equal(artifactDirectory(name), "100-vote-invalid-%22bad%22"); + assert.equal(decodeURIComponent(artifactDirectory(name)), name); +}); + +test("upload-forbidden characters and path separators round-trip safely", () => { + for (const character of ['"', ":", "<", ">", "|", "*", "?", "\r", "\n", "/", "\\"]) { + const name = "case-" + character; + const directory = artifactDirectory(name); + assert.match(directory, /^[A-Za-z0-9_%~-]+$/); + assert.equal(decodeURIComponent(directory), name); + } +}); + +test("encoding is distinct from literal escapes and preserves Unicode", () => { + const names = ['case-"', "case-%22", "case-%2522", "case-/", "case-%2F", "case-😀", "case-é"]; + const directories = names.map(artifactDirectory); + assert.equal(new Set(directories).size, names.length); + assert.deepEqual(directories.map(decodeURIComponent), names); +}); + +test("plain names stay readable and dot segments cannot traverse directories", () => { + assert.equal(artifactDirectory("concurrent-unique-0"), "concurrent-unique-0"); + for (const name of [".", "..", "../outside", "trailing. "]) { + const directory = artifactDirectory(name); + assert.match(directory, /^[A-Za-z0-9_%~-]+$/); + assert.equal(decodeURIComponent(directory), name); + } +}); diff --git a/server/characterization/post-comments/check.sh b/server/characterization/post-comments/check.sh new file mode 100644 index 000000000..dbeb78ba5 --- /dev/null +++ b/server/characterization/post-comments/check.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Hosted and local entry point. Images must already contain dependencies. +set -euo pipefail +cd "$(dirname "$0")/../../.." +: "${COMPOSE_PROJECT_NAME:?unique project required}" +: "${POLIS_RECOVERY_PG_PORT:?unique port required}" +: "${P027_HTTP_PORT:?unique port required}" +: "${P027_CONTROL_PORT:?unique port required}" +dc() { docker compose -f server/characterization/compose.yml -f server/characterization/post-comments/compose.yml "$@"; } +ready() { + dc exec -T driver node -e 'let n=0;const check=()=>fetch(process.env.P027_CONTROL_URL+"/ready").then(r=>{if(!r.ok)throw Error("not ready")}).catch(e=>{if(++n===45){console.error(e);process.exitCode=1}else setTimeout(check,1000)});check()' +} +dc up -d +ready +dc exec -T driver node --test characterization/post-comments/artifact-path.test.cjs +dc exec -T driver node --test characterization/post-comments/admission.test.cjs +dc exec -T driver node --test characterization/post-comments/observation.test.cjs +# Keep the existing expected-differences policy's own regression suite. +dc exec -T driver node --test characterization/collective-statement/expected.test.cjs +dc exec -T driver node characterization/cli.cjs seed +dc restart server dynamodb +ready +status=0 +dc exec -T -e P027_SOURCE_COMMIT="${P027_SOURCE_COMMIT:-unknown}" driver node characterization/post-comments/run.cjs /artifacts/comments-ci /app/characterization/post-comments/golden || status=1 +# A failed serial case does not prevent independent concurrent observations. +dc exec -T driver node characterization/post-comments/concurrent.cjs /artifacts/comments-ci-concurrent /app/characterization/post-comments/golden || status=1 +dc exec -T driver node characterization/cli.cjs seed +dc restart server dynamodb +ready +dc exec -T oidc-simulator node < server/characterization/votes/provider-tokens.cjs | dc exec -T driver node characterization/votes/install-tokens.cjs +dc exec -T -e COMMENTS_ADDITIONAL=1 driver node characterization/post-comments/run.cjs /artifacts/comments-ci-additional /app/characterization/post-comments/golden/additional || status=1 +POST_COMMENTS_TRANSLATION=false dc up -d server +ready +dc exec -T driver node characterization/cli.cjs seed +dc restart server dynamodb +ready +dc exec -T -e COMMENTS_LANGUAGE_DISABLED=1 driver node characterization/post-comments/run.cjs /artifacts/comments-ci-disabled /app/characterization/post-comments/golden/disabled || status=1 +exit "$status" diff --git a/server/characterization/post-comments/compose.yml b/server/characterization/post-comments/compose.yml new file mode 100644 index 000000000..099e11ce4 --- /dev/null +++ b/server/characterization/post-comments/compose.yml @@ -0,0 +1,19 @@ +services: + server: + environment: + P027_VOTES_PROFILE: "1" + P027_COMMENTS_PROFILE: "1" + SES_ENDPOINT: http://comments-ses:8025 + SHOULD_USE_TRANSLATION_API: "${POST_COMMENTS_TRANSLATION:-true}" + GOOGLE_CREDS_STRINGIFIED: '{}' + depends_on: + comments-ses: { condition: service_started } + driver: + environment: + P027_COMMENTS_PROFILE: "1" + comments-ses: + image: ${P027_SERVER_IMAGE:-p027-server} + working_dir: /app + command: ["node", "characterization/post-comments/ses.cjs"] + volumes: ["./:/app/characterization:ro"] + networks: [sealed] diff --git a/server/characterization/post-comments/concurrent.cjs b/server/characterization/post-comments/concurrent.cjs new file mode 100644 index 000000000..6b9591c39 --- /dev/null +++ b/server/characterization/post-comments/concurrent.cjs @@ -0,0 +1,67 @@ +"use strict"; +// Queue two real HTTP writers behind the real transaction-scoped allocator. +// The requests overlap; the observed wait order makes assigned tids replayable. +require("ts-node/register/transpile-only"); +const assert=require("node:assert/strict"),fs=require("node:fs"),path=require("node:path"); +const {Pool}=require("pg"),recorder=require("../cli.cjs"); +const {delta,canonical}=require("../core.cjs"),{Normalizer}=require("../normalize.cjs"); +const {comparable}=require("../compare.cjs"),{records,put}=require("../recording.cjs"); +const {assertCommentsAttempts}=require("./admission.cjs"); +const {artifactDirectory}=require("./artifact-path.cjs"); +const pool=new Pool({connectionString:process.env.DATABASE_URL}); +const wait=ms=>new Promise(r=>setTimeout(r,ms)); +async function get(p){const r=await fetch(process.env.P027_CONTROL_URL+p);assert.equal(r.status,200);return r.json();} +async function until(predicate){for(let n=0;n<200;n++){if(await predicate())return;await wait(25);}throw Error("allocator waiter not observed");} +async function main(){ + const out=process.argv[2];assert.ok(out.startsWith("/artifacts/comments-"));fs.mkdirSync(out,{recursive:true}); + const tokens={...await get("/tokens"),...await get("/votes-tokens")}; + const tables=[...new Set((await recorder.schema()).map(r=>r.table_name))]; + await pool.query("UPDATE conversations SET is_active=true,strict_moderation=false,treevite_enabled=false,xid_required=false,use_xid_whitelist=false WHERE zid=1"); + const results=[]; + for(const duplicate of [false,true]){ + const name=duplicate?"concurrent-duplicate":"concurrent-unique"; + await get("/comments-fault?kind=none&language=null-fallback"); + await get("/begin?seed=001122334455&case=post-comments/"+name); + const before=await recorder.snapshot(tables),obsBefore=await get("/state"); + const client=await pool.connect(); const pending=[]; + try{ + await client.query("BEGIN");await client.query("SELECT pg_advisory_xact_lock(873791984,1)"); + for(const [i,actor] of ["participant","pid0"].entries()){ + const request={method:"POST",path:"/api/v3/comments",query:{},headers:{"content-type":"application/json","x-forwarded-proto":"https",authorization:"$auth:"+actor},body:{conversation_id:"2p027generated",txt:"Generated "+name+" "+(duplicate?0:i)}}; + pending.push({request,response:recorder.send(request,tokens)}); + // A duplicate's second request also reaches INSERT: both pre-checks read + // before the first writer commits. No route, SQL or timeout is replaced. + await until(async()=>Number((await pool.query("SELECT count(*) FROM pg_locks WHERE locktype='advisory' AND classid=873791984 AND objid=1 AND NOT granted")).rows[0].count)===i+1); + } + await client.query("COMMIT"); + }finally{await client.query("ROLLBACK");client.release();} + const responses=await Promise.all(pending.map(x=>x.response)); + await until(async()=>{const s=await get("/state");return !s.work.pending.length&&!s.work.late.length;}); + assert.equal((await get("/barrier")).name,"request-effects-drained"); + const after=await recorder.snapshot(tables),obs=await get("/state"); + const effects={db:delta(before,after),files:{},outbound:obs.outbound.slice(obsBefore.outbound.length),participantCreated:0,participants:[],jwtIssued:0,jwts:[],jwtMinted:0}; + assertCommentsAttempts(effects.outbound,{template:"comment-moderation",count:0,recipients:[],pending:0,conversationId:"2p027generated"}); + assert.deepEqual(obs.process.slice(obsBefore.process.length),[]); + const rows=effects.db["pg:comments"].added; + assert.equal(rows.length,duplicate?1:2); + assert.equal(effects.db["pg:votes"],undefined); + const normalized=[]; + for(const [i,response] of responses.entries()){ + assert.equal(response.status,i===1&&duplicate?409:200); + const wire=response.wire;delete response.wire; + wire.response.process_alive_at_end=true; + const c={caseId:"post-comments/"+name+"/"+i,case:name+"/"+i,auth:i?"pid0":"participant",request:pending[i].request,response,wire,effects,process:[],routeHits:[],oracle:{pass:true,failures:[],flag:null}}; + const n=new Normalizer();wire.response.headers=require("../headers.cjs").headers(wire.response.headers); + c.response=n.normalize(c.response,"$.response"); // no new credentials in these cases + if(response.status===200){const row=rows.find(r=>r.pid===(i?0:2));assert.ok(row);assert.equal(response.body.tid,row.tid);assert.equal(response.body.currentPid,row.pid);} + const dir=path.join(out,artifactDirectory(name+"-"+i));fs.mkdirSync(dir,{recursive:true}); + put(dir,"comparison.json",c); + for(const [key,value] of Object.entries(records(c)))put(dir,key+".json",value); + normalized.push(comparable(c)); + } + results.push({case:name,responses:normalized,comments:rows});put(out,"concurrent.json",results); + console.log(JSON.stringify({case:name,requests:2,comments:rows.length,statuses:responses.map(r=>r.status)})); + } + if(process.argv[3])assert.equal(canonical(results),canonical(JSON.parse(fs.readFileSync(path.join(process.argv[3],"concurrent.json"))))); +} +main().catch(e=>{console.error(e);process.exitCode=1}).finally(async()=>{await pool.end();await recorder.close()}); diff --git a/server/characterization/post-comments/contract-cases.json b/server/characterization/post-comments/contract-cases.json new file mode 100644 index 000000000..750a056d9 --- /dev/null +++ b/server/characterization/post-comments/contract-cases.json @@ -0,0 +1,944 @@ +[ + { + "case": "anonymous-first", + "status": 200, + "body": "{\"tid\":2,\"currentPid\":4,\"auth\":{\"token\":\"$jwt:82842f14c4d2ad82d7c6b278415aa7742d1049a5f6885297ad8b6d8dfcf3cc71\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "pid0-no-vote", + "status": 200, + "body": "{\"tid\":3,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-agree", + "status": 200, + "body": "{\"tid\":4,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-disagree", + "status": 200, + "body": "{\"tid\":5,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-pass", + "status": 200, + "body": "{\"tid\":6,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-seed", + "status": 200, + "body": "{\"tid\":7,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-seed-explicit-vote", + "status": 200, + "body": "{\"tid\":8,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "pid0-strict", + "status": 200, + "body": "{\"tid\":9,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "participant-no-vote", + "status": 200, + "body": "{\"tid\":10,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-agree", + "status": 200, + "body": "{\"tid\":11,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-disagree", + "status": 200, + "body": "{\"tid\":12,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-pass", + "status": 200, + "body": "{\"tid\":13,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-seed", + "status": 200, + "body": "{\"tid\":14,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-seed-explicit-vote", + "status": 200, + "body": "{\"tid\":15,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "participant-strict", + "status": 200, + "body": "{\"tid\":16,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-no-vote", + "status": 200, + "body": "{\"tid\":17,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-agree", + "status": 200, + "body": "{\"tid\":18,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-disagree", + "status": 200, + "body": "{\"tid\":19,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-pass", + "status": 200, + "body": "{\"tid\":20,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-seed", + "status": 200, + "body": "{\"tid\":21,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-seed-explicit-vote", + "status": 200, + "body": "{\"tid\":22,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "standard-strict", + "status": 200, + "body": "{\"tid\":23,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-no-vote", + "status": 200, + "body": "{\"tid\":24,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-agree", + "status": 200, + "body": "{\"tid\":25,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-disagree", + "status": 200, + "body": "{\"tid\":26,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-pass", + "status": 200, + "body": "{\"tid\":27,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-seed", + "status": 200, + "body": "{\"tid\":28,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-seed-explicit-vote", + "status": 200, + "body": "{\"tid\":29,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "xid-strict", + "status": 200, + "body": "{\"tid\":30,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "owner-no-vote", + "status": 200, + "body": "{\"tid\":31,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-agree", + "status": 200, + "body": "{\"tid\":32,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-disagree", + "status": 200, + "body": "{\"tid\":33,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-pass", + "status": 200, + "body": "{\"tid\":34,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-seed", + "status": 200, + "body": "{\"tid\":35,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-seed-explicit-vote", + "status": 200, + "body": "{\"tid\":36,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "owner-strict", + "status": 200, + "body": "{\"tid\":37,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "admin-no-vote", + "status": 200, + "body": "{\"tid\":38,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-agree", + "status": 200, + "body": "{\"tid\":39,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-disagree", + "status": 200, + "body": "{\"tid\":40,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-pass", + "status": 200, + "body": "{\"tid\":41,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-seed", + "status": 200, + "body": "{\"tid\":42,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-seed-explicit-vote", + "status": 200, + "body": "{\"tid\":43,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "admin-strict", + "status": 200, + "body": "{\"tid\":44,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-no-vote", + "status": 200, + "body": "{\"tid\":45,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-agree", + "status": 200, + "body": "{\"tid\":46,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-disagree", + "status": 200, + "body": "{\"tid\":47,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-pass", + "status": 200, + "body": "{\"tid\":48,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-seed", + "status": 200, + "body": "{\"tid\":49,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-seed-explicit-vote", + "status": 200, + "body": "{\"tid\":50,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-closed", + "status": 403, + "body": "{\"error\":\"polis_err_conversation_is_closed\",\"message\":\"polis_err_conversation_is_closed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-strict", + "status": 200, + "body": "{\"tid\":51,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "oidc-first-use", + "status": 200, + "body": "{\"tid\":52,\"currentPid\":5}", + "recording_oracle_pass": true + }, + { + "case": "oidc-repeat", + "status": 200, + "body": "{\"tid\":53,\"currentPid\":5}", + "recording_oracle_pass": true + }, + { + "case": "xid-first-use", + "status": 200, + "body": "{\"tid\":54,\"currentPid\":6,\"auth\":{\"token\":\"$jwt:86e10d492ae3fa8ed5c7dacc5fac16c6ce08daff77761ae2fffa3282b4a3f1c4\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "xid-existing-bare", + "status": 200, + "body": "{\"tid\":55,\"currentPid\":2,\"auth\":{\"token\":\"$jwt:ba44042502d5f77fffff3332e52baa5b985690b45ca322ac54905652d1853f0c\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "xid-request-precedence", + "status": 200, + "body": "{\"tid\":56,\"currentPid\":7,\"auth\":{\"token\":\"$jwt:fcab3f69918d689766943c331f648b8124f036a8ec81d3ea9e897b8467314197\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "xid-required", + "status": 403, + "body": "{\"error\":\"polis_err_xid_required\",\"message\":\"polis_err_xid_required\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "xid-whitelisted", + "status": 200, + "body": "{\"tid\":57,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-refused", + "status": 403, + "body": "{\"error\":\"polis_err_xid_not_allowed\",\"message\":\"polis_err_xid_not_allowed\",\"status\":403}", + "recording_oracle_pass": true + }, + { + "case": "treevite-pid0", + "status": 200, + "body": "{\"tid\":58,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "treevite-participant", + "status": 200, + "body": "{\"tid\":59,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "treevite-standard", + "status": 200, + "body": "{\"tid\":60,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "treevite-xid", + "status": 200, + "body": "{\"tid\":61,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "treevite-owner", + "status": 200, + "body": "{\"tid\":62,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "treevite-anonymous-refused", + "status": 401, + "body": "{\"error\":\"polis_err_treevite_auth_required\",\"message\":\"polis_err_treevite_auth_required\",\"status\":401}", + "recording_oracle_pass": true + }, + { + "case": "treevite-xid-refused", + "status": 401, + "body": "{\"error\":\"polis_err_treevite_auth_required\",\"message\":\"polis_err_treevite_auth_required\",\"status\":401}", + "recording_oracle_pass": true + }, + { + "case": "treevite-oidc-first-refused", + "status": 401, + "body": "{\"error\":\"polis_err_treevite_auth_required\",\"message\":\"polis_err_treevite_auth_required\",\"status\":401}", + "recording_oracle_pass": true + }, + { + "case": "foreign-token", + "status": 200, + "body": "{\"tid\":63,\"currentPid\":8,\"auth\":{\"token\":\"$jwt:36ab7b9fa0f42b528d8ca6b98a06cee1c628264a1e7ced3bd691753044f60bb1\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "auth-expired", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}", + "recording_oracle_pass": true + }, + { + "case": "auth-bad", + "status": 401, + "body": "{\"error\":\"Invalid token format\",\"details\":\"Token does not match any supported JWT type\"}", + "recording_oracle_pass": true + }, + { + "case": "auth-signature", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}", + "recording_oracle_pass": true + }, + { + "case": "text-empty", + "status": 400, + "body": "{\"error\":\"polis_err_param_missing_txt\",\"message\":\"polis_err_param_missing_txt\",\"status\":400,\"auth\":{\"token\":\"$jwt:8b7f516434846f571df5ecef8b3b3eab10ad76f51c1a16743a22a85683f7a6e2\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "text-spaces", + "status": 400, + "body": "{\"error\":\"polis_err_param_missing_txt\",\"message\":\"polis_err_param_missing_txt\",\"status\":400,\"auth\":{\"token\":\"$jwt:809cdfce82b9910e52f522c3b880d0d201938f3300966fb76eae35f0c548ed17\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "text-null", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "text-number", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "text-boolean", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "text-array", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "text-object", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "text-too-long", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "text-utf16-too-long", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "text-max-length", + "status": 200, + "body": "{\"tid\":64,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "text-utf16-boundary", + "status": 200, + "body": "{\"tid\":65,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "text-tab", + "status": 200, + "body": "{\"tid\":66,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "text-trim", + "status": 200, + "body": "{\"tid\":67,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "text-trim-duplicate", + "status": 409, + "body": "{\"error\":\"polis_err_post_comment_duplicate\",\"message\":\"polis_err_post_comment_duplicate\",\"status\":409}", + "recording_oracle_pass": true + }, + { + "case": "duplicate-before-closed", + "status": 409, + "body": "{\"error\":\"polis_err_post_comment_duplicate\",\"message\":\"polis_err_post_comment_duplicate\",\"status\":409}", + "recording_oracle_pass": true + }, + { + "case": "duplicate-exact", + "status": 409, + "body": "{\"error\":\"polis_err_post_comment_duplicate\",\"message\":\"polis_err_post_comment_duplicate\",\"status\":409}", + "recording_oracle_pass": true + }, + { + "case": "duplicate-case-sensitive", + "status": 200, + "body": "{\"tid\":68,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "vote-null", + "status": 200, + "body": "{\"tid\":69,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "vote-prefix", + "status": 200, + "body": "{\"tid\":70,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "vote-fraction-string", + "status": 200, + "body": "{\"tid\":71,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "vote-invalid-2", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "vote-invalid-0.5", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "vote-invalid-true", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "vote-invalid-\"bad\"", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "vote-invalid-[]", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "vote-invalid-{}", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "seed-number", + "status": 200, + "body": "{\"tid\":72,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "seed-off", + "status": 200, + "body": "{\"tid\":73,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "seed-null", + "status": 200, + "body": "{\"tid\":74,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "seed-invalid", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "ignored-fields", + "status": 200, + "body": "{\"tid\":75,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "missing-conversation", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "unknown-conversation", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "invalid-xid", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "sql-insert", + "status": 500, + "body": "{\"error\":\"polis_err_post_comment\",\"message\":\"polis_err_post_comment\",\"status\":500,\"auth\":{\"token\":\"$jwt:9d595d5d6fe43e6f426c302eeb98551c9946f1c1ebb2eb73be91c770ed7eb3a3\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "sql-participant", + "status": 500, + "body": "{\"error\":\"polis_err_post_comment_participant_race_condition\",\"message\":\"polis_err_post_comment_participant_race_condition\",\"status\":500,\"auth\":{\"token\":\"$jwt:d61b6ca0de82d44a9f9d468103aa537603861bb43c1f9bdc1ab4d3417e9ea702\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "sql-foreign", + "status": 500, + "body": "{\"error\":\"polis_err_post_comment_constraint_violation\",\"message\":\"polis_err_post_comment_constraint_violation\",\"status\":500,\"auth\":{\"token\":\"$jwt:f6e038526918503ca42f9e017412bf391cecb7e416b90b484df3c9b3bc101668\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "sql-duplicate", + "status": 409, + "body": "{\"error\":\"polis_err_post_comment_duplicate\",\"message\":\"polis_err_post_comment_duplicate\",\"status\":409,\"auth\":{\"token\":\"$jwt:12ae68cbcc3673841c2bf83090bf95c68321477404fffb388ec861e032a78328\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "sql-allocator", + "status": 500, + "body": "{\"error\":\"polis_err_post_comment\",\"message\":\"polis_err_post_comment\",\"status\":500,\"auth\":{\"token\":\"$jwt:026a54049ec867d916c13bee4f213850b487de01f16268b0639acbc05bf6e556\",\"token_type\":\"Bearer\",\"expires_in\":31536000}}", + "recording_oracle_pass": true + }, + { + "case": "author-vote-failure-after-commit", + "status": 500, + "body": "{\"error\":\"polis_err_post_comment\",\"message\":\"polis_err_post_comment\",\"status\":500}", + "recording_oracle_pass": true + }, + { + "case": "retry-after-vote-failure", + "status": 409, + "body": "{\"error\":\"polis_err_post_comment_duplicate\",\"message\":\"polis_err_post_comment_duplicate\",\"status\":409}", + "recording_oracle_pass": true + }, + { + "case": "language-success", + "status": 200, + "body": "{\"tid\":77,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "language-error", + "status": 200, + "body": "{\"tid\":78,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "language-malformed", + "status": 200, + "body": "{\"tid\":79,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "notification-task-failure", + "status": 200, + "body": "{\"tid\":81,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "notification-interaction-failure", + "status": 200, + "body": "{\"tid\":82,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "moderation-count-failure", + "status": 200, + "body": "{\"tid\":83,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "pid0-seed-disagree", + "status": 200, + "body": "{\"tid\":2,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "pid0-seed-pass", + "status": 200, + "body": "{\"tid\":3,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "participant-seed-disagree", + "status": 200, + "body": "{\"tid\":4,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "participant-seed-pass", + "status": 200, + "body": "{\"tid\":5,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-seed-disagree", + "status": 200, + "body": "{\"tid\":6,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-seed-pass", + "status": 200, + "body": "{\"tid\":7,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-seed-disagree", + "status": 200, + "body": "{\"tid\":8,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "xid-seed-pass", + "status": 200, + "body": "{\"tid\":9,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "owner-seed-disagree", + "status": 200, + "body": "{\"tid\":10,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "owner-seed-pass", + "status": 200, + "body": "{\"tid\":11,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "admin-seed-disagree", + "status": 200, + "body": "{\"tid\":12,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "admin-seed-pass", + "status": 200, + "body": "{\"tid\":13,\"currentPid\":1}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-seed-disagree", + "status": 200, + "body": "{\"tid\":14,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-seed-pass", + "status": 200, + "body": "{\"tid\":15,\"currentPid\":3}", + "recording_oracle_pass": true + }, + { + "case": "oidc-account", + "status": 500, + "body": "{\"error\":\"user_creation_failed\",\"message\":\"Failed to create or map user account\",\"details\":\"generated recording SQL failure\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-account-conflict", + "status": 429, + "body": "{\"error\":\"authentication_conflict\",\"message\":\"Authentication system encountered a temporary conflict. Please try again.\",\"retry_after\":1}", + "recording_oracle_pass": true + }, + { + "case": "oidc-account-load", + "status": 429, + "body": "{\"error\":\"too_many_requests\",\"message\":\"Authentication system is experiencing high load. Please try again in a moment.\",\"retry_after\":1}", + "recording_oracle_pass": true + }, + { + "case": "oidc-missing-email", + "status": 400, + "body": "{\"error\":\"invalid_user_data\",\"message\":\"User account is missing required information (email).\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-expired", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"jwt expired\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-issuer", + "status": 401, + "body": "{\"error\":\"Invalid token format\",\"details\":\"Token does not match any supported JWT type\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-audience", + "status": 401, + "body": "{\"error\":\"Invalid token format\",\"details\":\"Token does not match any supported JWT type\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-signature", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"invalid signature\"}", + "recording_oracle_pass": true + }, + { + "case": "oidc-unknown-key", + "status": 401, + "body": "{\"error\":\"Invalid authentication token\",\"details\":\"Unable to find a signing key that matches 'generated-unpublished-key'\"}", + "recording_oracle_pass": true + }, + { + "case": "language-disabled", + "status": 200, + "body": "{\"tid\":2,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "concurrent-duplicate/0", + "status": 200, + "body": "{\"tid\":89,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "concurrent-duplicate/1", + "status": 409, + "body": "{\"error\":\"polis_err_post_comment_duplicate\",\"message\":\"polis_err_post_comment_duplicate\",\"status\":409}", + "recording_oracle_pass": true + }, + { + "case": "concurrent-unique/0", + "status": 200, + "body": "{\"tid\":87,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "concurrent-unique/1", + "status": 200, + "body": "{\"tid\":88,\"currentPid\":0}", + "recording_oracle_pass": true + }, + { + "case": "language-timeout", + "status": 200, + "body": "{\"tid\":80,\"currentPid\":2}", + "recording_oracle_pass": true + }, + { + "case": "standard-first-join", + "status": 200, + "body": "{\"tid\":84,\"currentPid\":23}", + "recording_oracle_pass": true + }, + { + "case": "standard-repeat-join", + "status": 200, + "body": "{\"tid\":85,\"currentPid\":23}", + "recording_oracle_pass": true + }, + { + "case": "text-absent", + "status": 400, + "body": "Bad Request\n", + "recording_oracle_pass": true + }, + { + "case": "site-moderator-recipient", + "status": 200, + "body": "{\"tid\":86,\"currentPid\":2}", + "recording_oracle_pass": true + } +] diff --git a/server/characterization/post-comments/control.cjs b/server/characterization/post-comments/control.cjs new file mode 100644 index 000000000..51e8859df --- /dev/null +++ b/server/characterization/post-comments/control.cjs @@ -0,0 +1,64 @@ +"use strict"; +// Isolated recorder controls. Loaded before the application; never in production. +exports.install = (_state) => { + const { Client } = require("pg"); + const query = Client.prototype.query; + let fault = null, fired = 0, language = "null-fallback", languageCalls = []; + // Test dependency control, like comment-stored-first.test.ts. The real + // detectLanguage validation and timeout run unchanged; no provider network. + const Translate = require("@google-cloud/translate").v2.Translate; + Translate.prototype.detect = function (text) { + languageCalls.push({text, mode: language}); + if (language === "success") return Promise.resolve([{language:"fr",confidence:0.5}]); + if (language === "timeout") return new Promise(() => {}); + if (language === "error") return Promise.reject(new Error("generated language provider failure")); + return Promise.resolve([{language:null,confidence:null}]); + }; + const matches = { + insert: /INSERT INTO COMMENTS/i, + participant: /INSERT INTO COMMENTS/i, + foreign: /INSERT INTO COMMENTS/i, + duplicate: /INSERT INTO COMMENTS/i, + allocator: /INSERT INTO COMMENTS/i, + vote: /INSERT INTO votes \(/i, + notification: /insert into notification_tasks/i, + interaction: /update participants set last_interaction/i, + moderation: /select count\(\*\) from comments/i, + }; + Client.prototype.query = function (...args) { + const sql = typeof args[0] === "string" ? args[0] : args[0]?.text || ""; + if (fault && matches[fault].test(sql)) { + const kind = fault; + fault = null; + fired++; + const error = Object.assign(new Error("generated comment recording SQL failure"), { + code: ["participant", "foreign"].includes(kind) ? "23503" : ["duplicate", "allocator"].includes(kind) ? "23505" : "XX000", + constraint: {participant:"comments_zid_pid_fkey", foreign:"comments_uid_fkey", duplicate:"comments_zid_txt_key", allocator:"comments_zid_tid_key"}[kind], + }); + const callback = args.at(-1); + if (typeof callback === "function") { queueMicrotask(() => callback(error)); return; } + return Promise.reject(error); + } + return query.apply(this, args); + }; + return async (req, res) => { + const url = new URL(req.url, "http://localhost"); + if (url.pathname === "/comments-fault") { + const kind = url.searchParams.get("kind"); + if (kind !== "none" && !Object.hasOwn(matches, kind)) throw Error("unknown comment fault"); + fault = kind === "none" ? null : kind; + language = url.searchParams.get("language") || "null-fallback"; + languageCalls = []; + // Configuration is a test dependency control, never a serving edit. + const config = require("../../src/config.ts").default; + if (language !== "disabled" && !config.shouldUseTranslationAPI) + throw Error("language profile must enable translation at process startup"); + fired = 0; + res.end("{}"); return true; + } + if (url.pathname === "/comments-fault-state") { + res.end(JSON.stringify({armed:fault,fired,languageCalls})); return true; + } + return false; + }; +}; diff --git a/server/characterization/post-comments/expected-differences.json b/server/characterization/post-comments/expected-differences.json new file mode 100644 index 000000000..6d749a929 --- /dev/null +++ b/server/characterization/post-comments/expected-differences.json @@ -0,0 +1 @@ +{"entries": []} diff --git a/server/characterization/post-comments/golden/additional/cases.json b/server/characterization/post-comments/golden/additional/cases.json new file mode 100644 index 000000000..89d7cdbb8 --- /dev/null +++ b/server/characterization/post-comments/golden/additional/cases.json @@ -0,0 +1,5858 @@ +[ + { + "caseId": "post-comments/pid0-seed-disagree", + "case": "pid0-seed-disagree", + "auth": "pid0", + "seed": "5416f500c22a", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-seed-disagree", + "is_seed": true, + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 0, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtc2VlZC1kaXNhZ3JlZSIsImlzX3NlZWQiOnRydWUsInZvdGUiOjF9", + "byte_length": 105, + "sha256": "c19eef1d7d4e7c6da95bba94c683f902cf3d42beea2400348912c5abe2c34b97" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-sXN+Gt7azU4GRhQ6lqgvDw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:26 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 45, + "bytes": { + "base64": "eyJ0aWQiOjIsImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "57a984ccdc14763bd14f2d95d4efec0a9500c17f04bf3cf5e1a75a7cd76cb6fa" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 44, + "last_byte_ms": 45, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 2 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 44.41739199999995, + "ttlbMs": 44.990103999999974 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 2, + "tweet_id": null, + "txt": "Generated comment pid0-seed-disagree", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:notification_tasks": { + "added": [ + { + "modified": 1700000000000, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 0, + "subscribed": 0, + "uid": 1, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 0, + "subscribed": 0, + "uid": 1, + "vote_count": 0, + "zid": 1 + } + ] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 2, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 2, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-seed-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/pid0-seed-pass", + "case": "pid0-seed-pass", + "auth": "pid0", + "seed": "4b4226ed93fa", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-seed-pass", + "is_seed": true, + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 0, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtc2VlZC1wYXNzIiwiaXNfc2VlZCI6dHJ1ZSwidm90ZSI6MH0=", + "byte_length": 101, + "sha256": "6004c0e145445f65dfb8c05d567c48dd0bcaca17ac15b85a5d162dd60d20f582" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-4iexfD77H6IeNk4K5qERaQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:26 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjMsImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "5830f5baff7e360e0db8c949d01cf1f477a1382b753bd51326ec25d9b2486d35" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 3 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.771591000000171, + "ttlbMs": 10.055051000000049 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 3, + "tweet_id": null, + "txt": "Generated comment pid0-seed-pass", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 3, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 3, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-seed-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-seed-disagree", + "case": "participant-seed-disagree", + "auth": "participant", + "seed": "7ec802f5ad1e", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-seed-disagree", + "is_seed": true, + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LXNlZWQtZGlzYWdyZWUiLCJpc19zZWVkIjp0cnVlLCJ2b3RlIjoxfQ==", + "byte_length": 112, + "sha256": "42d880c5cffa6a94e623a2c57ad701bfcc3c97d6ded1321ea1363a25ab4764b2" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-GXsHftw0ijJuA3MFEjGhyA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:27 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 11, + "bytes": { + "base64": "eyJ0aWQiOjQsImN1cnJlbnRQaWQiOjJ9", + "byte_length": 24, + "sha256": "0d96bc3abc0a96c76c4bc1b85a9ec57f70e23899d51401474e210b16e5cb4c67" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 11, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 4 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.578303000000005, + "ttlbMs": 10.816429999999855 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 4, + "tweet_id": null, + "txt": "Generated comment participant-seed-disagree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 2, + "subscribed": 0, + "uid": 3, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 2, + "subscribed": 0, + "uid": 3, + "vote_count": 0, + "zid": 1 + } + ] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 4, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 4, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-seed-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-seed-pass", + "case": "participant-seed-pass", + "auth": "participant", + "seed": "37414bab9c19", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-seed-pass", + "is_seed": true, + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 2, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LXNlZWQtcGFzcyIsImlzX3NlZWQiOnRydWUsInZvdGUiOjB9", + "byte_length": 108, + "sha256": "9108272f58a3f3f251109caeae92d57eeb2e2a814769d86df4018057148fdd7f" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-01IN0rodJ571Vh3QEN8KNA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:27 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjUsImN1cnJlbnRQaWQiOjJ9", + "byte_length": 24, + "sha256": "bfcb44e9bc4bc2050b3e7c6c6be76b8f13c103af2fc2202da77337cda618f728" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 12, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 5 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 11.547350999999708, + "ttlbMs": 11.743851999999606 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 5, + "tweet_id": null, + "txt": "Generated comment participant-seed-pass", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 5, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 5, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-seed-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-seed-disagree", + "case": "standard-seed-disagree", + "auth": "standard", + "seed": "5f70ffcaf661", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-seed-disagree", + "is_seed": true, + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 3, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLXNlZWQtZGlzYWdyZWUiLCJpc19zZWVkIjp0cnVlLCJ2b3RlIjoxfQ==", + "byte_length": 109, + "sha256": "defd22abc6e5989068d9034159704a649f87db8cfa3c30cf1787bdefee935941" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-/yVv3xHFSf2bzCrIYn+POQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:28 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjYsImN1cnJlbnRQaWQiOjJ9", + "byte_length": 24, + "sha256": "b2884cf8b1511b8a1dbe7a97083e145d015670c9a790c6ec5408f9f18c76f595" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 6 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.1235359999996035, + "ttlbMs": 7.300994999999602 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 6, + "tweet_id": null, + "txt": "Generated comment standard-seed-disagree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 6, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 6, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-seed-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-seed-pass", + "case": "standard-seed-pass", + "auth": "standard", + "seed": "3d77d0b2d37b", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-seed-pass", + "is_seed": true, + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 4, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLXNlZWQtcGFzcyIsImlzX3NlZWQiOnRydWUsInZvdGUiOjB9", + "byte_length": 105, + "sha256": "db4e2c66bd53357f14f2d07de51cc3da32aa670823366d728b95c8ab9ce2ff55" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-ap/bvH04b8oJy/X9ZF1CTA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:28 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjcsImN1cnJlbnRQaWQiOjJ9", + "byte_length": 24, + "sha256": "2d6ca6f41b3945af294f0e466f88dc904f4583bf6e5721df84e842c5cb9380ff" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 7 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.082128999999895, + "ttlbMs": 9.298254999999699 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 7, + "tweet_id": null, + "txt": "Generated comment standard-seed-pass", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 7, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 7, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-seed-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-seed-disagree", + "case": "xid-seed-disagree", + "auth": "xid", + "seed": "fcb27c7f5279", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-seed-disagree", + "is_seed": true, + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 5, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1zZWVkLWRpc2FncmVlIiwiaXNfc2VlZCI6dHJ1ZSwidm90ZSI6MX0=", + "byte_length": 104, + "sha256": "2de210878e40b4589e3b03d4b90181f74cf5563edd9941a23fef9a4e9aebc38d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-S85YKAqExgjbpvnpqW7RVw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:29 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjgsImN1cnJlbnRQaWQiOjJ9", + "byte_length": 24, + "sha256": "a54535cd48ad93552286847d394b0aa75656e500b425de3afc0a614285f1d7b0" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 12, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 8 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 11.715810000000147, + "ttlbMs": 11.898769000000357 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 8, + "tweet_id": null, + "txt": "Generated comment xid-seed-disagree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 8, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 8, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-seed-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-seed-pass", + "case": "xid-seed-pass", + "auth": "xid", + "seed": "26631e91a302", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-seed-pass", + "is_seed": true, + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1zZWVkLXBhc3MiLCJpc19zZWVkIjp0cnVlLCJ2b3RlIjowfQ==", + "byte_length": 100, + "sha256": "e676421a7c379a1de4a450460ccc5a9602be643da0c17092a48960de8b5a67a0" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-3WzxQvLy/sJlFvCHhu7kKg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:29 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjksImN1cnJlbnRQaWQiOjJ9", + "byte_length": 24, + "sha256": "fe3a8072c0228843f28936712ad28f5d4cc02ae9fb3a25d7e1b7610cae011ddb" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 9 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.138010000000122, + "ttlbMs": 10.311219000000165 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 9, + "tweet_id": null, + "txt": "Generated comment xid-seed-pass", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 9, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 9, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-seed-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-seed-disagree", + "case": "owner-seed-disagree", + "auth": "owner", + "seed": "623f4c9f89c8", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-seed-disagree", + "is_seed": true, + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLXNlZWQtZGlzYWdyZWUiLCJpc19zZWVkIjp0cnVlLCJ2b3RlIjoxfQ==", + "byte_length": 106, + "sha256": "28b65029fc6f2a180c954293eca73b36f951efb777c6682bb71d3583e7500f8d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-EJABlu4KIoHuK+rnkZ5Ufg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:29 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 21, + "bytes": { + "base64": "eyJ0aWQiOjEwLCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "28f6817c196df79550bc346e727cd45e0926145f6b9167ec6b733d779ea59b47" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 21, + "last_byte_ms": 21, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 10 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 21.2509, + "ttlbMs": 21.434526000000005 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 10, + "tweet_id": null, + "txt": "Generated comment owner-seed-disagree", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 10, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 10, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 17.70525699999962, + "blocked": false, + "host": "oidc-simulator", + "method": "GET", + "path": "/.well-known/jwks.json", + "port": 3000, + "protocol": "https", + "response": "{\"keys\":[{\"kty\":\"RSA\",\"n\":\"wzwwEqR5p7a6CaG61i3od-GLTyype3t_f0pwwtoA9NsZANcjHaAUR_qzqlNRQlLI687vF1OfbETYLeHIT5V36QGrMfrYR_tYAoaKFixC_wOjt8EBPoeHgaTOAyGf3V3YNwocNU-StyV1X4hPmDjCrapNYpbKIcAJwq5Ij0WBKGNXBcUUbAceRtLqgzf_6x2vcQJeE5nJK5gd41f_jtlK9Xge0Ig6CcdKOI7U3agyI_iNF3SL0bnCfvtDRIkgAzzeN5Yj4S3Z4rJVQ1RgzZmqBmnjw8h06G8wDyaQPf19u4F___gF-dL1md_fVRKL5UL7OZg42hIZzwzdhrxOGcXUFQ\",\"e\":\"AQAB\",\"alg\":\"RS256\",\"kid\":\"NkRGQjI5N0RBNUUwMTYwOEMxQUVGQkJBQTJBODBGNTE2MDA5NDM5RA\",\"use\":\"sig\"}]}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-seed-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-seed-pass", + "case": "owner-seed-pass", + "auth": "owner", + "seed": "20ea5b29c8af", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-seed-pass", + "is_seed": true, + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLXNlZWQtcGFzcyIsImlzX3NlZWQiOnRydWUsInZvdGUiOjB9", + "byte_length": 102, + "sha256": "3bd758852736ac167e9ec9e7f6f603593f26ec848538d134d9a75591e5fce2d3" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-OZ/R5NGCNdHr2iSjF6O/HQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:30 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjExLCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "ee813e8f54668b89e880edbda59c4bc6c29eda30b8882098b914612ebfc4b55b" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 12, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 11 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 12.25676999999996, + "ttlbMs": 12.455270999999811 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 11, + "tweet_id": null, + "txt": "Generated comment owner-seed-pass", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 11, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 11, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-seed-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-seed-disagree", + "case": "admin-seed-disagree", + "auth": "admin", + "seed": "4b76735a698b", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-seed-disagree", + "is_seed": true, + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLXNlZWQtZGlzYWdyZWUiLCJpc19zZWVkIjp0cnVlLCJ2b3RlIjoxfQ==", + "byte_length": 106, + "sha256": "85a57f21cf8caebc2e691eabeb3c8b00dcfda3d056a2bf0b5a823bf5345bf296" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-ysr/aMy1pX9ohdvU67Rx7A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:30 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjEyLCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "e6f81894479ee43996699769c370dee02c08cb4fcae81174d05a031a935f3e61" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 12 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.114008999999896, + "ttlbMs": 10.279802000000018 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 12, + "tweet_id": null, + "txt": "Generated comment admin-seed-disagree", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 1, + "subscribed": 0, + "uid": 2, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 1, + "subscribed": 0, + "uid": 2, + "vote_count": 0, + "zid": 1 + } + ] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 1, + "tid": 12, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 1, + "tid": 12, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-seed-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-seed-pass", + "case": "admin-seed-pass", + "auth": "admin", + "seed": "4998bf789997", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-seed-pass", + "is_seed": true, + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLXNlZWQtcGFzcyIsImlzX3NlZWQiOnRydWUsInZvdGUiOjB9", + "byte_length": 102, + "sha256": "0240b39c1f3038da506a83d60d1dbddd7125917762657f3648b20d175380866c" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-v7gu+KuyZ7DP46/S24QdYw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:31 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjEzLCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "2c9388a99b28e2b8d6c6b14aa088e7e441b7423707c21c785f1614323ebde6c9" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 13 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.385428000000502, + "ttlbMs": 10.53330300000016 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 13, + "tweet_id": null, + "txt": "Generated comment admin-seed-pass", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 1, + "tid": 13, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 1, + "tid": 13, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-seed-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-seed-disagree", + "case": "site-moderator-seed-disagree", + "auth": "site-moderator", + "seed": "20884e1e8226", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-seed-disagree", + "is_seed": true, + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLXNlZWQtZGlzYWdyZWUiLCJpc19zZWVkIjp0cnVlLCJ2b3RlIjoxfQ==", + "byte_length": 115, + "sha256": "85d230a84d1445b70b5e29fec3ae366445190f7623e71c2269dec76ccdf2ae9a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-LGz7HSCPMBn3DjAabpoDPg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:31 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjE0LCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "dbf9da0b0af1651e4ae584cf9bf0c787502db4b3f7e0119301363a9f5bb80300" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 14 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.492215000000215, + "ttlbMs": 9.642839999999524 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 14, + "tweet_id": null, + "txt": "Generated comment site-moderator-seed-disagree", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 3, + "subscribed": 0, + "uid": 100004, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 3, + "subscribed": 0, + "uid": 100004, + "vote_count": 0, + "zid": 1 + } + ] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 3, + "tid": 14, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 3, + "tid": 14, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-seed-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-seed-pass", + "case": "site-moderator-seed-pass", + "auth": "site-moderator", + "seed": "339c5e2f2d8e", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-seed-pass", + "is_seed": true, + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLXNlZWQtcGFzcyIsImlzX3NlZWQiOnRydWUsInZvdGUiOjB9", + "byte_length": 111, + "sha256": "c9f87bacb8ce7b4a7b883b0ee9a5dba2c8fef275eaa98fa690e2d789837c1e04" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-YeNVkHpwDlqIpY5aUsDoBQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:32 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjE1LCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "9aab2a88924e9c42b5df25778065b06ffd7883a4033b4124a383e2ac9d6fc3f3" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 15 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.804997999999614, + "ttlbMs": 7.948956999999609 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 15, + "tweet_id": null, + "txt": "Generated comment site-moderator-seed-pass", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 3, + "tid": 15, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 3, + "tid": 15, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-seed-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/oidc-account", + "case": "oidc-account", + "auth": "comments-owner-2", + "seed": "dbcc41c5d702", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:comments-owner-2" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-account" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "23229ecdc3ed7bc3dff205e4" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:comments-owner-2" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtYWNjb3VudCJ9", + "byte_length": 75, + "sha256": "07cd8107589f58c8d21f31f8c806ebed3cf953f3e49ee40fc90e36f2e757d52f" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 500, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "125", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"7d-UqKD/GEG54Du+As2zHM+Vg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:32 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 4, + "bytes": { + "base64": "eyJlcnJvciI6InVzZXJfY3JlYXRpb25fZmFpbGVkIiwibWVzc2FnZSI6IkZhaWxlZCB0byBjcmVhdGUgb3IgbWFwIHVzZXIgYWNjb3VudCIsImRldGFpbHMiOiJnZW5lcmF0ZWQgcmVjb3JkaW5nIFNRTCBmYWlsdXJlIn0=", + "byte_length": 125, + "sha256": "5c7a8479d2a67811166d7f9019511ed0006c0d813e909daf8e12e306ec88ea00" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 4, + "last_byte_ms": 4, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "generated recording SQL failure", + "error": "user_creation_failed", + "message": "Failed to create or map user account" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 500, + "ttfbMs": 3.600351999999475, + "ttlbMs": 3.7262689999997747 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/oidc-account-conflict", + "case": "oidc-account-conflict", + "auth": "comments-owner-2", + "seed": "f508ef069943", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:comments-owner-2" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-account-conflict" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "23229ecdc3ed7bc3dff205e4" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:comments-owner-2" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtYWNjb3VudC1jb25mbGljdCJ9", + "byte_length": 84, + "sha256": "658cc2c24b8058170da6bff610ea5cd9af5efe6a54baa102fa9b75ab878539cb" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 429, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "137", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"89-g0EiXkOEPIAKhOP1UUMeNQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:33 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "eyJlcnJvciI6ImF1dGhlbnRpY2F0aW9uX2NvbmZsaWN0IiwibWVzc2FnZSI6IkF1dGhlbnRpY2F0aW9uIHN5c3RlbSBlbmNvdW50ZXJlZCBhIHRlbXBvcmFyeSBjb25mbGljdC4gUGxlYXNlIHRyeSBhZ2Fpbi4iLCJyZXRyeV9hZnRlciI6MX0=", + "byte_length": 137, + "sha256": "640d93512642240b6491dbabb6382d0e0e4022052e151d747e0eb84b85c64d0f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "authentication_conflict", + "message": "Authentication system encountered a temporary conflict. Please try again.", + "retry_after": 1 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 429, + "ttfbMs": 3.3197250000002896, + "ttlbMs": 3.434892000000218 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/oidc-account-load", + "case": "oidc-account-load", + "auth": "comments-owner-2", + "seed": "adaf2e820a46", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:comments-owner-2" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-account-load" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "23229ecdc3ed7bc3dff205e4" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:comments-owner-2" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtYWNjb3VudC1sb2FkIn0=", + "byte_length": 80, + "sha256": "b33367dfe0a0d4ed63a2b9e67328fb14dbf34be77e8d611f4a4257ebb6914e5f" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 429, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "136", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"88-DovMU3Ld3s9Uo3IyS4lolg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:33 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "eyJlcnJvciI6InRvb19tYW55X3JlcXVlc3RzIiwibWVzc2FnZSI6IkF1dGhlbnRpY2F0aW9uIHN5c3RlbSBpcyBleHBlcmllbmNpbmcgaGlnaCBsb2FkLiBQbGVhc2UgdHJ5IGFnYWluIGluIGEgbW9tZW50LiIsInJldHJ5X2FmdGVyIjoxfQ==", + "byte_length": 136, + "sha256": "5393d0dada760406beebf5e37bb8fee5a6ca72f1b1a3120fd77c64244dd49682" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "too_many_requests", + "message": "Authentication system is experiencing high load. Please try again in a moment.", + "retry_after": 1 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 429, + "ttfbMs": 3.3063499999998385, + "ttlbMs": 3.4309339999999793 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/oidc-missing-email", + "case": "oidc-missing-email", + "auth": "oidc-missing-email", + "seed": "87fe50875d4d", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:oidc-missing-email" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-missing-email" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-oidc-no-email" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:oidc-missing-email" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtbWlzc2luZy1lbWFpbCJ9", + "byte_length": 81, + "sha256": "66fe336a01ec01341679611c098259c60c08ba9a8e57aaff8998bf43dd05d87d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "95", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"5f-QGxS/pWYjLgdL+brIiLdOw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:33 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 2, + "bytes": { + "base64": "eyJlcnJvciI6ImludmFsaWRfdXNlcl9kYXRhIiwibWVzc2FnZSI6IlVzZXIgYWNjb3VudCBpcyBtaXNzaW5nIHJlcXVpcmVkIGluZm9ybWF0aW9uIChlbWFpbCkuIn0=", + "byte_length": 95, + "sha256": "abea640eb5104ea2feaac9ba82367c9839f9e4c87a67b1fdcc18caa9852df876" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 2, + "last_byte_ms": 2, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "invalid_user_data", + "message": "User account is missing required information (email)." + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 400, + "ttfbMs": 2.2938450000001467, + "ttlbMs": 2.406970000000001 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/oidc-expired", + "case": "oidc-expired", + "auth": "oidc-expired", + "seed": "af2d9676295d", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:oidc-expired" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-expired" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-oidc-vote-fixture" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:oidc-expired" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtZXhwaXJlZCJ9", + "byte_length": 75, + "sha256": "480b98357e952b9b9ee37e1d62caa025c4845ec668ff7f5b78641c37a916bcd9" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "64", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"40-AZECOzOIgn6Jhruy53oRuA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:34 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "eyJlcnJvciI6IkludmFsaWQgYXV0aGVudGljYXRpb24gdG9rZW4iLCJkZXRhaWxzIjoiand0IGV4cGlyZWQifQ==", + "byte_length": 64, + "sha256": "455bdc63aad37bd64cad42fc6de0dd5a76209a92c23d71b764f6b59f24744b02" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 2, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "jwt expired", + "error": "Invalid authentication token" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 2.4698459999999614, + "ttlbMs": 2.6134710000005725 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/oidc-issuer", + "case": "oidc-issuer", + "auth": "oidc-issuer", + "seed": "b00f68631364", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:oidc-issuer" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-issuer" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-oidc-vote-fixture" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:oidc-issuer" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtaXNzdWVyIn0=", + "byte_length": 74, + "sha256": "673c30dce079253c3c3cb2305f6cd142f1fd5bc3aa998fb556d2872df3f9cc81" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "88", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"58-HG9z2b+w5WYrQmAW1A3b9g\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:34 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 1, + "bytes": { + "base64": "eyJlcnJvciI6IkludmFsaWQgdG9rZW4gZm9ybWF0IiwiZGV0YWlscyI6IlRva2VuIGRvZXMgbm90IG1hdGNoIGFueSBzdXBwb3J0ZWQgSldUIHR5cGUifQ==", + "byte_length": 88, + "sha256": "8a63420d75a3d9036037c407d494e254cc7fd443893999d54d35c56b4702d105" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 1, + "last_byte_ms": 1, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "Token does not match any supported JWT type", + "error": "Invalid token format" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 0.9100039999993896, + "ttlbMs": 1.0082129999991594 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/oidc-audience", + "case": "oidc-audience", + "auth": "oidc-audience", + "seed": "088d01eb6b26", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:oidc-audience" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-audience" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-oidc-vote-fixture" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:oidc-audience" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtYXVkaWVuY2UifQ==", + "byte_length": 76, + "sha256": "c6fcad7be0c7873748a2dc2e29669661873e57bdbde6f7a45ae1a3500c92b447" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "88", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"58-HG9z2b+w5WYrQmAW1A3b9g\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:35 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 1, + "bytes": { + "base64": "eyJlcnJvciI6IkludmFsaWQgdG9rZW4gZm9ybWF0IiwiZGV0YWlscyI6IlRva2VuIGRvZXMgbm90IG1hdGNoIGFueSBzdXBwb3J0ZWQgSldUIHR5cGUifQ==", + "byte_length": 88, + "sha256": "8a63420d75a3d9036037c407d494e254cc7fd443893999d54d35c56b4702d105" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 1, + "last_byte_ms": 1, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "Token does not match any supported JWT type", + "error": "Invalid token format" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 0.9259629999996832, + "ttlbMs": 1.0356300000003102 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/oidc-signature", + "case": "oidc-signature", + "auth": "oidc-signature", + "seed": "ab87492a68d0", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:oidc-signature" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-signature" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-oidc-vote-fixture" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:oidc-signature" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtc2lnbmF0dXJlIn0=", + "byte_length": 77, + "sha256": "0d9e97dc08e4b20230e5e107851563c8bc017d7307c3f5596ad16b818fe580fd" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "70", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"46-hTUIfGJfxLTn7SPS4Ow0pA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:35 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 2, + "bytes": { + "base64": "eyJlcnJvciI6IkludmFsaWQgYXV0aGVudGljYXRpb24gdG9rZW4iLCJkZXRhaWxzIjoiaW52YWxpZCBzaWduYXR1cmUifQ==", + "byte_length": 70, + "sha256": "df42f92d3421b3031dde54aa025f2205befc9d644ce8f63829f15cf01ec52a34" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 2, + "last_byte_ms": 2, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "invalid signature", + "error": "Invalid authentication token" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 2.149470000000292, + "ttlbMs": 2.26555400000143 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/oidc-unknown-key", + "case": "oidc-unknown-key", + "auth": "oidc-unknown-key", + "seed": "8e5a35e94373", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:oidc-unknown-key" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-unknown-key" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-oidc-vote-fixture" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:oidc-unknown-key" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtdW5rbm93bi1rZXkifQ==", + "byte_length": 79, + "sha256": "6759276cf1fc639f49e99d5fc039d58703690095b9221d6bcfb8a70a7de0c2d5" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "122", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"7a-oUEsEgBGT38FJAxt6ei/TQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:31:36 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 6, + "bytes": { + "base64": "eyJlcnJvciI6IkludmFsaWQgYXV0aGVudGljYXRpb24gdG9rZW4iLCJkZXRhaWxzIjoiVW5hYmxlIHRvIGZpbmQgYSBzaWduaW5nIGtleSB0aGF0IG1hdGNoZXMgJ2dlbmVyYXRlZC11bnB1Ymxpc2hlZC1rZXknIn0=", + "byte_length": 122, + "sha256": "cdb94aeaa513960c283c83266bd7bb17b12ae387c3052d15d701db21e7ff601a" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 6, + "last_byte_ms": 6, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "Unable to find a signing key that matches 'generated-unpublished-key'", + "error": "Invalid authentication token" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 6.3291989999997895, + "ttlbMs": 6.486532999999326 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 16.268457999998645, + "blocked": false, + "host": "oidc-simulator", + "method": "GET", + "path": "/.well-known/jwks.json", + "port": 3000, + "protocol": "https", + "response": "{\"keys\":[{\"kty\":\"RSA\",\"n\":\"wzwwEqR5p7a6CaG61i3od-GLTyype3t_f0pwwtoA9NsZANcjHaAUR_qzqlNRQlLI687vF1OfbETYLeHIT5V36QGrMfrYR_tYAoaKFixC_wOjt8EBPoeHgaTOAyGf3V3YNwocNU-StyV1X4hPmDjCrapNYpbKIcAJwq5Ij0WBKGNXBcUUbAceRtLqgzf_6x2vcQJeE5nJK5gd41f_jtlK9Xge0Ig6CcdKOI7U3agyI_iNF3SL0bnCfvtDRIkgAzzeN5Yj4S3Z4rJVQ1RgzZmqBmnjw8h06G8wDyaQPf19u4F___gF-dL1md_fVRKL5UL7OZg42hIZzwzdhrxOGcXUFQ\",\"e\":\"AQAB\",\"alg\":\"RS256\",\"kid\":\"NkRGQjI5N0RBNUUwMTYwOEMxQUVGQkJBQTJBODBGNTE2MDA5NDM5RA\",\"use\":\"sig\"}]}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + } +] diff --git a/server/characterization/post-comments/golden/cases.json b/server/characterization/post-comments/golden/cases.json new file mode 100644 index 000000000..36a7abbd0 --- /dev/null +++ b/server/characterization/post-comments/golden/cases.json @@ -0,0 +1,35433 @@ +[ + { + "caseId": "post-comments/anonymous-first", + "case": "anonymous-first", + "auth": "unauthenticated", + "seed": "1b230d91c2ca", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment anonymous-first" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFub255bW91cy1maXJzdCJ9", + "byte_length": 78, + "sha256": "ce5fa4e00064df297b91451dc72f9abf92650aa6840d3b90670b4eabab3285b1" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "702", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"2be-VvJBvNtOoHXfXPsIYmJKzg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:42 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 53, + "bytes": { + "base64": "eyJ0aWQiOjIsImN1cnJlbnRQaWQiOjQsImF1dGgiOnsidG9rZW4iOiIkand0OjgyODQyZjE0YzRkMmFkODJkN2M2YjI3ODQxNWFhNzc0MmQxMDQ5YTVmNjg4NTI5N2FkOGI2ZDhkZmNmM2NjNzEiLCJ0b2tlbl90eXBlIjoiQmVhcmVyIiwiZXhwaXJlc19pbiI6MzE1MzYwMDB9fQ==", + "byte_length": 157, + "sha256": "9ed579112f6012296ef65126b5067beb44c38fab71b83814d68d47cd1039070a" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 53, + "last_byte_ms": 53, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "702", + "etag": "W/\"2be-VvJBvNtOoHXfXPsIYmJKzg\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 4, + "sub": "anon:4", + "uid": 4 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "currentPid": 4, + "tid": 2 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 52.69891499999994, + "ttlbMs": 53.35237799999993 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 4, + "quote_src_url": null, + "tid": 2, + "tweet_id": null, + "txt": "Generated comment anonymous-first", + "uid": 4, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 5, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 4, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:notification_tasks": { + "added": [ + { + "modified": 1700000000000, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 4, + "subscribed": 0, + "uid": 4, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 4, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:1", + "site_owner": true, + "tut": 0, + "uid": 4, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 4, + "sub": "anon:4", + "uid": 4 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 4, + "subscribed": 0, + "uid": 4, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment anonymous-first", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/pid0-no-vote", + "case": "pid0-no-vote", + "auth": "pid0", + "seed": "4ef05c068ce4", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-no-vote" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtbm8tdm90ZSJ9", + "byte_length": 75, + "sha256": "7672b52aaedd819e10298ed2b878dad975dc78a37da8f0cd930c5d0591ae287a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-4iexfD77H6IeNk4K5qERaQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:43 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 11, + "bytes": { + "base64": "eyJ0aWQiOjMsImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "5830f5baff7e360e0db8c949d01cf1f477a1382b753bd51326ec25d9b2486d35" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 11, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 3 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.779493000000002, + "ttlbMs": 11.076661999999942 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 3, + "tweet_id": null, + "txt": "Generated comment pid0-no-vote", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 0, + "subscribed": 0, + "uid": 1, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 0, + "subscribed": 0, + "uid": 1, + "vote_count": 0, + "zid": 1 + } + ] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-no-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/pid0-agree", + "case": "pid0-agree", + "auth": "pid0", + "seed": "a354a6f409bd", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-agree", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtYWdyZWUiLCJ2b3RlIjotMX0=", + "byte_length": 83, + "sha256": "5acf80bf8d451a2b78487652ac9de64e9fc7fbac948ab8c8125fc481bdfb29f6" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-oGhD277w8UoyclwB0sVYAQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:43 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 16, + "bytes": { + "base64": "eyJ0aWQiOjQsImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "87bcefaee243a66b1d21835ba5bcb659459023e6e2ec4aef84899d0e3c776237" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 16, + "last_byte_ms": 16, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 4 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 15.813404000000219, + "ttlbMs": 16.037989000000152 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 4, + "tweet_id": null, + "txt": "Generated comment pid0-agree", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 4, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 4, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-agree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/pid0-disagree", + "case": "pid0-disagree", + "auth": "pid0", + "seed": "85f8ff40dc31", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-disagree", + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtZGlzYWdyZWUiLCJ2b3RlIjoxfQ==", + "byte_length": 85, + "sha256": "21b6106c6334787cb35a51771d0c63041804cc085e33f09cc4fe601b9b4b8a14" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-bA0Pz8P7bN54RXHBPlys6g\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:44 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjUsImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "e96f42264b005fbb530ba9ac6b1f92b1ac9ec7fe5e70b71cd3c5e9ff60976cbc" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 5 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.031341000000339, + "ttlbMs": 7.291093000000274 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 5, + "tweet_id": null, + "txt": "Generated comment pid0-disagree", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 5, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 5, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/pid0-pass", + "case": "pid0-pass", + "auth": "pid0", + "seed": "4c599c2ad54a", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-pass", + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtcGFzcyIsInZvdGUiOjB9", + "byte_length": 81, + "sha256": "e74df17d5eeec9566960f8c731d2896b5f0e81712641217bd4d73f2d4ad70451" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-TRemkSI19d1dqgwGW5xKyA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:44 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjYsImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "27e6d25f4c2ed0a3486c774342bed27919f98a46b91eba2fc27a91d3b1eccfec" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 6 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.73634600000014, + "ttlbMs": 7.931097000000136 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 6, + "tweet_id": null, + "txt": "Generated comment pid0-pass", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 6, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 6, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/pid0-seed", + "case": "pid0-seed", + "auth": "pid0", + "seed": "afb8195290ce", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-seed", + "is_seed": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtc2VlZCIsImlzX3NlZWQiOnRydWV9", + "byte_length": 87, + "sha256": "f2ed3b4924724234285f4dabb561f67b6fc5cef033d99f8d255b1f5e7d90380e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-4jlycuwf1ZE9GpMkKg9KGQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:45 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjcsImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "bf1bfb182ac284adeb27165e69d6c6947e923277f66f7907d97ca8300fb3753c" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 7 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.302259999999933, + "ttlbMs": 7.492510999999922 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 7, + "tweet_id": null, + "txt": "Generated comment pid0-seed", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-seed", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/pid0-seed-explicit-vote", + "case": "pid0-seed-explicit-vote", + "auth": "pid0", + "seed": "510cee1b9e17", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-seed-explicit-vote", + "is_seed": true, + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtc2VlZC1leHBsaWNpdC12b3RlIiwiaXNfc2VlZCI6dHJ1ZSwidm90ZSI6LTF9", + "byte_length": 111, + "sha256": "2bca18a29ebef5d2be49ea63413c1477b8679cd23e381b9a1fb475b0fe69dc3e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-IRAma/p0ATu2fZ12+2/BpA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:45 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjgsImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "e1a740a0e86cda112f4e9f2e243b8813d093f12d3597127a021c073040f23671" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 8 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.159509000000071, + "ttlbMs": 7.330136000000039 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 8, + "tweet_id": null, + "txt": "Generated comment pid0-seed-explicit-vote", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 8, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 8, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-seed-explicit-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/pid0-closed", + "case": "pid0-closed", + "auth": "pid0", + "seed": "55a11249e68f", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-closed" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtY2xvc2VkIn0=", + "byte_length": 74, + "sha256": "621f2c206e5e336fde3c6d31cefcb96f2fc46c94a3b269d77e372a59fb46f347" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-gQukeO67bdDfjv7rYuqujw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:45 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwibWVzc2FnZSI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwic3RhdHVzIjo0MDN9", + "byte_length": 102, + "sha256": "ac00f242422b3b197b949c87b193a090840262a8c6c05a0b06ad17353f7c129f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_conversation_is_closed", + "message": "polis_err_conversation_is_closed", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 4.697117000000162, + "ttlbMs": 4.908910000000105 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/pid0-strict", + "case": "pid0-strict", + "auth": "pid0", + "seed": "48d1f56df8e9", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment pid0-strict" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 1, + "recipients": [ + { + "class": "owner", + "address": "Generated Owner " + } + ] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBpZDAtc3RyaWN0In0=", + "byte_length": 74, + "sha256": "5e14032bf837292dcde0a5d86a5ecbc89f6da7e669aff3bda88296d2b6c8efef" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-P5ALqXwB1zH3sHvxzn23Sg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:46 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjksImN1cnJlbnRQaWQiOjB9", + "byte_length": 24, + "sha256": "e1f93bc919db5d6c2ae7ae1d30cf0b1d1d996728361440f120c0d552a99f872b" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 9 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.320856999999705, + "ttlbMs": 9.482484000000113 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 9, + "tweet_id": null, + "txt": "Generated comment pid0-strict", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 26.27989399999933, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "1 Statement is waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "1 Statement is waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 31.868266999999832, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "1 Statement is waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "1 Statement is waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + }, + { + "at_ms": 32.37522899999931, + "blocked": false, + "host": "comments-ses", + "method": null, + "path": null, + "port": 8025, + "protocol": "tcp", + "termination": null + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment pid0-strict", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-no-vote", + "case": "participant-no-vote", + "auth": "participant", + "seed": "76f09b7fc95b", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-no-vote" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 2, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LW5vLXZvdGUifQ==", + "byte_length": 82, + "sha256": "fbe7cb134d44cb01a7a916126dc82dbe3809f23c8786b6eb3eb977dddd8364fd" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-D0IohVMX49NcSGW/GZvMug\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:46 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjEwLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "239d0aecb4e79fd4e50a6b62b405c4e11ba6710615fce3e7a2296364d65628a1" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 10 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.621087999999872, + "ttlbMs": 6.779381000000285 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 10, + "tweet_id": null, + "txt": "Generated comment participant-no-vote", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 2, + "subscribed": 0, + "uid": 3, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 2, + "subscribed": 0, + "uid": 3, + "vote_count": 0, + "zid": 1 + } + ] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-no-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-agree", + "case": "participant-agree", + "auth": "participant", + "seed": "3774076529d0", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-agree", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 3, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LWFncmVlIiwidm90ZSI6LTF9", + "byte_length": 90, + "sha256": "9da82b9086ab3fbdc309372fb8d5ca8c158f700af1e36cc12afa4076502cf760" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-o96ECIr9kguglC8xRTBWUw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:47 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjExLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "5da3bbad80af0b25d06d8f2a16664fef3299676e6697f340bde3fff3ea4005c6" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 11 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.358766999999716, + "ttlbMs": 8.531101999999919 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 11, + "tweet_id": null, + "txt": "Generated comment participant-agree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 11, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 11, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-agree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-disagree", + "case": "participant-disagree", + "auth": "participant", + "seed": "f6115843489b", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-disagree", + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 4, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LWRpc2FncmVlIiwidm90ZSI6MX0=", + "byte_length": 92, + "sha256": "9c1fb97459f994a9640f7745aa09f45829022f243feae1cc64604d369096fa18" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-lG/H1NJdjPZGN3qtXUpTsg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:47 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjEyLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "b3f26190e8382e84cd95e946aaccd9bba8be280c3218d9a2e4a6b911cbb07de5" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 12 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.418399999999565, + "ttlbMs": 9.56473399999959 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 12, + "tweet_id": null, + "txt": "Generated comment participant-disagree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 12, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 12, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-pass", + "case": "participant-pass", + "auth": "participant", + "seed": "cd3b3c2795f5", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-pass", + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 5, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LXBhc3MiLCJ2b3RlIjowfQ==", + "byte_length": 88, + "sha256": "7883ceb7680700b99ed5d684d595d84bab8d03deb4ec6057340a85f85f5b3c43" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-LEgNUgJuTrQx7Viy9/Z1Cg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:48 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjEzLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "1eb01584d679aa6e101dc0ce3c8cebb953b6a05b45a4eda0bc28dc8ac44c8a5e" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 13 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.046097999999802, + "ttlbMs": 8.19184899999982 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 13, + "tweet_id": null, + "txt": "Generated comment participant-pass", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 13, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 13, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-seed", + "case": "participant-seed", + "auth": "participant", + "seed": "7d7df6576a27", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-seed", + "is_seed": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 6, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LXNlZWQiLCJpc19zZWVkIjp0cnVlfQ==", + "byte_length": 94, + "sha256": "3c0401d7178e085100cddaa91844ce5d182947782cfe106c473f283daf1dc001" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-rIel3MnoMu6yMZcaKUQy5Q\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:48 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJ0aWQiOjE0LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "76ae9dc3810fd3dbb229b78f86dfaa8b72ed5336d79cda56eca878e6d3ef0700" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 14 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 5.051035000000411, + "ttlbMs": 5.180870000000141 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 14, + "tweet_id": null, + "txt": "Generated comment participant-seed", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-seed", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-seed-explicit-vote", + "case": "participant-seed-explicit-vote", + "auth": "participant", + "seed": "502c9ff85dbe", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-seed-explicit-vote", + "is_seed": true, + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 7, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LXNlZWQtZXhwbGljaXQtdm90ZSIsImlzX3NlZWQiOnRydWUsInZvdGUiOi0xfQ==", + "byte_length": 118, + "sha256": "d95d5bf31499275afa42762f3159de8098ece3a14882ab9f3f0ae833cab7933d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-vXwQNCmFo125GEEUIIpTKQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:48 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjE1LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "a53cdd9f5f472d827844dbd3b68ad923b4fe72267a8916a33c89067926afdc82" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 15 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.101556999999957, + "ttlbMs": 8.249974999999722 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 15, + "tweet_id": null, + "txt": "Generated comment participant-seed-explicit-vote", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 15, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 15, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-seed-explicit-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/participant-closed", + "case": "participant-closed", + "auth": "participant", + "seed": "8ce1e1caf182", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-closed" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 7, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LWNsb3NlZCJ9", + "byte_length": 81, + "sha256": "f2ccc6393d80644c0338d5285f3845f5776aeeb567595e86bbc9fda3be7c4a0d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-gQukeO67bdDfjv7rYuqujw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:49 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwibWVzc2FnZSI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwic3RhdHVzIjo0MDN9", + "byte_length": 102, + "sha256": "ac00f242422b3b197b949c87b193a090840262a8c6c05a0b06ad17353f7c129f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_conversation_is_closed", + "message": "polis_err_conversation_is_closed", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 4.639074000000619, + "ttlbMs": 4.770242000000508 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/participant-strict", + "case": "participant-strict", + "auth": "participant", + "seed": "c8b486b698ae", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment participant-strict" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 8, + "count": 1, + "recipients": [ + { + "class": "owner", + "address": "Generated Owner " + } + ] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHBhcnRpY2lwYW50LXN0cmljdCJ9", + "byte_length": 81, + "sha256": "7dc70d2983b9a6c5e11fb117b67790d4af81895aaad5ffa8272349557e6329e3" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-YtJck6pcYFGBXvzzWE7y7g\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:49 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjE2LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "adc0762a53bb14f7795ba437405b8d09e7211517606f8769ac79a4d3d97b89ce" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 16 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.242850000000544, + "ttlbMs": 8.38339300000007 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 16, + "tweet_id": null, + "txt": "Generated comment participant-strict", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 24.396421999999802, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "8 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "8 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 25.725431999999273, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "8 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "8 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment participant-strict", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-no-vote", + "case": "standard-no-vote", + "auth": "standard", + "seed": "a19fc3283ad7", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-no-vote" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 9, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLW5vLXZvdGUifQ==", + "byte_length": 79, + "sha256": "9f287c995e0074b56cd64e082a63e3a5fcc89462cf8effad8dff0c51f35030aa" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-KY33tD/FPYZ1Av9hjxH/2Q\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:50 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJ0aWQiOjE3LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "737e56b582e5241f44a2ca07b72f6b17545d1b9706a6abe126b03c7ed0d3aa61" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 17 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 5.00220200000058, + "ttlbMs": 5.115286000001106 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 17, + "tweet_id": null, + "txt": "Generated comment standard-no-vote", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-no-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-agree", + "case": "standard-agree", + "auth": "standard", + "seed": "850634a518cf", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-agree", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 10, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLWFncmVlIiwidm90ZSI6LTF9", + "byte_length": 87, + "sha256": "37269dd4124a2f74e5ef0aff98f257700194dba50257db44b61e1533299e6d53" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-jWLtklbdaDHsESgPPC5FEQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:50 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjE4LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "c4ba089d10edb12045c63fec7fe0e427e247728cacc5dba19342a97b27f07c52" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 18 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.999132999999347, + "ttlbMs": 7.136967000000368 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 18, + "tweet_id": null, + "txt": "Generated comment standard-agree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 18, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 18, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-agree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-disagree", + "case": "standard-disagree", + "auth": "standard", + "seed": "aff4240f3237", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-disagree", + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 11, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLWRpc2FncmVlIiwidm90ZSI6MX0=", + "byte_length": 89, + "sha256": "1049c27d52dad03dbdc43e6541202ba72316a7d4e5a0578dabfdd6b1510db70c" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-DO+fHO0tIhLbV/dlbtkggA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:51 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjE5LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "87bcb724d453fd49d2d2ec45ac7ca1552715a550d596449c4114414b82241325" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 19 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.509642999999414, + "ttlbMs": 8.65714399999888 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 19, + "tweet_id": null, + "txt": "Generated comment standard-disagree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 19, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 19, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-pass", + "case": "standard-pass", + "auth": "standard", + "seed": "d291fd775844", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-pass", + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 12, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLXBhc3MiLCJ2b3RlIjowfQ==", + "byte_length": 85, + "sha256": "f7e98653d01f1d8879a5946fd68ba9fe154bb0b8987af8bd23f1e0d7906dc60a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-6kTR1N/Qo11XmQirNW8hUA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:51 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjIwLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "7010632f6cb6ea327c759c7ad61fa1c2a72d4788018bf25478301f3249465486" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 20 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.659046999999191, + "ttlbMs": 6.788715000000593 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 20, + "tweet_id": null, + "txt": "Generated comment standard-pass", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 20, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 20, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-seed", + "case": "standard-seed", + "auth": "standard", + "seed": "f15aa62de983", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-seed", + "is_seed": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 13, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLXNlZWQiLCJpc19zZWVkIjp0cnVlfQ==", + "byte_length": 91, + "sha256": "0d703e30b60d9c03452e3f53980e71cff6dde3bd6c8d5359ce6380ce740b326d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-dtkAv/ns+r6ikhwi1GJnhg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:51 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJ0aWQiOjIxLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "34d7628148c3b338dca90beefa5eed8fe2b0fd63470f4679f4d0a137fc919aca" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 21 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 5.365162999998574, + "ttlbMs": 5.4896219999991445 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 21, + "tweet_id": null, + "txt": "Generated comment standard-seed", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-seed", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-seed-explicit-vote", + "case": "standard-seed-explicit-vote", + "auth": "standard", + "seed": "e6e2c292166a", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-seed-explicit-vote", + "is_seed": true, + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 14, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLXNlZWQtZXhwbGljaXQtdm90ZSIsImlzX3NlZWQiOnRydWUsInZvdGUiOi0xfQ==", + "byte_length": 115, + "sha256": "eaa81200f19d4f2eeb84e19d9831d503d3914bb19b8a63ffbff336e033b0b856" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-PAb1cmxxDzm1T3FQgot/kA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:52 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjIyLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "b242c188654dcb1d2c58b257fff9a6ed0117289be7b18a7feb9eba19b21864ab" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 22 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.012140000000727, + "ttlbMs": 8.146891000000323 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 22, + "tweet_id": null, + "txt": "Generated comment standard-seed-explicit-vote", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 22, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 22, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-seed-explicit-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-closed", + "case": "standard-closed", + "auth": "standard", + "seed": "e36d93c6cae7", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-closed" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 14, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLWNsb3NlZCJ9", + "byte_length": 78, + "sha256": "a3ba2ead46167190631f3f97601f610a6fede98c1ebda2dedc86f4c497d1555b" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-gQukeO67bdDfjv7rYuqujw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:52 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 4, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwibWVzc2FnZSI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwic3RhdHVzIjo0MDN9", + "byte_length": 102, + "sha256": "ac00f242422b3b197b949c87b193a090840262a8c6c05a0b06ad17353f7c129f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 4, + "last_byte_ms": 4, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_conversation_is_closed", + "message": "polis_err_conversation_is_closed", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 3.767692999999781, + "ttlbMs": 3.899402999999438 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/standard-strict", + "case": "standard-strict", + "auth": "standard", + "seed": "08eaf85b0e45", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-strict" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 15, + "count": 1, + "recipients": [ + { + "class": "owner", + "address": "Generated Owner " + } + ] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLXN0cmljdCJ9", + "byte_length": 78, + "sha256": "a39f210ddd7135e110a10250148d22817b46341d16838481651e295434a7a498" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-VMg60Pj6gPwUcvWs72oaTg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:53 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjIzLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "7ab4eff7a60a2e792d3aeb470ec036db876678835dd8d235383d8077947c93b8" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 23 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.506477000000814, + "ttlbMs": 8.643894000000728 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 23, + "tweet_id": null, + "txt": "Generated comment standard-strict", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 27.205275000000256, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "15 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "15 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 28.127198000000135, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "15 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "15 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-strict", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-no-vote", + "case": "xid-no-vote", + "auth": "xid", + "seed": "4f5fb1060c06", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-no-vote" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 16, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1uby12b3RlIn0=", + "byte_length": 74, + "sha256": "dfba481391cb645d8de40b7838491b7058bb8d04b0ec881ae34195aae5ae599a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-hfIXmLszZ8NIG6rEDL197A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:53 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjI0LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "388fefc9f9f87c70588c9032ce5d49e47068a4e24446960093fdf902ca29cc7f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 24 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.171550999999454, + "ttlbMs": 7.3102599999983795 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 24, + "tweet_id": null, + "txt": "Generated comment xid-no-vote", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-no-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-agree", + "case": "xid-agree", + "auth": "xid", + "seed": "c6d17dc7999e", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-agree", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 17, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1hZ3JlZSIsInZvdGUiOi0xfQ==", + "byte_length": 82, + "sha256": "d031210ecc815e8fb8b8ff6aac8aa5e856f5db026b589b6c253c2ce589a0fa04" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-aiZy4T6Bvmmshx/6e2bZYA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:54 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjI1LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "de6d31d64978cb98c8db3d0858e318464bfff2145b139a8c9048e913fade56ec" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 25 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.161098999999012, + "ttlbMs": 8.337475000000268 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 25, + "tweet_id": null, + "txt": "Generated comment xid-agree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 25, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 25, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-agree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-disagree", + "case": "xid-disagree", + "auth": "xid", + "seed": "d15da6e4c94f", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-disagree", + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 18, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1kaXNhZ3JlZSIsInZvdGUiOjF9", + "byte_length": 84, + "sha256": "6bd59c2df9722a01596377a7eb059fca02ba696dfeeb4107f97935ff5af00315" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-FNWYcQ0aBv/CON7tEhWzAA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:54 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjI2LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "f691481264ed165498406fd4846194f1193eaf353722daac82a450ff5ac6564b" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 26 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.470470000000205, + "ttlbMs": 7.625512000000526 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 26, + "tweet_id": null, + "txt": "Generated comment xid-disagree", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 26, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 26, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-pass", + "case": "xid-pass", + "auth": "xid", + "seed": "6ea397cead2c", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-pass", + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 19, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1wYXNzIiwidm90ZSI6MH0=", + "byte_length": 80, + "sha256": "10dfa4db37a37dd3159679a18fee15f425bd7b3c6aa4ebd279ec212e190da04d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-HNxu7A1p//eLuUJbnZ0M/A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:54 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjI3LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "173a2b397ae5d5f675a53ca13de185f89c20429bd22a8083a6b1af7298e0fcd1" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 27 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.353106999999, + "ttlbMs": 9.510732999999163 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 27, + "tweet_id": null, + "txt": "Generated comment xid-pass", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 27, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 27, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-seed", + "case": "xid-seed", + "auth": "xid", + "seed": "337524a397a3", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-seed", + "is_seed": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 20, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1zZWVkIiwiaXNfc2VlZCI6dHJ1ZX0=", + "byte_length": 86, + "sha256": "d15d573ac4a54ad4f4246f4b218ac26b13e5d6cd23c5deb333d56129e3fb7aa5" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-k3paL4kc+kU34OcwTy8kbg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:55 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjI4LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "28fe472df73398495dfe993d6e5d8c392db2eb8e7668f5b99c62b04a7d29feaf" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 28 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.071862000000692, + "ttlbMs": 10.239489000001413 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 28, + "tweet_id": null, + "txt": "Generated comment xid-seed", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-seed", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-seed-explicit-vote", + "case": "xid-seed-explicit-vote", + "auth": "xid", + "seed": "4d1fe5ecaaef", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-seed-explicit-vote", + "is_seed": true, + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 21, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1zZWVkLWV4cGxpY2l0LXZvdGUiLCJpc19zZWVkIjp0cnVlLCJ2b3RlIjotMX0=", + "byte_length": 110, + "sha256": "2a3d996f9040f2e2b29dfe136ac7589234e52240ddaf8455ed1c6d79c26e2b13" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-+gBwW4aSc61WT8PQjk3m3A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:55 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjI5LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "84cd1f70eb527514fa5f969ebaf2dcff4f13e914c8a534bb79178b82c30ee597" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 29 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.4355520000008255, + "ttlbMs": 7.577970000000278 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 29, + "tweet_id": null, + "txt": "Generated comment xid-seed-explicit-vote", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 29, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 29, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-seed-explicit-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-closed", + "case": "xid-closed", + "auth": "xid", + "seed": "fb2c07d46028", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-closed" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 21, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1jbG9zZWQifQ==", + "byte_length": 73, + "sha256": "a2d91edbc432c5154be8c9a0a27b29fe026bffaf1635111e9068e64dfaf416f6" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-gQukeO67bdDfjv7rYuqujw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:56 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwibWVzc2FnZSI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwic3RhdHVzIjo0MDN9", + "byte_length": 102, + "sha256": "ac00f242422b3b197b949c87b193a090840262a8c6c05a0b06ad17353f7c129f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_conversation_is_closed", + "message": "polis_err_conversation_is_closed", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 4.52353199999925, + "ttlbMs": 4.659991999998965 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/xid-strict", + "case": "xid-strict", + "auth": "xid", + "seed": "22376a2704cb", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-strict" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 1, + "recipients": [ + { + "class": "owner", + "address": "Generated Owner " + } + ] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1zdHJpY3QifQ==", + "byte_length": 73, + "sha256": "269dee5a99487e2064172773c8de3072782d0fab678afd02271ba9acc9b3a029" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-9oksEiivQUR3NIYy5i2NHg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:56 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjMwLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "be44b532bed7a43d886221f7f4c260f09f0a9af9433706eb31b9a52833fe7053" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 30 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.207064999998693, + "ttlbMs": 9.35060700000031 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 30, + "tweet_id": null, + "txt": "Generated comment xid-strict", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 26.564479000000574, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 27.391984999998385, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-strict", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-no-vote", + "case": "owner-no-vote", + "auth": "owner", + "seed": "ed19fd7405ca", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-no-vote" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLW5vLXZvdGUifQ==", + "byte_length": 76, + "sha256": "6034e2a81e74a8b9fd5065a5453f869cacaf34f45b4db4d07c153efdd6794d4a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-4LNGSmrj/me+A4xNPGMbMg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:57 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 17, + "bytes": { + "base64": "eyJ0aWQiOjMxLCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "190c16ec54c71475324917628753a845644af0021b7ce7654800f98f044c810d" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 17, + "last_byte_ms": 17, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 31 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 16.831826000001456, + "ttlbMs": 16.987828000001173 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 31, + "tweet_id": null, + "txt": "Generated comment owner-no-vote", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 17.033120000000054, + "blocked": false, + "host": "oidc-simulator", + "method": "GET", + "path": "/.well-known/jwks.json", + "port": 3000, + "protocol": "https", + "response": "{\"keys\":[{\"kty\":\"RSA\",\"n\":\"wzwwEqR5p7a6CaG61i3od-GLTyype3t_f0pwwtoA9NsZANcjHaAUR_qzqlNRQlLI687vF1OfbETYLeHIT5V36QGrMfrYR_tYAoaKFixC_wOjt8EBPoeHgaTOAyGf3V3YNwocNU-StyV1X4hPmDjCrapNYpbKIcAJwq5Ij0WBKGNXBcUUbAceRtLqgzf_6x2vcQJeE5nJK5gd41f_jtlK9Xge0Ig6CcdKOI7U3agyI_iNF3SL0bnCfvtDRIkgAzzeN5Yj4S3Z4rJVQ1RgzZmqBmnjw8h06G8wDyaQPf19u4F___gF-dL1md_fVRKL5UL7OZg42hIZzwzdhrxOGcXUFQ\",\"e\":\"AQAB\",\"alg\":\"RS256\",\"kid\":\"NkRGQjI5N0RBNUUwMTYwOEMxQUVGQkJBQTJBODBGNTE2MDA5NDM5RA\",\"use\":\"sig\"}]}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-no-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-agree", + "case": "owner-agree", + "auth": "owner", + "seed": "6310b2cc5ded", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-agree", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLWFncmVlIiwidm90ZSI6LTF9", + "byte_length": 84, + "sha256": "c9b4f651f78329aaf3b92bb2d904cc9af24e4f440a3e3a5231de5168f6b62288" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-rTcanWY4EHMNu/5ZM0lfTg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:57 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjMyLCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "c9b22ea8d94b510dec3bf7b1a5d68912893d85500eb973db64006671e342f59c" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 32 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.33194100000037, + "ttlbMs": 9.463442000000214 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 32, + "tweet_id": null, + "txt": "Generated comment owner-agree", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 32, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 32, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-agree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-disagree", + "case": "owner-disagree", + "auth": "owner", + "seed": "a63fb8d52c40", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-disagree", + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLWRpc2FncmVlIiwidm90ZSI6MX0=", + "byte_length": 86, + "sha256": "3cb6bdf5f43699030e9bd71ad7013b89b4fec731c075740b8464d115eee57f08" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-HKBkiZkPrLwx6QyGjyb8bA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:57 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjMzLCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "0ea6dd68cdadcfe3a5fb819c83659af5bde9f4d708118f333ed16978be802200" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 33 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.25294699999904, + "ttlbMs": 10.40248999999858 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 33, + "tweet_id": null, + "txt": "Generated comment owner-disagree", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 33, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 33, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-pass", + "case": "owner-pass", + "auth": "owner", + "seed": "254d9ad9635b", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-pass", + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLXBhc3MiLCJ2b3RlIjowfQ==", + "byte_length": 82, + "sha256": "f9dccae8204575c932c54c1726d9dc6b8804a61fc618290dc7d328e7c0121bd3" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-fxVmLe+lLQ9RIoHbv4E2Cg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:58 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjM0LCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "00792809917d2a4e655f8bf99107fb3d2182168c31d1c318df1d9268bcc116ed" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 34 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.90893700000015, + "ttlbMs": 9.042272000000594 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 34, + "tweet_id": null, + "txt": "Generated comment owner-pass", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 34, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 34, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-seed", + "case": "owner-seed", + "auth": "owner", + "seed": "52ece2ad6dda", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-seed", + "is_seed": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLXNlZWQiLCJpc19zZWVkIjp0cnVlfQ==", + "byte_length": 88, + "sha256": "e782bcd6d1506807a7b52fcda95d7b5193adab5ee4ccf385574b84a2cea9ab74" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-qqqsJIflREhTxa6ZOq3Krg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:58 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjM1LCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "8bd96cf2a265b2cca898a7d4145998b670351974b7724476bb5e3cc30945d359" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 35 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.5830540000024484, + "ttlbMs": 7.726596000000427 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 35, + "tweet_id": null, + "txt": "Generated comment owner-seed", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-seed", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-seed-explicit-vote", + "case": "owner-seed-explicit-vote", + "auth": "owner", + "seed": "02bf871dc9ef", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-seed-explicit-vote", + "is_seed": true, + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLXNlZWQtZXhwbGljaXQtdm90ZSIsImlzX3NlZWQiOnRydWUsInZvdGUiOi0xfQ==", + "byte_length": 112, + "sha256": "a90e74e7b39256bdc1c71c41175e75b2ce93cfaed43bd918961bc76407c2a980" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-NO62tVxpfXzkcgjjIl/Ltg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:59 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 11, + "bytes": { + "base64": "eyJ0aWQiOjM2LCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "ccfe23cb9440eac235ca01cf215f4caa90dccd9db4eb2c83c86ae7795e5f469d" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 11, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 36 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.616281999999046, + "ttlbMs": 10.771199999999226 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 36, + "tweet_id": null, + "txt": "Generated comment owner-seed-explicit-vote", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 0, + "tid": 36, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 0, + "tid": 36, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-seed-explicit-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/owner-closed", + "case": "owner-closed", + "auth": "owner", + "seed": "49335a12c0ce", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-closed" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLWNsb3NlZCJ9", + "byte_length": 75, + "sha256": "4fd1380cc94d703ad9e707af7a2180c69f9e5b6ac485aaebde84f562122c0fbb" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-gQukeO67bdDfjv7rYuqujw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:18:59 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwibWVzc2FnZSI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwic3RhdHVzIjo0MDN9", + "byte_length": 102, + "sha256": "ac00f242422b3b197b949c87b193a090840262a8c6c05a0b06ad17353f7c129f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_conversation_is_closed", + "message": "polis_err_conversation_is_closed", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 7.149799999999232, + "ttlbMs": 7.289050999999745 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/owner-strict", + "case": "owner-strict", + "auth": "owner", + "seed": "f6ee601c8cb6", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment owner-strict" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 1, + "recipients": [ + { + "class": "owner", + "address": "Generated Owner " + } + ] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG93bmVyLXN0cmljdCJ9", + "byte_length": 75, + "sha256": "4aa2f309b2f374931f46b5f1e9a10d97e7f19d4121e35364b2feb526accd5a11" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-Ufn9NnG3zKzdIMSykyiVKw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:00 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjM3LCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "cdf8fcd9bd27c9be9ec6bf84494e46e54f6f81ce8a310caa9166fb6d381aa108" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 37 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.623359000001074, + "ttlbMs": 9.763652000001457 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 37, + "tweet_id": null, + "txt": "Generated comment owner-strict", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 25.990516000001662, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 26.915481, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment owner-strict", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-no-vote", + "case": "admin-no-vote", + "auth": "admin", + "seed": "ddf9c258a0da", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-no-vote" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLW5vLXZvdGUifQ==", + "byte_length": 76, + "sha256": "354bc5310fc2c96874483d8f5c5ba3fb41b961875d3980ff46ba4f27f89224cb" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-oVoG+LtGKYMtDxM4s7f/Ow\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:00 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjM4LCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "366322ca3c98f4b440663a5e5d5e060ea9bd7b4fa18aa77f219b785aa2c087b0" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 38 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.337343000002875, + "ttlbMs": 7.459094000001642 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 38, + "tweet_id": null, + "txt": "Generated comment admin-no-vote", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 1, + "subscribed": 0, + "uid": 2, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 1, + "subscribed": 0, + "uid": 2, + "vote_count": 0, + "zid": 1 + } + ] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-no-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-agree", + "case": "admin-agree", + "auth": "admin", + "seed": "7f476a8dc813", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-agree", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLWFncmVlIiwidm90ZSI6LTF9", + "byte_length": 84, + "sha256": "32644063305da86e94c126b9ff2939680e598af40c59a4ba164f670456f076e3" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-mc28Plzoh95ni8J6obLEbA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:00 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjM5LCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "f647e8600f1a0d5bceeb6bcc325dd7a9c232ee1aef919ccad2e208d2c5c2fb1a" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 39 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.584310000002006, + "ttlbMs": 8.710019000001921 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 39, + "tweet_id": null, + "txt": "Generated comment admin-agree", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 1, + "tid": 39, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 1, + "tid": 39, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-agree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-disagree", + "case": "admin-disagree", + "auth": "admin", + "seed": "b609fffa4be2", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-disagree", + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLWRpc2FncmVlIiwidm90ZSI6MX0=", + "byte_length": 86, + "sha256": "f86be5520d5236213c8ac399133545fbb74f95038040f126610e6a0dc11630ae" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-sUgKgTgi40JN+2AzAbmFXw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:01 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjQwLCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "83ae2628f8f729080f8d675a88a760fdbab3e9d614ef8bebca2e9f66d6c67191" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 12, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 40 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 11.762041000001773, + "ttlbMs": 11.898667000001296 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 40, + "tweet_id": null, + "txt": "Generated comment admin-disagree", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 1, + "tid": 40, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 1, + "tid": 40, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-pass", + "case": "admin-pass", + "auth": "admin", + "seed": "b630f5d579df", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-pass", + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLXBhc3MiLCJ2b3RlIjowfQ==", + "byte_length": 82, + "sha256": "fd2760dd90c0390ff147521d4660cfbe5865a2e19c75e3e31fd8be1cc4503581" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-biKKjet5sDhli8J+DNCKgQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:01 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjQxLCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "6662d959f2748990c1ffeb3388eb9e38974f594584201ec73a2e988188b1e3e3" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 41 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.348524000000907, + "ttlbMs": 9.487275000003137 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 41, + "tweet_id": null, + "txt": "Generated comment admin-pass", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 1, + "tid": 41, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 1, + "tid": 41, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-seed", + "case": "admin-seed", + "auth": "admin", + "seed": "4715bc0e979b", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-seed", + "is_seed": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLXNlZWQiLCJpc19zZWVkIjp0cnVlfQ==", + "byte_length": 88, + "sha256": "53d4715cfa0a930bad4a7bad16a0cadb8a1019ce23f5353e2cccf1a789111c56" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-fhY7R0khjl+EdsITuFvT6w\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:02 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjQyLCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "53ce092f20b8ca5d6720316890356f0ee82d926897db20cdfb9995f28d8dece6" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 42 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.880221999999776, + "ttlbMs": 8.04859800000122 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 42, + "tweet_id": null, + "txt": "Generated comment admin-seed", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-seed", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-seed-explicit-vote", + "case": "admin-seed-explicit-vote", + "auth": "admin", + "seed": "3fa28f1ffcee", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-seed-explicit-vote", + "is_seed": true, + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLXNlZWQtZXhwbGljaXQtdm90ZSIsImlzX3NlZWQiOnRydWUsInZvdGUiOi0xfQ==", + "byte_length": 112, + "sha256": "871b0c28c808aeedfdf88f7c97fb9acbe8191df9857c8f3623983500b2a2b367" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-zuQqAJQdhjoAjQGtZ7RB3w\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:02 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjQzLCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "585d292d3702f8bb81fd15a867874c83fb0d75b99f2e12cffe89321f3c191796" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 43 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.097347999999329, + "ttlbMs": 8.301848999999493 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 43, + "tweet_id": null, + "txt": "Generated comment admin-seed-explicit-vote", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 1, + "tid": 43, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 1, + "tid": 43, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-seed-explicit-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/admin-closed", + "case": "admin-closed", + "auth": "admin", + "seed": "bd48b426ec5a", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-closed" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLWNsb3NlZCJ9", + "byte_length": 75, + "sha256": "6ef67df66efb5ea356eadd4b12499d81f2958a4c720c7093086a958f1e26e34d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-gQukeO67bdDfjv7rYuqujw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:03 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwibWVzc2FnZSI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwic3RhdHVzIjo0MDN9", + "byte_length": 102, + "sha256": "ac00f242422b3b197b949c87b193a090840262a8c6c05a0b06ad17353f7c129f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_conversation_is_closed", + "message": "polis_err_conversation_is_closed", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 5.177870000003168, + "ttlbMs": 5.329371000003448 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/admin-strict", + "case": "admin-strict", + "auth": "admin", + "seed": "1655e6359cf8", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:admin" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment admin-strict" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "d9b4fceaaad12fc20cef8fe6" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 1, + "recipients": [ + { + "class": "owner", + "address": "Generated Owner " + } + ] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:admin" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGFkbWluLXN0cmljdCJ9", + "byte_length": 75, + "sha256": "95665b3cc8a813bb174311e2ee7765ba53a382f9720fc974fb5d52f76aef1c48" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-ULbdHHD9HxuCIh7673Szlg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:03 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 15, + "bytes": { + "base64": "eyJ0aWQiOjQ0LCJjdXJyZW50UGlkIjoxfQ==", + "byte_length": 25, + "sha256": "7146cd8fcc4e5042600ab2fa5f594b2a2dd8f88a3563bdc26e42b71e5080d6f5" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 15, + "last_byte_ms": 16, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 1, + "tid": 44 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 15.386940999997023, + "ttlbMs": 15.523941999999806 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 1, + "quote_src_url": null, + "tid": 44, + "tweet_id": null, + "txt": "Generated comment admin-strict", + "uid": 2, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 32.382101000002876, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 33.52365099999952, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment admin-strict", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-no-vote", + "case": "site-moderator-no-vote", + "auth": "site-moderator", + "seed": "33d9b2fa06a8", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-no-vote" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLW5vLXZvdGUifQ==", + "byte_length": 85, + "sha256": "e731c963c2c3b2e5476d515ec8cddb6520934c5987c102640d50bf296c7b577e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-qoDh70X9zLt7166tUXDdpA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:04 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjQ1LCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "28e8cbe4f10a261415a5732462f48567da9caf5946c705b54bc97cc48362e4bd" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 11, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 45 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 11.468331000000035, + "ttlbMs": 11.621165000000474 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 45, + "tweet_id": null, + "txt": "Generated comment site-moderator-no-vote", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 3, + "subscribed": 0, + "uid": 100004, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 3, + "subscribed": 0, + "uid": 100004, + "vote_count": 0, + "zid": 1 + } + ] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-no-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-agree", + "case": "site-moderator-agree", + "auth": "site-moderator", + "seed": "79e7f82181af", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-agree", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLWFncmVlIiwidm90ZSI6LTF9", + "byte_length": 93, + "sha256": "3525e96bcf1805e391db718f8307d3a6bc204f2919c8f8040e26cea0cba90f41" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-uBT9YapA1AClpmjDVBMWCQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:04 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjQ2LCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "ca0b56d2fd91b2aecb00e05b36a00b40089daf47febb9c71fba8e215587b03bd" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 12, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 46 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 12.06996000000072, + "ttlbMs": 12.228794000002381 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 46, + "tweet_id": null, + "txt": "Generated comment site-moderator-agree", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 3, + "tid": 46, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 3, + "tid": 46, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-agree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-disagree", + "case": "site-moderator-disagree", + "auth": "site-moderator", + "seed": "c49976dfe14f", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-disagree", + "vote": 1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLWRpc2FncmVlIiwidm90ZSI6MX0=", + "byte_length": 95, + "sha256": "6f367aa28f73c7b5696e530fdc9502bd0efd9f43e4310f0873daea17837a3279" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-S0Al0QBy6FgwGA88GdXTsA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:04 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjQ3LCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "8372cd67bb8b248134a5db0d2e1abe9433b99af321f54695027bee4a4a485a20" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 12, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 47 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 12.266460999999254, + "ttlbMs": 12.417044999998325 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 47, + "tweet_id": null, + "txt": "Generated comment site-moderator-disagree", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 3, + "tid": 47, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 3, + "tid": 47, + "vote": 1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "disagree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-disagree", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-pass", + "case": "site-moderator-pass", + "auth": "site-moderator", + "seed": "947d136c55bc", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-pass", + "vote": 0 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLXBhc3MiLCJ2b3RlIjowfQ==", + "byte_length": 91, + "sha256": "9b292efa534993e7b642eb2ef465fd1e27545d3aa60600b3faa39ce1f08a7f87" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-by8w68v3NWcdY3m5E7G89Q\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:05 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjQ4LCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "0647db88dbbd1ca7f67869971c211105e7bd845dd1201d43eaf8ac8fe7d20f0c" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 12, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 48 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 11.919167000000016, + "ttlbMs": 12.070668000000296 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 48, + "tweet_id": null, + "txt": "Generated comment site-moderator-pass", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 3, + "tid": 48, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 3, + "tid": 48, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-pass", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-seed", + "case": "site-moderator-seed", + "auth": "site-moderator", + "seed": "f874326bbc62", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-seed", + "is_seed": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLXNlZWQiLCJpc19zZWVkIjp0cnVlfQ==", + "byte_length": 97, + "sha256": "e2038f60e751a02fc7cccc9c20686b6e014f9ae1d8e5d386f8e4712d63689cc0" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-hw66Vyub26Ew/llw5h29qA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:05 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjQ5LCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "255c40770da6efbafa69fbaec4a9ed9392db1dc124b090df72398037e0f2a1a3" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 49 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.531191999998555, + "ttlbMs": 9.843236000000616 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 49, + "tweet_id": null, + "txt": "Generated comment site-moderator-seed", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-seed", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-seed-explicit-vote", + "case": "site-moderator-seed-explicit-vote", + "auth": "site-moderator", + "seed": "201051c1eccf", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-seed-explicit-vote", + "is_seed": true, + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLXNlZWQtZXhwbGljaXQtdm90ZSIsImlzX3NlZWQiOnRydWUsInZvdGUiOi0xfQ==", + "byte_length": 121, + "sha256": "9c6fd5c275e35e88938dc1bfc1dd602fe6f4c0adb0d68622e82aa47749282af0" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-B2CmQygB3PlgnKKGf0sgXA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:06 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjUwLCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "0138e44490544600e86a4ed38db4ef3db6b25d30a1f2fba2beb3ad82c64eb0a1" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 50 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.503294999998616, + "ttlbMs": 6.637129999999161 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 50, + "tweet_id": null, + "txt": "Generated comment site-moderator-seed-explicit-vote", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 3, + "tid": 50, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 3, + "tid": 50, + "vote": -1, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "agree" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-seed-explicit-vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/site-moderator-closed", + "case": "site-moderator-closed", + "auth": "site-moderator", + "seed": "22505c5b89dd", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-closed" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLWNsb3NlZCJ9", + "byte_length": 84, + "sha256": "1366aa496068156102e2b0703fe7916ae4ff0912e15ed16860efb77edf8d25b4" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-gQukeO67bdDfjv7rYuqujw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:06 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwibWVzc2FnZSI6InBvbGlzX2Vycl9jb252ZXJzYXRpb25faXNfY2xvc2VkIiwic3RhdHVzIjo0MDN9", + "byte_length": 102, + "sha256": "ac00f242422b3b197b949c87b193a090840262a8c6c05a0b06ad17353f7c129f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_conversation_is_closed", + "message": "polis_err_conversation_is_closed", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 7.843221999999514, + "ttlbMs": 8.21218299999964 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/site-moderator-strict", + "case": "site-moderator-strict", + "auth": "site-moderator", + "seed": "97e2b6f8b2bb", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:site-moderator" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-strict" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-moderator" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 22, + "count": 1, + "recipients": [ + { + "class": "owner", + "address": "Generated Owner " + } + ] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:site-moderator" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLXN0cmljdCJ9", + "byte_length": 84, + "sha256": "b329e638f2be5ca54990d28b750a414491cabb52c87f862fdfaf9ba7776a7c49" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-uRf8C5i/ypgQ4wCP+DhmNg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:06 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjUxLCJjdXJyZW50UGlkIjozfQ==", + "byte_length": 25, + "sha256": "fe71063355d3045a9c1b82a3f2382ff4d9b03b347bfd9721ae6cde2c92aa4fe6" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 3, + "tid": 51 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.83867299999838, + "ttlbMs": 6.9636739999987185 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 3, + "quote_src_url": null, + "tid": 51, + "tweet_id": null, + "txt": "Generated comment site-moderator-strict", + "uid": 100004, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 23.266829000000143, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 26.090306999998575, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "22 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-strict", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/oidc-first-use", + "case": "oidc-first-use", + "auth": "comments-owner-1", + "seed": "3c666c45d3a1", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:comments-owner-1" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-first-use" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "818cc4edffe62a671450d4ed" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 23, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:comments-owner-1" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtZmlyc3QtdXNlIn0=", + "byte_length": 77, + "sha256": "84179a50e24960ee337eb8c026cbf54c5972894da92cfb65cbad1dcd6cfccc41" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-awGOgGy0cyTJpRO19yl7gg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:07 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 14, + "bytes": { + "base64": "eyJ0aWQiOjUyLCJjdXJyZW50UGlkIjo1fQ==", + "byte_length": 25, + "sha256": "fc4a6ad82a78b9d67d98baa6eb8addb93c8b3491a920fd2bd34789508532ff55" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 14, + "last_byte_ms": 14, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 5, + "tid": 52 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 14.050306000001001, + "ttlbMs": 14.18434900000284 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 5, + "quote_src_url": null, + "tid": 52, + "tweet_id": null, + "txt": "Generated comment oidc-first-use", + "uid": 5, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 6, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 5, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:oidc_user_mappings": { + "added": [ + { + "created": 1700000000000, + "oidc_sub": "818cc4edffe62a671450d4ed", + "uid": 5 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 5, + "subscribed": 0, + "uid": 5, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 5, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": "test.user.1@polis.test", + "hname": "Test User 1", + "is_owner": true, + "oinvite": null, + "site_id": "$site_id:2", + "site_owner": true, + "tut": 0, + "uid": 5, + "username": "test.user.1", + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 5, + "subscribed": 0, + "uid": 5, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment oidc-first-use", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/oidc-repeat", + "case": "oidc-repeat", + "auth": "comments-owner-1", + "seed": "955a04ed70ff", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:comments-owner-1" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment oidc-repeat" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "818cc4edffe62a671450d4ed" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 24, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:comments-owner-1" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG9pZGMtcmVwZWF0In0=", + "byte_length": 74, + "sha256": "6354b85ae2678e73ecc33dba18bd095dd9eefaf5a7c3b4e0ee73681451493c08" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-Yh22BFmw/SS1zZBSkMNYtg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:07 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjUzLCJjdXJyZW50UGlkIjo1fQ==", + "byte_length": 25, + "sha256": "602fcc0cd9f85b6fa2da22c2b4a50477be9625f4301983f67275a96434473154" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 5, + "tid": 53 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.818463999999949, + "ttlbMs": 6.941172999999253 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 5, + "quote_src_url": null, + "tid": 53, + "tweet_id": null, + "txt": "Generated comment oidc-repeat", + "uid": 5, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment oidc-repeat", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-first-use", + "case": "xid-first-use", + "auth": "unauthenticated", + "seed": "961466c14be1", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-first-use", + "xid": "generated-new-comment-member" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 25, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1maXJzdC11c2UiLCJ4aWQiOiJnZW5lcmF0ZWQtbmV3LWNvbW1lbnQtbWVtYmVyIn0=", + "byte_length": 113, + "sha256": "36b8f5b126aef0cdfc8f55eb5c923638a1490fe8578277a7a5415113aab74550" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "779", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"30b-+oB6PWTQVTayPK2mqty9Ig\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:08 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 18, + "bytes": { + "base64": "eyJ0aWQiOjU0LCJjdXJyZW50UGlkIjo2LCJhdXRoIjp7InRva2VuIjoiJGp3dDo4NmUxMGQ0OTJhZTNmYThlZDVjN2RhY2M1ZmFjMTZjNmNlMDhkYWZmNzc3NjFhZTJmZmZhMzI4MmI0YTNmMWM0IiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImV4cGlyZXNfaW4iOjMxNTM2MDAwfX0=", + "byte_length": 158, + "sha256": "5ddf773c046cc879f0e7c79cccaea48fa8b1e534670d9c68e6096043799e72cb" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 18, + "last_byte_ms": 18, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "779", + "etag": "W/\"30b-+oB6PWTQVTayPK2mqty9Ig\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 6, + "sub": "xid:generated-new-comment-member", + "uid": 6, + "xid": "generated-new-comment-member", + "xid_participant": true + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "currentPid": 6, + "tid": 54 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 18.109584999998333, + "ttlbMs": 18.260001999999076 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 6, + "quote_src_url": null, + "tid": 54, + "tweet_id": null, + "txt": "Generated comment xid-first-use", + "uid": 6, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 7, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 6, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 6, + "subscribed": 0, + "uid": 6, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 6, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:3", + "site_owner": true, + "tut": 0, + "uid": 6, + "username": null, + "zinvite": null + } + ], + "removed": [] + }, + "pg:xids": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "owner": 1, + "pid": 6, + "uid": 6, + "x_email": null, + "x_name": null, + "x_profile_image_url": null, + "xid": "generated-new-comment-member", + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 6, + "sub": "xid:generated-new-comment-member", + "uid": 6, + "xid": "generated-new-comment-member", + "xid_participant": true + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 6, + "subscribed": 0, + "uid": 6, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-first-use", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-existing-bare", + "case": "xid-existing-bare", + "auth": "unauthenticated", + "seed": "0aa45dc4e312", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-existing-bare", + "xid": "generated-member" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 26, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1leGlzdGluZy1iYXJlIiwieGlkIjoiZ2VuZXJhdGVkLW1lbWJlciJ9", + "byte_length": 105, + "sha256": "03057d2adfd56233d72e4cc8864b0da19a7baab0b418da1209e43000562335c6" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "747", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"2eb-1VqUzGVvggyW14wx732kQg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:08 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjU1LCJjdXJyZW50UGlkIjoyLCJhdXRoIjp7InRva2VuIjoiJGp3dDpiYTQ0MDQyNTAyZDVmNzdmZmZmZjMzMzJlNTJiYWE1Yjk4NTY5MGI0NWNhMzIyYWM1NDkwNTY1MmQxODUzZjBjIiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImV4cGlyZXNfaW4iOjMxNTM2MDAwfX0=", + "byte_length": 158, + "sha256": "3c0e412f54a680de45a1023dedc80facdc95b0c0c772d880d0460b0655b0602c" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "747", + "etag": "W/\"2eb-1VqUzGVvggyW14wx732kQg\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 2, + "sub": "xid:generated-member", + "uid": 3, + "xid": "generated-member", + "xid_participant": true + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "currentPid": 2, + "tid": 55 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.687387000001763, + "ttlbMs": 7.835888000001432 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 55, + "tweet_id": null, + "txt": "Generated comment xid-existing-bare", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 2, + "sub": "xid:generated-member", + "uid": 3, + "xid": "generated-member", + "xid_participant": true + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-existing-bare", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-request-precedence", + "case": "xid-request-precedence", + "auth": "xid", + "seed": "591ca4241efa", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-request-precedence", + "xid": "generated-comment-override" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-comment-override" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 27, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1yZXF1ZXN0LXByZWNlZGVuY2UiLCJ4aWQiOiJnZW5lcmF0ZWQtY29tbWVudC1vdmVycmlkZSJ9", + "byte_length": 120, + "sha256": "aec6d38b9488c8a2052928f0a38181b8a690f4f3b8b22145fea0e6c610bd4939" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "773", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"305-cGq1VGWNJWhGL3hbdQwlhg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:09 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 18, + "bytes": { + "base64": "eyJ0aWQiOjU2LCJjdXJyZW50UGlkIjo3LCJhdXRoIjp7InRva2VuIjoiJGp3dDpmY2FiM2Y2OTkxOGQ2ODk3NjY5NDNjMzMxZjY0OGI4MTI0ZjAzNmE4ZWM4MWQzZWE5ZTg5N2I4NDY3MzE0MTk3IiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImV4cGlyZXNfaW4iOjMxNTM2MDAwfX0=", + "byte_length": 158, + "sha256": "693bd66c8eb298e2456379e6d4d73e8816b90949b2be3e0d9595837fbf5be87a" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 17, + "last_byte_ms": 18, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "773", + "etag": "W/\"305-cGq1VGWNJWhGL3hbdQwlhg\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 7, + "sub": "xid:generated-comment-override", + "uid": 7, + "xid": "generated-comment-override", + "xid_participant": true + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "currentPid": 7, + "tid": 56 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 17.384122000003117, + "ttlbMs": 17.54166400000031 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 7, + "quote_src_url": null, + "tid": 56, + "tweet_id": null, + "txt": "Generated comment xid-request-precedence", + "uid": 7, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 8, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 7, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 7, + "subscribed": 0, + "uid": 7, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 7, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:4", + "site_owner": true, + "tut": 0, + "uid": 7, + "username": null, + "zinvite": null + } + ], + "removed": [] + }, + "pg:xids": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "owner": 1, + "pid": 7, + "uid": 7, + "x_email": null, + "x_name": null, + "x_profile_image_url": null, + "xid": "generated-comment-override", + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 7, + "sub": "xid:generated-comment-override", + "uid": 7, + "xid": "generated-comment-override", + "xid_participant": true + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 7, + "subscribed": 0, + "uid": 7, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-request-precedence", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-required", + "case": "xid-required", + "auth": "unauthenticated", + "seed": "86029c052ea3", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-required" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 27, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1yZXF1aXJlZCJ9", + "byte_length": 75, + "sha256": "78f1b323254cccd85cbecc1c5f88148f301a7fdf7ac799f43b168e1592a0448f" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "82", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"52-wqyFVhfBXJlyCxDO5SHRug\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:09 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl94aWRfcmVxdWlyZWQiLCJtZXNzYWdlIjoicG9saXNfZXJyX3hpZF9yZXF1aXJlZCIsInN0YXR1cyI6NDAzfQ==", + "byte_length": 82, + "sha256": "5df1c63eff397fad6a45b07417d7d928735922eb2f726ff95816f86d29deb81b" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_xid_required", + "message": "polis_err_xid_required", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 2.859852999998111, + "ttlbMs": 2.9698959999986982 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/xid-whitelisted", + "case": "xid-whitelisted", + "auth": "xid", + "seed": "1f945d9882be", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-whitelisted" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 28, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC13aGl0ZWxpc3RlZCJ9", + "byte_length": 78, + "sha256": "4d568d6c1080a574f3545b16d52e334c51cb10523a3ab0cdb43c3d9948b7117b" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-WjYevIxWJB7jDbiHFg/c0w\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:10 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjU3LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "e61b36485d654bf5fdff0c01119ccf822bca1c0c94f5af8502fd8ff40cacdc37" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 57 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.551010999999562, + "ttlbMs": 7.6907199999986915 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 57, + "tweet_id": null, + "txt": "Generated comment xid-whitelisted", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment xid-whitelisted", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/xid-refused", + "case": "xid-refused", + "auth": "unauthenticated", + "seed": "dd7727f9b1b4", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment xid-refused", + "xid": "generated-denied" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 28, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHhpZC1yZWZ1c2VkIiwieGlkIjoiZ2VuZXJhdGVkLWRlbmllZCJ9", + "byte_length": 99, + "sha256": "f3b6c6b7ae08fcb8b71cb654275f5f9d83730a349f440540b184dc098f669b5a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 403, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "88", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"58-aNR8CK2b1psCQr5LMtaRMw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:10 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl94aWRfbm90X2FsbG93ZWQiLCJtZXNzYWdlIjoicG9saXNfZXJyX3hpZF9ub3RfYWxsb3dlZCIsInN0YXR1cyI6NDAzfQ==", + "byte_length": 88, + "sha256": "2d008212a9f3939e7c200ae5ff1c29dafe6da35606cfd0eb9217183586179b3f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_xid_not_allowed", + "message": "polis_err_xid_not_allowed", + "status": 403 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 403, + "ttfbMs": 3.3281480000005104, + "ttlbMs": 3.4357730000010633 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/treevite-pid0", + "case": "treevite-pid0", + "auth": "pid0", + "seed": "0bc62762587d", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment treevite-pid0" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:1" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 28, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:pid0" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHRyZWV2aXRlLXBpZDAifQ==", + "byte_length": 76, + "sha256": "4f44ab632219f739e858ba317f93570b94fd02c7d7f865011312d33a1ee2ae3a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-ZRYVdiEuBd2zSGlLeBuBpg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:10 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJ0aWQiOjU4LCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "b2d4215a19de2115b33fd1a340ac8ced22eb4803e58bcafff1707143a354616c" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 58 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 5.243703000000096, + "ttlbMs": 5.378454000001511 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 58, + "tweet_id": null, + "txt": "Generated comment treevite-pid0", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment treevite-pid0", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/treevite-participant", + "case": "treevite-participant", + "auth": "participant", + "seed": "1cdafb08f7af", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment treevite-participant" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 29, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHRyZWV2aXRlLXBhcnRpY2lwYW50In0=", + "byte_length": 83, + "sha256": "90867a342c03256ebe6d965985c0e03480931dcb27bda6109b691463cfee7976" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-qgYFl/xK27/dsZ8OAWLP5A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:11 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 11, + "bytes": { + "base64": "eyJ0aWQiOjU5LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "67371c78158721163208b183a234d4952773c32136306502f3ba51ed0cf96b0f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 11, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 59 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.61582400000043, + "ttlbMs": 10.758992000002763 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 59, + "tweet_id": null, + "txt": "Generated comment treevite-participant", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment treevite-participant", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/treevite-standard", + "case": "treevite-standard", + "auth": "standard", + "seed": "1be2d0ba6a17", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment treevite-standard" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-standard" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 30, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHRyZWV2aXRlLXN0YW5kYXJkIn0=", + "byte_length": 80, + "sha256": "06305fe7e2b808d68e539dc4332549556e67839239c664656efd149144444632" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-vtLXLeR1WBYI8ZdO2m3f0w\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:11 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjYwLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "b306140918ac54853a255c156f1b5c8f10f1a48ce90b7ff3c6c07ace86055df2" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 60 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.444017000001622, + "ttlbMs": 8.76535199999853 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 60, + "tweet_id": null, + "txt": "Generated comment treevite-standard", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment treevite-standard", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/treevite-xid", + "case": "treevite-xid", + "auth": "xid", + "seed": "3c6c64ee6f25", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:xid" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment treevite-xid" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "xid:generated-member", + "xid": "generated-member" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 31, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:xid" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHRyZWV2aXRlLXhpZCJ9", + "byte_length": 75, + "sha256": "c0527a340894e0a3d8e2508a8675441a21fd72e7f107debe877f50a2a7e72270" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-HxkBkaAbILRnPvTPGpJGUA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:12 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjYxLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "d78cecec7f58b2ce3aa6eb4bd5966103686143e290c5277bd8d83d12f6065acb" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 61 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.866236000001663, + "ttlbMs": 10.05798700000014 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 61, + "tweet_id": null, + "txt": "Generated comment treevite-xid", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment treevite-xid", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/treevite-owner", + "case": "treevite-owner", + "auth": "owner", + "seed": "c431142bf8c7", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment treevite-owner" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 31, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHRyZWV2aXRlLW93bmVyIn0=", + "byte_length": 77, + "sha256": "e32f962b0931e873b85413cab72af92b41a454975bd987d5d3be7c709b373116" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-9mbp29/aU67iQ21N+CY19Q\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:12 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 13, + "bytes": { + "base64": "eyJ0aWQiOjYyLCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "087eb2ab9be61356c7bc3c26d26c76328a00113c1cbfb52e4da42cd2c2415986" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 13, + "last_byte_ms": 13, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 62 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 12.548629000000801, + "ttlbMs": 12.692589000002044 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 62, + "tweet_id": null, + "txt": "Generated comment treevite-owner", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment treevite-owner", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/treevite-anonymous-refused", + "case": "treevite-anonymous-refused", + "auth": "unauthenticated", + "seed": "1c68320e270e", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment treevite-anonymous-refused" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 31, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHRyZWV2aXRlLWFub255bW91cy1yZWZ1c2VkIn0=", + "byte_length": 89, + "sha256": "87fb4209283b45225d0311d73a5bb2c7bf2a8e1f762b6da254d02646c8d4ccba" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-b49g3KHZAeJ+h7h4DsJf6w\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:13 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl90cmVldml0ZV9hdXRoX3JlcXVpcmVkIiwibWVzc2FnZSI6InBvbGlzX2Vycl90cmVldml0ZV9hdXRoX3JlcXVpcmVkIiwic3RhdHVzIjo0MDF9", + "byte_length": 102, + "sha256": "737e48d7205112ae581dbc497bcc33e38b818ae702877cecd446fc7cafb2fe9a" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_treevite_auth_required", + "message": "polis_err_treevite_auth_required", + "status": 401 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 8.623601999999664, + "ttlbMs": 8.785436000001937 + }, + "effects": { + "db": { + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:5", + "site_owner": true, + "tut": 0, + "uid": 8, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/treevite-xid-refused", + "case": "treevite-xid-refused", + "auth": "unauthenticated", + "seed": "252e16290156", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment treevite-xid-refused", + "xid": "generated-treevite-new" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 31, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHRyZWV2aXRlLXhpZC1yZWZ1c2VkIiwieGlkIjoiZ2VuZXJhdGVkLXRyZWV2aXRlLW5ldyJ9", + "byte_length": 114, + "sha256": "669a3d83c922b4ad41e3b29f3071ede5769b9df8facdfccf39499c168f823cc1" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-b49g3KHZAeJ+h7h4DsJf6w\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:14 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 11, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl90cmVldml0ZV9hdXRoX3JlcXVpcmVkIiwibWVzc2FnZSI6InBvbGlzX2Vycl90cmVldml0ZV9hdXRoX3JlcXVpcmVkIiwic3RhdHVzIjo0MDF9", + "byte_length": 102, + "sha256": "737e48d7205112ae581dbc497bcc33e38b818ae702877cecd446fc7cafb2fe9a" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 11, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_treevite_auth_required", + "message": "polis_err_treevite_auth_required", + "status": 401 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 10.59444799999983, + "ttlbMs": 10.750490999998874 + }, + "effects": { + "db": { + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:6", + "site_owner": true, + "tut": 0, + "uid": 9, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/treevite-oidc-first-refused", + "case": "treevite-oidc-first-refused", + "auth": "comments-owner-2", + "seed": "da10f6abc8c1", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:comments-owner-2" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment treevite-oidc-first-refused" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "23229ecdc3ed7bc3dff205e4" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 31, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:comments-owner-2" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHRyZWV2aXRlLW9pZGMtZmlyc3QtcmVmdXNlZCJ9", + "byte_length": 90, + "sha256": "8a4e840fbad4bcc7a6103c0d74e2f08ca6472cce73c9017bcdb95ee4fab600ef" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-b49g3KHZAeJ+h7h4DsJf6w\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:14 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 6, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl90cmVldml0ZV9hdXRoX3JlcXVpcmVkIiwibWVzc2FnZSI6InBvbGlzX2Vycl90cmVldml0ZV9hdXRoX3JlcXVpcmVkIiwic3RhdHVzIjo0MDF9", + "byte_length": 102, + "sha256": "737e48d7205112ae581dbc497bcc33e38b818ae702877cecd446fc7cafb2fe9a" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 6, + "last_byte_ms": 6, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_treevite_auth_required", + "message": "polis_err_treevite_auth_required", + "status": 401 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 6.354253000001336, + "ttlbMs": 6.478127999998833 + }, + "effects": { + "db": { + "pg:oidc_user_mappings": { + "added": [ + { + "created": 1700000000000, + "oidc_sub": "23229ecdc3ed7bc3dff205e4", + "uid": 10 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": "test.user.2@polis.test", + "hname": "Test User 2", + "is_owner": true, + "oinvite": null, + "site_id": "$site_id:7", + "site_owner": true, + "tut": 0, + "uid": 10, + "username": "test.user.2", + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/foreign-token", + "case": "foreign-token", + "auth": "foreign", + "seed": "235f92570efc", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:foreign" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment foreign-token" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:foreign" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGZvcmVpZ24tdG9rZW4ifQ==", + "byte_length": 76, + "sha256": "85c3a25a4dd353242a046a2e32db0999306c32605e72210251d0b6be93b12a4c" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "705", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"2c1-zEFPl1UnSToALnr+tc+M1A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:15 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 27, + "bytes": { + "base64": "eyJ0aWQiOjYzLCJjdXJyZW50UGlkIjo4LCJhdXRoIjp7InRva2VuIjoiJGp3dDozNmFiN2I5ZmEwZjQyYjUyOGQ4Y2E2Yjk4YTA2Y2VlMWM2MjgyNjRhMWU3Y2VkM2JkNjkxNzUzMDQ0ZjYwYmIxIiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImV4cGlyZXNfaW4iOjMxNTM2MDAwfX0=", + "byte_length": 158, + "sha256": "9fc866845e6aa3d3c718697d4a422aff12776eec60972c51ede6af93ad451116" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 27, + "last_byte_ms": 27, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "705", + "etag": "W/\"2c1-zEFPl1UnSToALnr+tc+M1A\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 8, + "sub": "anon:11", + "uid": 11 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "currentPid": 8, + "tid": 63 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 27.071979000000283, + "ttlbMs": 27.230522000005294 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 8, + "quote_src_url": null, + "tid": 63, + "tweet_id": null, + "txt": "Generated comment foreign-token", + "uid": 11, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 9, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 8, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 8, + "subscribed": 0, + "uid": 11, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 11, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:8", + "site_owner": true, + "tut": 0, + "uid": 11, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 8, + "sub": "anon:11", + "uid": 11 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 8, + "subscribed": 0, + "uid": 11, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment foreign-token", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/auth-expired", + "case": "auth-expired", + "auth": "expired", + "seed": "2ea050698715", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:expired" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment auth-expired" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:expired" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGF1dGgtZXhwaXJlZCJ9", + "byte_length": 75, + "sha256": "377a8987417b16bbb74efd9f3966b4a8eaed2a2e89bef539e5754bd84bfd59f6" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "64", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"40-AZECOzOIgn6Jhruy53oRuA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:15 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 2, + "bytes": { + "base64": "eyJlcnJvciI6IkludmFsaWQgYXV0aGVudGljYXRpb24gdG9rZW4iLCJkZXRhaWxzIjoiand0IGV4cGlyZWQifQ==", + "byte_length": 64, + "sha256": "455bdc63aad37bd64cad42fc6de0dd5a76209a92c23d71b764f6b59f24744b02" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 2, + "last_byte_ms": 2, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "jwt expired", + "error": "Invalid authentication token" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 1.809345999994548, + "ttlbMs": 1.9861799999998766 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/auth-bad", + "case": "auth-bad", + "auth": "bad", + "seed": "c77b577fab06", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:bad" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment auth-bad" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:bad" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGF1dGgtYmFkIn0=", + "byte_length": 71, + "sha256": "752a99013769c47a976bdafca358d6db42d796b5618f8b172535b21632583b3e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "88", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"58-HG9z2b+w5WYrQmAW1A3b9g\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:16 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 1, + "bytes": { + "base64": "eyJlcnJvciI6IkludmFsaWQgdG9rZW4gZm9ybWF0IiwiZGV0YWlscyI6IlRva2VuIGRvZXMgbm90IG1hdGNoIGFueSBzdXBwb3J0ZWQgSldUIHR5cGUifQ==", + "byte_length": 88, + "sha256": "8a63420d75a3d9036037c407d494e254cc7fd443893999d54d35c56b4702d105" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 1, + "last_byte_ms": 1, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "Token does not match any supported JWT type", + "error": "Invalid token format" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 0.8380479999977979, + "ttlbMs": 0.9377989999993588 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/auth-signature", + "case": "auth-signature", + "auth": "signature", + "seed": "09c500657eb4", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:signature" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment auth-signature" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:signature" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGF1dGgtc2lnbmF0dXJlIn0=", + "byte_length": 77, + "sha256": "46faf2d0a99f7bc4a2d5146c91d8166d6cb39c2aacb9bf78bd1490116d308f35" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 401, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "70", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"46-hTUIfGJfxLTn7SPS4Ow0pA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:16 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 2, + "bytes": { + "base64": "eyJlcnJvciI6IkludmFsaWQgYXV0aGVudGljYXRpb24gdG9rZW4iLCJkZXRhaWxzIjoiaW52YWxpZCBzaWduYXR1cmUifQ==", + "byte_length": 70, + "sha256": "df42f92d3421b3031dde54aa025f2205befc9d644ce8f63829f15cf01ec52a34" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 2, + "last_byte_ms": 2, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "details": "invalid signature", + "error": "Invalid authentication token" + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 401, + "ttfbMs": 2.3206409999984317, + "ttlbMs": 2.4381419999990612 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-empty", + "case": "text-empty", + "auth": "unauthenticated", + "seed": "522eed5e02c3", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IiJ9", + "byte_length": 45, + "sha256": "d9990a152f497ff6e1a725c52d4cb8666081f4fed97af6c48b860d59986b2a3f" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "772", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"304-KD/d1Abb+xNuSHNZV47pjQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:17 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wYXJhbV9taXNzaW5nX3R4dCIsIm1lc3NhZ2UiOiJwb2xpc19lcnJfcGFyYW1fbWlzc2luZ190eHQiLCJzdGF0dXMiOjQwMCwiYXV0aCI6eyJ0b2tlbiI6IiRqd3Q6OGI3ZjUxNjQzNDg0NmY1NzFkZjVlY2VmOGIzYjNlYWIxMGFkNzZmNTFjMWExNjc0M2EyMmE4NTY4M2Y3YTZlMiIsInRva2VuX3R5cGUiOiJCZWFyZXIiLCJleHBpcmVzX2luIjozMTUzNjAwMH19", + "byte_length": 225, + "sha256": "57c837a8779c7c13b3f61b0e8e9001a4a2662aa07064384f2b75f52e635020ac" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "772", + "etag": "W/\"304-KD/d1Abb+xNuSHNZV47pjQ\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 9, + "sub": "anon:12", + "uid": 12 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "error": "polis_err_param_missing_txt", + "message": "polis_err_param_missing_txt", + "status": 400 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 400, + "ttfbMs": 7.259257999998226, + "ttlbMs": 7.4118429999944055 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 10, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 9, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 9, + "subscribed": 0, + "uid": 12, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 12, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:9", + "site_owner": true, + "tut": 0, + "uid": 12, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 9, + "sub": "anon:12", + "uid": 12 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 9, + "subscribed": 0, + "uid": 12, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-spaces", + "case": "text-spaces", + "auth": "unauthenticated", + "seed": "4084a167d524", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": " " + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IiAgICJ9", + "byte_length": 48, + "sha256": "a72594673483d8f23f5f6e0ee1d1ceba42ced27363411543aa18bb4ec01889b9" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "774", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"306-bZegkA8+QbeqN54hapiCgg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:17 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wYXJhbV9taXNzaW5nX3R4dCIsIm1lc3NhZ2UiOiJwb2xpc19lcnJfcGFyYW1fbWlzc2luZ190eHQiLCJzdGF0dXMiOjQwMCwiYXV0aCI6eyJ0b2tlbiI6IiRqd3Q6ODA5Y2RmY2U4MmI5OTEwZTUyZjUyMmMzYjg4MGQwZDIwMTkzOGYzMzAwOTY2ZmI3NmVhZTM1ZjBjNTQ4ZWQxNyIsInRva2VuX3R5cGUiOiJCZWFyZXIiLCJleHBpcmVzX2luIjozMTUzNjAwMH19", + "byte_length": 225, + "sha256": "daa739db98e54359a9e03191df0d467ee669cfd2234417b754e1b47a2175530d" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "774", + "etag": "W/\"306-bZegkA8+QbeqN54hapiCgg\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 10, + "sub": "anon:13", + "uid": 13 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "error": "polis_err_param_missing_txt", + "message": "polis_err_param_missing_txt", + "status": 400 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 400, + "ttfbMs": 7.757096000001184, + "ttlbMs": 7.89051300000574 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 11, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 10, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 10, + "subscribed": 0, + "uid": 13, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 13, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:10", + "site_owner": true, + "tut": 0, + "uid": 13, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 10, + "sub": "anon:13", + "uid": 13 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 10, + "subscribed": 0, + "uid": 13, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-null", + "case": "text-null", + "auth": "unauthenticated", + "seed": "8402a63b62b3", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": null + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6bnVsbH0=", + "byte_length": 47, + "sha256": "1233ce6c560aa89c846177b0b3c10623ce43e2e1c25b12fcd2c089224b8b19f6" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:18 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 15, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 15, + "last_byte_ms": 15, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 14.874770000002172, + "ttlbMs": 15.02697900000203 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 12, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 11, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 11, + "subscribed": 0, + "uid": 14, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 14, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:11", + "site_owner": true, + "tut": 0, + "uid": 14, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 1, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 11, + "subscribed": 0, + "uid": 14, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-number", + "case": "text-number", + "auth": "unauthenticated", + "seed": "8984b5da7300", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": 7 + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6N30=", + "byte_length": 44, + "sha256": "c24a08f2ddbc28868c95443c9d41713d8b13c9950c94af207e5f576838b35cb2" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:18 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 15, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 15, + "last_byte_ms": 15, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 14.892477999994298, + "ttlbMs": 15.027562999996007 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 13, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 12, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 12, + "subscribed": 0, + "uid": 15, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 15, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:12", + "site_owner": true, + "tut": 0, + "uid": 15, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 1, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 12, + "subscribed": 0, + "uid": 15, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-boolean", + "case": "text-boolean", + "auth": "unauthenticated", + "seed": "5d4bedfd80f3", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": false + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6ZmFsc2V9", + "byte_length": 48, + "sha256": "2017a5ca85bfd76180c27a2a95c8ac7e94d1a2eaf979bfbd76702c87e7d92e5c" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:18 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 7.522551999994903, + "ttlbMs": 7.666427999996813 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 14, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 13, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 13, + "subscribed": 0, + "uid": 16, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 16, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:13", + "site_owner": true, + "tut": 0, + "uid": 16, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 1, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 13, + "subscribed": 0, + "uid": 16, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-array", + "case": "text-array", + "auth": "unauthenticated", + "seed": "9de19ffbb568", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": [] + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6W119", + "byte_length": 45, + "sha256": "05cd90722e1b7753eea81277cc96655fa8a67778476b0859b0c83a5b1c885a84" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:19 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 13, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 13, + "last_byte_ms": 13, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 13.293175999999221, + "ttlbMs": 13.453676999997697 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 15, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 14, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 14, + "subscribed": 0, + "uid": 17, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 17, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:14", + "site_owner": true, + "tut": 0, + "uid": 17, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 1, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 14, + "subscribed": 0, + "uid": 17, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-object", + "case": "text-object", + "auth": "unauthenticated", + "seed": "4e944320203c", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": {} + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6e319", + "byte_length": 45, + "sha256": "9c5eeb384505f45a2505140b52653f694863fc2c6fc26abedcb1dcd1427fc707" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:19 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 14, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 14, + "last_byte_ms": 14, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 13.55959399999847, + "ttlbMs": 13.738470000003872 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 16, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 15, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 15, + "subscribed": 0, + "uid": 18, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 18, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:15", + "site_owner": true, + "tut": 0, + "uid": 18, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 1, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 15, + "subscribed": 0, + "uid": 18, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-too-long", + "case": "text-too-long", + "auth": "unauthenticated", + "seed": "1d97e10d94bf", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6Inh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4In0=", + "byte_length": 1043, + "sha256": "21a6dff3f7e2b17e752ebbc26c8eef25a9f87adb259e9163e5a07fd2a134a0e4" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:20 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 10.224404000000504, + "ttlbMs": 10.38082199999917 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 17, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 16, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 16, + "subscribed": 0, + "uid": 19, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 19, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:16", + "site_owner": true, + "tut": 0, + "uid": 19, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 1, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 16, + "subscribed": 0, + "uid": 19, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-utf16-too-long", + "case": "text-utf16-too-long", + "auth": "unauthenticated", + "seed": "da536b16bdd3", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 32, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IvCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIAifQ==", + "byte_length": 2041, + "sha256": "f362953aab074df9eb84b475b68b1e0857e6e809791249f1054b554e1e8f51dc" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:20 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 14, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 14, + "last_byte_ms": 14, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 13.531092999997782, + "ttlbMs": 13.675218999997014 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 18, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 17, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 17, + "subscribed": 0, + "uid": 20, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 20, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:17", + "site_owner": true, + "tut": 0, + "uid": 20, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 1, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 17, + "subscribed": 0, + "uid": 20, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/text-max-length", + "case": "text-max-length", + "auth": "participant", + "seed": "3e2044d1b68d", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 33, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6Inh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHgifQ==", + "byte_length": 1042, + "sha256": "4a42d5f0bfe4aa417d7699a311f7f0c659ead41dbf9a505b099ac2387384a522" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-5x4/H9YOWJodmz+nQfsjXQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:21 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJ0aWQiOjY0LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "0fd89584e1321ccb836b61ca05c8c67bdb4db82685708a6866e6c4b0919482b7" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 6, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 64 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 5.455078999999387, + "ttlbMs": 5.589247000003525 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 64, + "tweet_id": null, + "txt": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/text-utf16-boundary", + "case": "text-utf16-boundary", + "auth": "participant", + "seed": "4aebedb3fafd", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00x" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 34, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IvCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgHgifQ==", + "byte_length": 2038, + "sha256": "39556c03713906c076b561e3eba5a361405dc811de1a95cf24b2fa5fc6c4e86e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-L1M/tmK1JdKIf9NCEFk5pA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:21 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjY1LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "ea4b712a363c903171d6244783fcf08bdee4854fc725f60fd457cc1be6f40b1f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 65 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.74460199999885, + "ttlbMs": 8.911228000004485 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 65, + "tweet_id": null, + "txt": "\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00x", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00\ud83d\ude00x", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/text-tab", + "case": "text-tab", + "auth": "participant", + "seed": "7428943ff868", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "\t" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 35, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6Ilx0In0=", + "byte_length": 47, + "sha256": "2a9bf241487a6b5071324ab41847a4c89855bbc9802747f03d2c1b3eba738be6" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-sJoKl83fOo8E4zwDYblrzA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:21 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJ0aWQiOjY2LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "f91aad115a01a6ec2c53a8e341f8ca3f485f19afd65edcfbf1f028627df9da8a" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 66 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 5.234452999997302, + "ttlbMs": 5.363287000000128 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 66, + "tweet_id": null, + "txt": "\t", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "\t", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/text-trim", + "case": "text-trim", + "auth": "participant", + "seed": "7f0c6acba634", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": " Generated trimmed text " + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 36, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IiAgR2VuZXJhdGVkIHRyaW1tZWQgdGV4dCAgIn0=", + "byte_length": 71, + "sha256": "cd5b32fe7f63a04f39d52a170d5d467e832a583844cbcbb9c53a6d0024d00956" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-Z0fSsOi9+ORiITothoqKIA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:22 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjY3LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "988eeba83a31c641e844b2788e6481795da057471d01342abafadc454502d86b" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 9, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 67 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 8.854643999999098, + "ttlbMs": 9.122104000001855 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 67, + "tweet_id": null, + "txt": "Generated trimmed text", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated trimmed text", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/text-trim-duplicate", + "case": "text-trim-duplicate", + "auth": "participant", + "seed": "50b30975b68f", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated trimmed text" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 36, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCB0cmltbWVkIHRleHQifQ==", + "byte_length": 67, + "sha256": "aaec0d430b2f4b4f25d43cd4c25dc043685c0bc90b030d1cb11d35773a7a505d" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 409, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-zCIjZ1CCaueCny6M7+PsGg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:22 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwibWVzc2FnZSI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwic3RhdHVzIjo0MDl9", + "byte_length": 102, + "sha256": "0e516e9327d3ae940fe084092476cc6f2c8a23ca11c73e932e2b7c9f5ab635cf" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_post_comment_duplicate", + "message": "polis_err_post_comment_duplicate", + "status": 409 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 409, + "ttfbMs": 2.9481869999945047, + "ttlbMs": 3.0650209999948856 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/duplicate-before-closed", + "case": "duplicate-before-closed", + "auth": "participant", + "seed": "ab1287451ac2", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated statement A" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 36, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBzdGF0ZW1lbnQgQSJ9", + "byte_length": 66, + "sha256": "38cff83368ffb12f4039126206c9c4ec753eb73378ec623331df2331b678ac5f" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 409, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-zCIjZ1CCaueCny6M7+PsGg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:23 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwibWVzc2FnZSI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwic3RhdHVzIjo0MDl9", + "byte_length": 102, + "sha256": "0e516e9327d3ae940fe084092476cc6f2c8a23ca11c73e932e2b7c9f5ab635cf" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_post_comment_duplicate", + "message": "polis_err_post_comment_duplicate", + "status": 409 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 409, + "ttfbMs": 2.5552669999960926, + "ttlbMs": 2.67439299999387 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/duplicate-exact", + "case": "duplicate-exact", + "auth": "participant", + "seed": "6fe90516466d", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated statement A" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 36, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBzdGF0ZW1lbnQgQSJ9", + "byte_length": 66, + "sha256": "38cff83368ffb12f4039126206c9c4ec753eb73378ec623331df2331b678ac5f" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 409, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-zCIjZ1CCaueCny6M7+PsGg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:23 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwibWVzc2FnZSI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwic3RhdHVzIjo0MDl9", + "byte_length": 102, + "sha256": "0e516e9327d3ae940fe084092476cc6f2c8a23ca11c73e932e2b7c9f5ab635cf" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_post_comment_duplicate", + "message": "polis_err_post_comment_duplicate", + "status": 409 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 409, + "ttfbMs": 2.6813099999999395, + "ttlbMs": 2.8142269999952987 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/duplicate-case-sensitive", + "case": "duplicate-case-sensitive", + "auth": "participant", + "seed": "725f54a6cd99", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "generated statement A" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 37, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6ImdlbmVyYXRlZCBzdGF0ZW1lbnQgQSJ9", + "byte_length": 66, + "sha256": "3bde75c0fdcb228e190dddf2a85cf6e2bf92754a0b9059cefa8c40b1d94aaa1a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-F4iWfF2ZbjiO/ZQgZffdIQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:24 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJ0aWQiOjY4LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "61da1d6501f293aa5cf56ffadd83f87e4fcb9501e522e852ef7891ba325b5304" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 68 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 4.836450000002515, + "ttlbMs": 4.950909000006504 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 68, + "tweet_id": null, + "txt": "generated statement A", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "generated statement A", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/vote-null", + "case": "vote-null", + "auth": "participant", + "seed": "54237341a9ef", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-null", + "vote": null + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 38, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtbnVsbCIsInZvdGUiOm51bGx9", + "byte_length": 84, + "sha256": "f42f14e180a781d4b80feac8013596fccae1ae209fa256f22581fa70ec7ccd44" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-Uw+UQNEi0KRAkkG8ixvGzg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:24 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 13, + "bytes": { + "base64": "eyJ0aWQiOjY5LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "954415a7d2dc17c0d215e25b672c31d42033e7ab8869f10855d6b2e7dd0baa47" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 13, + "last_byte_ms": 13, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 69 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 12.683921000003465, + "ttlbMs": 12.831922000004852 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 69, + "tweet_id": null, + "txt": "Generated comment vote-null", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment vote-null", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/vote-prefix", + "case": "vote-prefix", + "auth": "participant", + "seed": "4e51ea0a39e9", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-prefix", + "vote": "0suffix" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 39, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtcHJlZml4Iiwidm90ZSI6IjBzdWZmaXgifQ==", + "byte_length": 91, + "sha256": "e62870fe9301f2e178b5acdc7f28bd84ca8e055356405e22d17b4d3e38d6b25e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-bBecdhFfmp2k68xL0yi3UA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:25 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 12, + "bytes": { + "base64": "eyJ0aWQiOjcwLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "c6e101d298007e94c5c1e268bbbf2364d93bd03704879e631db3056ae468128f" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 12, + "last_byte_ms": 12, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 70 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 11.530786999996053, + "ttlbMs": 11.669912999997905 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 70, + "tweet_id": null, + "txt": "Generated comment vote-prefix", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 70, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 70, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment vote-prefix", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/vote-fraction-string", + "case": "vote-fraction-string", + "auth": "participant", + "seed": "d78e28e2e2a8", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-fraction-string", + "vote": "0.9" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtZnJhY3Rpb24tc3RyaW5nIiwidm90ZSI6IjAuOSJ9", + "byte_length": 96, + "sha256": "bb377ec056fe78998ad9ba04b5b96e9ea9f4ec15f95c4943f11051724bc2f878" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-zmSAcrQFkerLnguBEfEIoQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:25 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjcxLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "c9cb388e443151d3cff593860c5d4f5a1d73696dc301e45e5a731e0f0b4e4dc3" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 8, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 71 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.946345999996993, + "ttlbMs": 8.221305999999458 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 71, + "tweet_id": null, + "txt": "Generated comment vote-fraction-string", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes": { + "added": [ + { + "created": 1700000000000, + "high_priority": false, + "pid": 2, + "tid": 71, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:votes_latest_unique": { + "added": [ + { + "modified": 1700000000000, + "pid": 2, + "tid": 71, + "vote": 0, + "weight_x_32767": 0, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 1, + "storedMeanings": [ + "pass" + ], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment vote-fraction-string", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/vote-invalid-2", + "case": "vote-invalid-2", + "auth": "participant", + "seed": "598a67306891", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-invalid-2", + "vote": 2 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtaW52YWxpZC0yIiwidm90ZSI6Mn0=", + "byte_length": 86, + "sha256": "2351920ad028de716dfe0cb34f3f0e14cdacd3f27d744eeeb4a9cbece0c05922" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:25 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 3.151188000003458, + "ttlbMs": 3.2902720000056433 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/vote-invalid-0.5", + "case": "vote-invalid-0.5", + "auth": "participant", + "seed": "d11db7721b59", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-invalid-0.5", + "vote": 0.5 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtaW52YWxpZC0wLjUiLCJ2b3RlIjowLjV9", + "byte_length": 90, + "sha256": "b018ab47e22022df10fa6656af2db3fcff82f069a620f1efc38e83d31eb61bc4" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:26 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 4, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 4, + "last_byte_ms": 4, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 3.55973300000187, + "ttlbMs": 3.9577780000036 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/vote-invalid-true", + "case": "vote-invalid-true", + "auth": "participant", + "seed": "cf849fc8c07f", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-invalid-true", + "vote": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtaW52YWxpZC10cnVlIiwidm90ZSI6dHJ1ZX0=", + "byte_length": 92, + "sha256": "fe7a78918bc4eacc944753c9d8628b1ef86f01b5e4496754eaada64ae10912a3" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:26 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 3.210564000000886, + "ttlbMs": 3.322439999996277 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/vote-invalid-\"bad\"", + "case": "vote-invalid-\"bad\"", + "auth": "participant", + "seed": "6ba8dde4568e", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-invalid-\"bad\"", + "vote": "bad" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtaW52YWxpZC1cImJhZFwiIiwidm90ZSI6ImJhZCJ9", + "byte_length": 96, + "sha256": "4ae0953635df79ec50b2ec742a308d92fb6d64f105b19dbca14706bb33032912" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:27 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 3, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 3.1578129999979865, + "ttlbMs": 3.293980999995256 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/vote-invalid-[]", + "case": "vote-invalid-[]", + "auth": "participant", + "seed": "f7c8ccbcc4cd", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-invalid-[]", + "vote": [] + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtaW52YWxpZC1bXSIsInZvdGUiOltdfQ==", + "byte_length": 88, + "sha256": "18220753bb4efeff56ca4cd999ed3a84adefd58d1f05c24745bb19073a1d9806" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:27 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 4, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 3.2951889999967534, + "ttlbMs": 3.6460249999945518 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/vote-invalid-{}", + "case": "vote-invalid-{}", + "auth": "participant", + "seed": "734670aeab22", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment vote-invalid-{}", + "vote": {} + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHZvdGUtaW52YWxpZC17fSIsInZvdGUiOnt9fQ==", + "byte_length": 88, + "sha256": "86b6e2156f99ddab9b74f8fe3861906c46ea4ecafea53aeadba2dde086de1b14" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:27 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 2, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 2, + "last_byte_ms": 2, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 1.9339709999985644, + "ttlbMs": 2.08538899999985 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/seed-number", + "case": "seed-number", + "auth": "owner", + "seed": "bf8eeac0e616", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment seed-number", + "is_seed": 2 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNlZWQtbnVtYmVyIiwiaXNfc2VlZCI6Mn0=", + "byte_length": 86, + "sha256": "684081a6246402216c3d8b46687ed5df86b13e591d6ad161049857ff311761a6" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-xzwFjGixdiccnHbuQZcz+Q\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:28 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjcyLCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "23e0d72e16bebb6914d435ee3f95cdb15675a216da6ba4fe1daed2452ff4a26b" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 72 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.27192500000092, + "ttlbMs": 7.41084299999784 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": true, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 72, + "tweet_id": null, + "txt": "Generated comment seed-number", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment seed-number", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/seed-off", + "case": "seed-off", + "auth": "owner", + "seed": "348088dfdd4a", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment seed-off", + "is_seed": "OFF" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNlZWQtb2ZmIiwiaXNfc2VlZCI6Ik9GRiJ9", + "byte_length": 87, + "sha256": "9bae904d03eb87900e43aa7a21f74b8acdb87a61bc104f7933f06f41e81107df" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-paU8oHk4PkwCb8hZQxfYlA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:28 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 8, + "bytes": { + "base64": "eyJ0aWQiOjczLCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "17ce852b5fa8611c43f3638b34773741ad01e2dfb9af12b5fc046a78b6fdc3d1" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 8, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 73 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 7.4586769999950775, + "ttlbMs": 7.595760999996855 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 73, + "tweet_id": null, + "txt": "Generated comment seed-off", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment seed-off", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/seed-null", + "case": "seed-null", + "auth": "owner", + "seed": "f2b656d01bcd", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:owner" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment seed-null", + "is_seed": null + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "8f4ca43a4bfe0fa4cbfae8ea" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:owner" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNlZWQtbnVsbCIsImlzX3NlZWQiOm51bGx9", + "byte_length": 87, + "sha256": "5ec8f5581e46583704bf89027293a99f3625b6026511597dcdd6f809cd08c4e0" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-14SPsbHdOxkmuPj5J5r4vQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:29 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 14, + "bytes": { + "base64": "eyJ0aWQiOjc0LCJjdXJyZW50UGlkIjowfQ==", + "byte_length": 25, + "sha256": "16e1d93367270ee066d9fc778f6c7c450c10645d86440da24865a90628196e97" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 14, + "last_byte_ms": 14, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 0, + "tid": 74 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 14.070347000000766, + "ttlbMs": 14.212931000001845 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 74, + "tweet_id": null, + "txt": "Generated comment seed-null", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment seed-null", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/seed-invalid", + "case": "seed-invalid", + "auth": "participant", + "seed": "26170c9d0e18", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment seed-invalid", + "is_seed": " true " + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 40, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNlZWQtaW52YWxpZCIsImlzX3NlZWQiOiIgdHJ1ZSAifQ==", + "byte_length": 94, + "sha256": "95a9fa2faa0824ad0cfd4499a0f7a33cb19048ad4ce8db6c8f7ff7ffdbc87c2b" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:29 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 3, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 3, + "last_byte_ms": 4, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 3.425273000000743, + "ttlbMs": 3.5714829999997164 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/ignored-fields", + "case": "ignored-fields", + "auth": "participant", + "seed": "cf728b8fa42a", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment ignored-fields", + "pid": 999, + "uid": 999, + "tid": 999, + "lang": "fr", + "weight": 123, + "nextComment": true + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGlnbm9yZWQtZmllbGRzIiwicGlkIjo5OTksInVpZCI6OTk5LCJ0aWQiOjk5OSwibGFuZyI6ImZyIiwid2VpZ2h0IjoxMjMsIm5leHRDb21tZW50Ijp0cnVlfQ==", + "byte_length": 151, + "sha256": "87d0f085ee57f30d1e5c6bcb6f620a3253e40e69641a53a488e39455ccb35c5e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-RpZhHplgCSqUyMCKq2fZkw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:30 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjc1LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "4dbad68574cc171fb5fae99ae5682decff041ea99b620a36f554b2965c313791" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 75 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.415905000001658, + "ttlbMs": 10.558489000002737 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 75, + "tweet_id": null, + "txt": "Generated comment ignored-fields", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment ignored-fields", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/missing-conversation", + "case": "missing-conversation", + "auth": "unauthenticated", + "seed": "f83436113b52", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": null, + "txt": "Generated comment missing-conversation" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOm51bGwsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG1pc3NpbmctY29udmVyc2F0aW9uIn0=", + "byte_length": 71, + "sha256": "b74b571f178a74274e3761d74dc84e4b7be3e99878497813463f05ddc5483158" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:30 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 2, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 2, + "last_byte_ms": 2, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 1.65251200000057, + "ttlbMs": 1.7689709999976913 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/unknown-conversation", + "case": "unknown-conversation", + "auth": "participant", + "seed": "83d3b6ed1b07", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2generatedmissing", + "txt": "Generated comment unknown-conversation" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIyZ2VuZXJhdGVkbWlzc2luZyIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHVua25vd24tY29udmVyc2F0aW9uIn0=", + "byte_length": 86, + "sha256": "d46a4adb43b0fa8e5b25088d3d4b7a90a00c43fe137c3c912c2210ec310ebae2" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:30 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 5, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 5.197035999997752, + "ttlbMs": 5.335370000000694 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/invalid-xid", + "case": "invalid-xid", + "auth": "unauthenticated", + "seed": "54513b1c9cd8", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment invalid-xid", + "xid": 3 + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGludmFsaWQteGlkIiwieGlkIjozfQ==", + "byte_length": 82, + "sha256": "11107a4ab805a13738890b1ae77b68833454b8863602f8079d101d71c447bb48" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:31 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 2, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 2, + "last_byte_ms": 2, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 1.5630519999976968, + "ttlbMs": 1.6639280000017607 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/sql-insert", + "case": "sql-insert", + "auth": "unauthenticated", + "seed": "84cea367f542", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment sql-insert" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNxbC1pbnNlcnQifQ==", + "byte_length": 73, + "sha256": "232571b99f6a2ffc9da99ba9b20e951b12b8b1978ffab7b9bf4fad43d327ec35" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 500, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "764", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"2fc-BdJTovMUr+z9nHWHE+yXbQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:31 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 17, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnQiLCJtZXNzYWdlIjoicG9saXNfZXJyX3Bvc3RfY29tbWVudCIsInN0YXR1cyI6NTAwLCJhdXRoIjp7InRva2VuIjoiJGp3dDo5ZDU5NWQ1ZDZmZTQzZTZmNDI2YzMwMmVlYjk4NTUxYzk5NDZmMWMxZWJiMmViNzNiZTkxYzc3MGVkN2ViM2EzIiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImV4cGlyZXNfaW4iOjMxNTM2MDAwfX0=", + "byte_length": 215, + "sha256": "b4c40def70f83f4fbfa12cb08d7099ac6ad1bed97abfe154e89372cc242fc304" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 17, + "last_byte_ms": 17, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "764", + "etag": "W/\"2fc-BdJTovMUr+z9nHWHE+yXbQ\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 18, + "sub": "anon:21", + "uid": 21 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "error": "polis_err_post_comment", + "message": "polis_err_post_comment", + "status": 500 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 500, + "ttfbMs": 16.991200000004028, + "ttlbMs": 17.143825999999535 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 19, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 18, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 18, + "subscribed": 0, + "uid": 21, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 21, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:18", + "site_owner": true, + "tut": 0, + "uid": 21, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 18, + "sub": "anon:21", + "uid": 21 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 18, + "subscribed": 0, + "uid": 21, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated comment sql-insert", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/sql-participant", + "case": "sql-participant", + "auth": "unauthenticated", + "seed": "5ec7d250cba8", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment sql-participant" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNxbC1wYXJ0aWNpcGFudCJ9", + "byte_length": 78, + "sha256": "e89acce25ee2bb01c6d8b2064111c7de30f853dd9d1316b72b19b1df02ee8a74" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 500, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "818", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"332-PZcr+zSNsygQA0ALq6HR7w\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:32 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 26, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfcGFydGljaXBhbnRfcmFjZV9jb25kaXRpb24iLCJtZXNzYWdlIjoicG9saXNfZXJyX3Bvc3RfY29tbWVudF9wYXJ0aWNpcGFudF9yYWNlX2NvbmRpdGlvbiIsInN0YXR1cyI6NTAwLCJhdXRoIjp7InRva2VuIjoiJGp3dDpkNjFiNmNhMGRlODJkNDRhOWY5ZDQ2ODEwM2FhNTM3NjAzODYxYmI0M2MxZjliZGMxYWI0ZDM0MTdlOWVhNzAyIiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImV4cGlyZXNfaW4iOjMxNTM2MDAwfX0=", + "byte_length": 269, + "sha256": "75fee67b42e723fe9ad029cf5d530b43c8befed0bddd084293bb18728603c304" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 26, + "last_byte_ms": 26, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "818", + "etag": "W/\"332-PZcr+zSNsygQA0ALq6HR7w\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 19, + "sub": "anon:22", + "uid": 22 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "error": "polis_err_post_comment_participant_race_condition", + "message": "polis_err_post_comment_participant_race_condition", + "status": 500 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 500, + "ttfbMs": 25.796176999996533, + "ttlbMs": 25.971761000000697 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 20, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 19, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 19, + "subscribed": 0, + "uid": 22, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 22, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:19", + "site_owner": true, + "tut": 0, + "uid": 22, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 19, + "sub": "anon:22", + "uid": 22 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 19, + "subscribed": 0, + "uid": 22, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated comment sql-participant", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/sql-foreign", + "case": "sql-foreign", + "auth": "unauthenticated", + "seed": "f613f78b71c1", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment sql-foreign" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNxbC1mb3JlaWduIn0=", + "byte_length": 74, + "sha256": "156e456aef34b55a1fb68e4aeb99da53286561564cbaf6346199cabf635d4119" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 500, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "806", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"326-v1rgrzIgUMFoZI+0G2Hu3A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:32 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 28, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfY29uc3RyYWludF92aW9sYXRpb24iLCJtZXNzYWdlIjoicG9saXNfZXJyX3Bvc3RfY29tbWVudF9jb25zdHJhaW50X3Zpb2xhdGlvbiIsInN0YXR1cyI6NTAwLCJhdXRoIjp7InRva2VuIjoiJGp3dDpmNmUwMzg1MjY5MTg1MDNjYTQyZjllMDE3NDEyYmYzOTFjZWNiN2U0MTZiOTBiNDg0ZGYzYzliM2JjMTAxNjY4IiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImV4cGlyZXNfaW4iOjMxNTM2MDAwfX0=", + "byte_length": 257, + "sha256": "abbea1876e774b97e7b728f488a3165b3c944204d395f203be610fa66b90b876" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 28, + "last_byte_ms": 28, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "806", + "etag": "W/\"326-v1rgrzIgUMFoZI+0G2Hu3A\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 20, + "sub": "anon:23", + "uid": 23 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "error": "polis_err_post_comment_constraint_violation", + "message": "polis_err_post_comment_constraint_violation", + "status": 500 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 500, + "ttfbMs": 27.68102400000498, + "ttlbMs": 27.824608000002627 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 21, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 20, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 20, + "subscribed": 0, + "uid": 23, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 23, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:20", + "site_owner": true, + "tut": 0, + "uid": 23, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 20, + "sub": "anon:23", + "uid": 23 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 20, + "subscribed": 0, + "uid": 23, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated comment sql-foreign", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/sql-duplicate", + "case": "sql-duplicate", + "auth": "unauthenticated", + "seed": "a0a0856a8f22", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment sql-duplicate" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNxbC1kdXBsaWNhdGUifQ==", + "byte_length": 76, + "sha256": "37d3f61648d4642972839fbf6163266d51902187378025a0aa51bb06fc35be49" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 409, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "784", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"310-3ZoeVwzcoDYSyqe5WYgeAg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:33 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 27, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwibWVzc2FnZSI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwic3RhdHVzIjo0MDksImF1dGgiOnsidG9rZW4iOiIkand0OjEyYWU2OGNiY2MzNjczODQxYzJiZjgzMDkwYmY5NWM2ODMyMTQ3NzQwNGZmZmIzODhlYzg2MWUwMzJhNzgzMjgiLCJ0b2tlbl90eXBlIjoiQmVhcmVyIiwiZXhwaXJlc19pbiI6MzE1MzYwMDB9fQ==", + "byte_length": 235, + "sha256": "721d55e9b1e438ef7bede536a368904d4f60ba464ec6cc4f927d14a209e12b10" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 27, + "last_byte_ms": 27, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "784", + "etag": "W/\"310-3ZoeVwzcoDYSyqe5WYgeAg\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 21, + "sub": "anon:24", + "uid": 24 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "error": "polis_err_post_comment_duplicate", + "message": "polis_err_post_comment_duplicate", + "status": 409 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 409, + "ttfbMs": 27.138435999993817, + "ttlbMs": 27.294894999999087 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 22, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 21, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 21, + "subscribed": 0, + "uid": 24, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 24, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:21", + "site_owner": true, + "tut": 0, + "uid": 24, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 21, + "sub": "anon:24", + "uid": 24 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 21, + "subscribed": 0, + "uid": 24, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated comment sql-duplicate", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/sql-allocator", + "case": "sql-allocator", + "auth": "unauthenticated", + "seed": "e0f3dbee9308", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment sql-allocator" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 41, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNxbC1hbGxvY2F0b3IifQ==", + "byte_length": 76, + "sha256": "013ee29612c754a0656024a4d125fcc503f1998dda0a78587d7d7b9d611f33e6" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 500, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "764", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"2fc-CTztLFmnNbfwdpIrUBuY+Q\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:34 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 28, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnQiLCJtZXNzYWdlIjoicG9saXNfZXJyX3Bvc3RfY29tbWVudCIsInN0YXR1cyI6NTAwLCJhdXRoIjp7InRva2VuIjoiJGp3dDowMjZhNTQwNDllYzg2N2Q5MTZjMTNiZWU0ZjIxMzg1MGI0ODdkZTAxZjE2MjY4YjA2MzlhY2JjMDViZjZlNTU2IiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImV4cGlyZXNfaW4iOjMxNTM2MDAwfX0=", + "byte_length": 215, + "sha256": "5a442ef52ca40590052524d2f66726021d2ea01fe046e3af7215963322a12251" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 28, + "last_byte_ms": 28, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "credentialWireValidation": { + "kind": "verified-jwt-values/1", + "contentLength": "764", + "etag": "W/\"2fc-CTztLFmnNbfwdpIrUBuY+Q\"", + "count": 1 + }, + "response": { + "body": { + "auth": { + "expires_in": 31536000, + "token": { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 22, + "sub": "anon:25", + "uid": 25 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + }, + "token_type": "Bearer" + }, + "error": "polis_err_post_comment", + "message": "polis_err_post_comment", + "status": 500 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 500, + "ttfbMs": 28.2612350000054, + "ttlbMs": 28.407028000001446 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 23, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 22, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 22, + "subscribed": 0, + "uid": 25, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 25, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:22", + "site_owner": true, + "tut": 0, + "uid": 25, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 1, + "jwtMinted": 1, + "jwts": [ + { + "$jwt": { + "anonymous_participant": true, + "aud": "participants", + "conversation_id": "2p027generated", + "iss": "https://pol.is/", + "pid": 22, + "sub": "anon:25", + "uid": 25 + }, + "header": { + "alg": "RS256", + "typ": "JWT" + }, + "ttl": 31536000 + } + ], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 22, + "subscribed": 0, + "uid": 25, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated comment sql-allocator", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/author-vote-failure-after-commit", + "case": "author-vote-failure-after-commit", + "auth": "participant", + "seed": "7686b37d65aa", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated durable before vote", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 42, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBkdXJhYmxlIGJlZm9yZSB2b3RlIiwidm90ZSI6LTF9", + "byte_length": 84, + "sha256": "49d32790c568a4b143b5777a90accf223e985981e87bf1e101c5b78190a5f61e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 500, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "82", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"52-LAeXHUFkNdVto7zBY9226A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:34 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 18, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnQiLCJtZXNzYWdlIjoicG9saXNfZXJyX3Bvc3RfY29tbWVudCIsInN0YXR1cyI6NTAwfQ==", + "byte_length": 82, + "sha256": "2f7cc9c686fac91564bca3d7c208027d1c7678c26087e625bff6ad0d6c861f06" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 18, + "last_byte_ms": 18, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_post_comment", + "message": "polis_err_post_comment", + "status": 500 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 500, + "ttfbMs": 17.680662999999186, + "ttlbMs": 17.829914000001736 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 76, + "tweet_id": null, + "txt": "Generated durable before vote", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated durable before vote", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/retry-after-vote-failure", + "case": "retry-after-vote-failure", + "auth": "participant", + "seed": "6681e289fefe", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated durable before vote", + "vote": -1 + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 42, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBkdXJhYmxlIGJlZm9yZSB2b3RlIiwidm90ZSI6LTF9", + "byte_length": 84, + "sha256": "49d32790c568a4b143b5777a90accf223e985981e87bf1e101c5b78190a5f61e" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 409, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-zCIjZ1CCaueCny6M7+PsGg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:35 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwibWVzc2FnZSI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwic3RhdHVzIjo0MDl9", + "byte_length": 102, + "sha256": "0e516e9327d3ae940fe084092476cc6f2c8a23ca11c73e932e2b7c9f5ab635cf" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "error": "polis_err_post_comment_duplicate", + "message": "polis_err_post_comment_duplicate", + "status": 409 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 409, + "ttfbMs": 10.032110000000102, + "ttlbMs": 10.176193999999668 + }, + "effects": { + "db": {}, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/language-success", + "case": "language-success", + "auth": "participant", + "seed": "8c1de30c38cc", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment language-success" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 43, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGxhbmd1YWdlLXN1Y2Nlc3MifQ==", + "byte_length": 79, + "sha256": "9436394725aeb63451477d0f83c543c7e8f492953dfffe98369b97b83cd45844" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-lOVi7pWqWe2+rvpA9s3jrw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:35 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 6, + "bytes": { + "base64": "eyJ0aWQiOjc3LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "30570624746ee1b3e905ecb19d3c6760065b5499eede20a24264331ea7c0a18e" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 6, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 77 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.437211000004027, + "ttlbMs": 6.5919620000058785 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": "fr", + "lang_confidence": 0.5, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 77, + "tweet_id": null, + "txt": "Generated comment language-success", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment language-success", + "mode": "success" + } + ] + } + } + }, + { + "caseId": "post-comments/language-error", + "case": "language-error", + "auth": "participant", + "seed": "f864e94805ca", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment language-error" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 44, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGxhbmd1YWdlLWVycm9yIn0=", + "byte_length": 77, + "sha256": "74e9bd84ca135d84535c27b8477c8976b7aec741fb82d11598268df12f807941" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-uMDg0QovV3vk+pSLM696yg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:36 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 9, + "bytes": { + "base64": "eyJ0aWQiOjc4LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "4d328b450c35fc8a8682d2d4caeea0fd7fcb48cdaa78c0275f04c8477eaed727" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 9, + "last_byte_ms": 10, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 78 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 9.253520999998727, + "ttlbMs": 9.530731999999261 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 78, + "tweet_id": null, + "txt": "Generated comment language-error", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment language-error", + "mode": "error" + } + ] + } + } + }, + { + "caseId": "post-comments/language-malformed", + "case": "language-malformed", + "auth": "participant", + "seed": "a9ca2dc52f1d", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment language-malformed" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 45, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGxhbmd1YWdlLW1hbGZvcm1lZCJ9", + "byte_length": 81, + "sha256": "580a51890c21f46974ffb99eec8f31eff35763e9d890ff5e98a8953efbbebe1c" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-juOazAOMaMdkkxynszQqcw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:36 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjc5LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "be4515503aca0f65830a2a69c003c318e50ca45339726f6b22eeec5f6b153fc3" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 79 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.429363000002922, + "ttlbMs": 10.569364000002679 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 79, + "tweet_id": null, + "txt": "Generated comment language-malformed", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment language-malformed", + "mode": "malformed" + } + ] + } + } + }, + { + "caseId": "post-comments/language-timeout", + "case": "language-timeout", + "auth": "participant", + "seed": "02ca39bada14", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment language-timeout" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "observationProfile": { + "name": "post-comments-provider-timeout/1", + "deadlineMs": 10000, + "nodeDetectionBudgetMs": 5000 + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 46, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGxhbmd1YWdlLXRpbWVvdXQifQ==", + "byte_length": 79, + "sha256": "17ac8a409c4d3099f84a85617aa0eeda09f891966866933d21003d405fd73485" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-UVpBEu0qeWIqnp8tI0+UGA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 21:47:13 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5013, + "bytes": { + "base64": "eyJ0aWQiOjgwLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "24ffb9272a42e2776809cb7d804efe40b07992c5ee8dab7a21a1599d3fc7876d" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5013, + "last_byte_ms": 5014, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 80 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 5013.363486999995, + "ttlbMs": 5013.620235999995 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 80, + "tweet_id": null, + "txt": "Generated comment language-timeout", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": "eventual provider fallback; not participation latency qualification" + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment language-timeout", + "mode": "timeout" + } + ] + } + } + }, + { + "caseId": "post-comments/notification-task-failure", + "case": "notification-task-failure", + "auth": "participant", + "seed": "0db3a94fb18d", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment notification-task-failure" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 47, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG5vdGlmaWNhdGlvbi10YXNrLWZhaWx1cmUifQ==", + "byte_length": 88, + "sha256": "4d5eb8097de98c9842c8606f39e7bbaf85a6d9fffe59b4b0a8a402e991dc16bd" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-lrWeRhEus0n0IV7MyI0rrw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:42 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 7, + "bytes": { + "base64": "eyJ0aWQiOjgxLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "5b02ab9b5a8a09657cbbd4d9e70d7e2d5b9e2b32fb53caf8c6be55fb2632e98b" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 7, + "last_byte_ms": 7, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 81 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.889546999998856, + "ttlbMs": 7.0152149999994435 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 81, + "tweet_id": null, + "txt": "Generated comment notification-task-failure", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated comment notification-task-failure", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/notification-interaction-failure", + "case": "notification-interaction-failure", + "auth": "participant", + "seed": "763c6169220d", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment notification-interaction-failure" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 48, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG5vdGlmaWNhdGlvbi1pbnRlcmFjdGlvbi1mYWlsdXJlIn0=", + "byte_length": 95, + "sha256": "bb6b89b0d285b3139708d7b38465a688523f24b701f251e3b9664e4ab3618f42" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-7rtTnS2+9dnKQBqf1rptKw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:42 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 5, + "bytes": { + "base64": "eyJ0aWQiOjgyLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "4a76d49cd52647057dd802a81c11eceff69e3d4e844090cca4eb75eb38702fe6" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 5, + "last_byte_ms": 6, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 82 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 5.425285999997868, + "ttlbMs": 5.535495999996783 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 82, + "tweet_id": null, + "txt": "Generated comment notification-interaction-failure", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated comment notification-interaction-failure", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/moderation-count-failure", + "case": "moderation-count-failure", + "auth": "participant", + "seed": "4971a32df7d6", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment moderation-count-failure" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 49, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IG1vZGVyYXRpb24tY291bnQtZmFpbHVyZSJ9", + "byte_length": 87, + "sha256": "c1cfe1d9fc4d4712d6b99ecec8aff27d23adcbd8fc3dd9fe35f0a6f30d78da6b" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-L+5UY21FilQvpgcOO8x5qg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:19:43 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 6, + "bytes": { + "base64": "eyJ0aWQiOjgzLCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "0282e2fa4cdcd67698afc8ba861ac9ddcb42721634e5ece315ddb7f132196769" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 6, + "last_byte_ms": 6, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 83 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 6.248708999999508, + "ttlbMs": 6.390709999999672 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 83, + "tweet_id": null, + "txt": "Generated comment moderation-count-failure", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 1, + "languageCalls": [ + { + "text": "Generated comment moderation-count-failure", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-first-join", + "case": "standard-first-join", + "auth": "standard-nonmember", + "seed": "01be198f7fca", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard-nonmember" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-first-join" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-nonmember" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 50, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard-nonmember" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLWZpcnN0LWpvaW4ifQ==", + "byte_length": 82, + "sha256": "c41ffb91cdc767b95cbb6d4a9ce0f9d463455f33d2cc77bf176c7997279fbe97" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "26", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"1a-akEB4QWxnl0yspjMSyWkVw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 23:46:50 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 28, + "bytes": { + "base64": "eyJ0aWQiOjg0LCJjdXJyZW50UGlkIjoyM30=", + "byte_length": 26, + "sha256": "d0773b337344b829dac714d2010b45f7ff2cb1fdf5536c88025520ed4e62daaf" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 28, + "last_byte_ms": 28, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 23, + "tid": 84 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 27.955199999996694, + "ttlbMs": 28.13840699999855 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 23, + "quote_src_url": null, + "tid": 84, + "tweet_id": null, + "txt": "Generated comment standard-first-join", + "uid": 100005, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 24, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 23, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 23, + "subscribed": 0, + "uid": 100005, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 100005, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 23, + "subscribed": 0, + "uid": 100005, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-first-join", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/standard-repeat-join", + "case": "standard-repeat-join", + "auth": "standard-nonmember", + "seed": "21e680ccb413", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:standard-nonmember" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment standard-repeat-join" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "generated-nonmember" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 51, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:standard-nonmember" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHN0YW5kYXJkLXJlcGVhdC1qb2luIn0=", + "byte_length": 83, + "sha256": "9a64e3072c15e04506e375e54c4f831f5fa28dbe6141da46837bca4e7455c188" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "26", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"1a-/FsrcmxYVZmIuzFIFm5+Dg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 23:46:50 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 10, + "bytes": { + "base64": "eyJ0aWQiOjg1LCJjdXJyZW50UGlkIjoyM30=", + "byte_length": 26, + "sha256": "c67da9c84c86a2e0526e5d28e3eba32edc6db60e0aed3b21c1c99c15b8695b98" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 10, + "last_byte_ms": 11, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 23, + "tid": 85 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 10.398767999999109, + "ttlbMs": 10.588599999995495 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 23, + "quote_src_url": null, + "tid": 85, + "tweet_id": null, + "txt": "Generated comment standard-repeat-join", + "uid": 100005, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment standard-repeat-join", + "mode": "null-fallback" + } + ] + } + } + }, + { + "caseId": "post-comments/text-absent", + "case": "text-absent", + "auth": "unauthenticated", + "seed": "711b4364041e", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https" + }, + "body": { + "conversation_id": "2p027generated" + } + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 51, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCJ9", + "byte_length": 36, + "sha256": "92a8afa9717d27f3ae40cbafd2d4539a25c43d7aa1f2e57007ed322837844f8c" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 400, + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "X-Content-Type-Options", + "value": "nosniff", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "12", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 23:46:51 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 14, + "bytes": { + "base64": "QmFkIFJlcXVlc3QK", + "byte_length": 12, + "sha256": "0cd6aed5d21ae37310b3c4e0facf48009005018bf4402fbcda1cb66d69b03346" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 14, + "last_byte_ms": 15, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "Bad Request\n", + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "text/html; charset=utf-8" + }, + "status": 400, + "ttfbMs": 14.31286800000089, + "ttlbMs": 14.514074999999139 + }, + "effects": { + "db": { + "pg:conversations": { + "added": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 25, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ], + "removed": [ + { + "auth_needed_to_vote": null, + "auth_needed_to_write": null, + "auth_opt_allow_3rdparty": null, + "auth_opt_fb": null, + "auth_opt_tw": null, + "bgcolor": null, + "branding_type": 1, + "context": null, + "course_id": null, + "created": 1700000001000, + "description": "Public-fixture inputs only", + "email_domain": null, + "help_bgcolor": null, + "help_color": null, + "help_type": 1, + "importance_enabled": false, + "is_active": true, + "is_anon": true, + "is_data_open": false, + "is_draft": false, + "is_public": true, + "link_url": null, + "modified": 1700000001000, + "org_id": null, + "owner": 1, + "owner_sees_participation_stats": false, + "parent_url": null, + "participant_count": 24, + "prioritize_seed": false, + "profanity_filter": false, + "socialbtn_type": 0, + "spam_filter": false, + "strict_moderation": false, + "style_btn": null, + "subscribe_type": 1, + "topic": "Generated characterization conversation", + "topics_enabled": false, + "treevite_enabled": false, + "upvotes": 1, + "use_xid_whitelist": false, + "vis_type": 0, + "write_hint_type": 1, + "write_type": 1, + "xid_required": false, + "zid": 1 + } + ] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 24, + "subscribed": 0, + "uid": 26, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants_extended": { + "added": [ + { + "created": 1700000000000, + "modified": 1700000000000, + "origin": null, + "parent_url": null, + "permanent_cookie": null, + "referrer": null, + "show_translation_activated": null, + "subscribe_email": null, + "uid": 26, + "zid": 1 + } + ], + "removed": [] + }, + "pg:users": { + "added": [ + { + "created": 1700000000000, + "email": null, + "hname": null, + "is_owner": false, + "oinvite": null, + "site_id": "$site_id:23", + "site_owner": true, + "tut": 0, + "uid": 26, + "username": null, + "zinvite": null + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 1, + "jwts": [], + "outbound": [], + "participantCreated": 1, + "participants": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 24, + "subscribed": 0, + "uid": 26, + "vote_count": 0, + "zid": 1 + } + ] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 0, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + }, + { + "caseId": "post-comments/site-moderator-recipient", + "case": "site-moderator-recipient", + "auth": "participant", + "seed": "d7730325bdbc", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment site-moderator-recipient" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 52, + "count": 2, + "recipients": [ + { + "class": "owner", + "address": "Generated Owner " + }, + { + "class": "site-moderator", + "address": "Generated moderator " + } + ] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IHNpdGUtbW9kZXJhdG9yLXJlY2lwaWVudCJ9", + "byte_length": 87, + "sha256": "a58c154262475633956a6be39ab3543695ed8a43d616bbac1f6a440972a078b4" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-2WlGC6J21Vu6y3Lh3yNGgQ\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 23:46:51 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 14, + "bytes": { + "base64": "eyJ0aWQiOjg2LCJjdXJyZW50UGlkIjoyfQ==", + "byte_length": 25, + "sha256": "ac0ab92474087ce8e0d0a1b5a3b1866ceeeebdda1f6a12eec660c7117111eeb1" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 14, + "last_byte_ms": 14, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 86 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 13.552040000002307, + "ttlbMs": 13.735037999998895 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 86, + "tweet_id": null, + "txt": "Generated comment site-moderator-recipient", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [ + { + "at_ms": 37.75001300001168, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "52 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "52 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 41.85061300000234, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "52 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "52 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated Owner " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + }, + { + "at_ms": 42.349984000000404, + "blocked": false, + "host": "comments-ses", + "method": null, + "path": null, + "port": 8025, + "protocol": "tcp", + "termination": null + }, + { + "at_ms": 56.33635500000673, + "command": "SendEmailCommand", + "input": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "52 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "52 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated moderator " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "response": { + "$metadata": { + "attempts": 1, + "httpStatusCode": 200, + "totalRetryDelay": 0 + }, + "MessageId": "generated-local-message" + }, + "service": "SESv2", + "termination": "end" + }, + { + "at_ms": 57.69472100000712, + "blocked": false, + "body": { + "Content": { + "Simple": { + "Body": { + "Html": { + "Charset": "UTF-8", + "Data": "52 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. +
Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis.
" + }, + "Text": { + "Charset": "UTF-8", + "Data": "52 Statements are waiting for your review here: https://pol.is/m/2p027generated\n\nThank you for using Polis. - Polis is powered by donations from people like you. Donate at https://donorbox.org/geo-polis." + } + }, + "Subject": { + "Charset": "UTF-8", + "Data": "Waiting for review (conversation 2p027generated)" + } + } + }, + "Destination": { + "ToAddresses": [ + "Generated moderator " + ] + }, + "FromEmailAddress": "sender@example.invalid" + }, + "host": "comments-ses", + "method": "POST", + "path": "/v2/email/outbound-emails", + "port": 8025, + "protocol": "http", + "response": "{\"MessageId\":\"generated-local-message\"}", + "termination": "end" + } + ], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment site-moderator-recipient", + "mode": "null-fallback" + } + ] + } + } + } +] diff --git a/server/characterization/post-comments/golden/concurrent.json b/server/characterization/post-comments/golden/concurrent.json new file mode 100644 index 000000000..ce41f063f --- /dev/null +++ b/server/characterization/post-comments/golden/concurrent.json @@ -0,0 +1,613 @@ +[ + { + "case": "concurrent-unique", + "responses": [ + { + "caseId": "post-comments/concurrent-unique/0", + "case": "concurrent-unique/0", + "auth": "participant", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated concurrent-unique 0" + } + }, + "response": { + "body": { + "currentPid": 2, + "tid": 87 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200 + }, + "effects": { + "db": { + "pg:comments": { + "removed": [], + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 87, + "tweet_id": null, + "txt": "Generated concurrent-unique 0", + "uid": 3, + "velocity": 1, + "zid": 1 + }, + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 88, + "tweet_id": null, + "txt": "Generated concurrent-unique 1", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ] + } + }, + "files": {}, + "outbound": [], + "participantCreated": 0, + "participants": [], + "jwtIssued": 0, + "jwts": [], + "jwtMinted": 0 + }, + "process": [], + "routeHits": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "wireBody": "eyJ0aWQiOjg3LCJjdXJyZW50UGlkIjoyfQ==", + "orderedHeaders": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-jL9j2NdbWyRMAa4lKw13lA\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + } + ] + }, + { + "caseId": "post-comments/concurrent-unique/1", + "case": "concurrent-unique/1", + "auth": "pid0", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated concurrent-unique 1" + } + }, + "response": { + "body": { + "currentPid": 0, + "tid": 88 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200 + }, + "effects": { + "db": { + "pg:comments": { + "removed": [], + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 87, + "tweet_id": null, + "txt": "Generated concurrent-unique 0", + "uid": 3, + "velocity": 1, + "zid": 1 + }, + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 88, + "tweet_id": null, + "txt": "Generated concurrent-unique 1", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ] + } + }, + "files": {}, + "outbound": [], + "participantCreated": 0, + "participants": [], + "jwtIssued": 0, + "jwts": [], + "jwtMinted": 0 + }, + "process": [], + "routeHits": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "wireBody": "eyJ0aWQiOjg4LCJjdXJyZW50UGlkIjowfQ==", + "orderedHeaders": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-zYfKJcrLcDHuSiFutkDr0Q\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + } + ] + } + ], + "comments": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 87, + "tweet_id": null, + "txt": "Generated concurrent-unique 0", + "uid": 3, + "velocity": 1, + "zid": 1 + }, + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 1, + "modified": 1700000000000, + "original_id": null, + "pid": 0, + "quote_src_url": null, + "tid": 88, + "tweet_id": null, + "txt": "Generated concurrent-unique 1", + "uid": 1, + "velocity": 1, + "zid": 1 + } + ] + }, + { + "case": "concurrent-duplicate", + "responses": [ + { + "caseId": "post-comments/concurrent-duplicate/0", + "case": "concurrent-duplicate/0", + "auth": "participant", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated concurrent-duplicate 0" + } + }, + "response": { + "body": { + "currentPid": 2, + "tid": 89 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200 + }, + "effects": { + "db": { + "pg:comments": { + "removed": [], + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 89, + "tweet_id": null, + "txt": "Generated concurrent-duplicate 0", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ] + } + }, + "files": {}, + "outbound": [], + "participantCreated": 0, + "participants": [], + "jwtIssued": 0, + "jwts": [], + "jwtMinted": 0 + }, + "process": [], + "routeHits": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "wireBody": "eyJ0aWQiOjg5LCJjdXJyZW50UGlkIjoyfQ==", + "orderedHeaders": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "25", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"19-ay4RZp2UDR92/ssjWUQ5Bw\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + } + ] + }, + { + "caseId": "post-comments/concurrent-duplicate/1", + "case": "concurrent-duplicate/1", + "auth": "pid0", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:pid0" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated concurrent-duplicate 0" + } + }, + "response": { + "body": { + "error": "polis_err_post_comment_duplicate", + "message": "polis_err_post_comment_duplicate", + "status": 409 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 409 + }, + "effects": { + "db": { + "pg:comments": { + "removed": [], + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 89, + "tweet_id": null, + "txt": "Generated concurrent-duplicate 0", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ] + } + }, + "files": {}, + "outbound": [], + "participantCreated": 0, + "participants": [], + "jwtIssued": 0, + "jwts": [], + "jwtMinted": 0 + }, + "process": [], + "routeHits": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "wireBody": "eyJlcnJvciI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwibWVzc2FnZSI6InBvbGlzX2Vycl9wb3N0X2NvbW1lbnRfZHVwbGljYXRlIiwic3RhdHVzIjo0MDl9", + "orderedHeaders": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "102", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"66-zCIjZ1CCaueCny6M7+PsGg\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + } + ] + } + ], + "comments": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 89, + "tweet_id": null, + "txt": "Generated concurrent-duplicate 0", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ] + } +] diff --git a/server/characterization/post-comments/golden/default-timeout-observation.json b/server/characterization/post-comments/golden/default-timeout-observation.json new file mode 100644 index 000000000..a243bd883 --- /dev/null +++ b/server/characterization/post-comments/golden/default-timeout-observation.json @@ -0,0 +1,170 @@ +{ + "caseId": "post-comments/language-timeout", + "case": "language-timeout", + "auth": "participant", + "seed": "02ca39bada14", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment language-timeout" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 46, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGxhbmd1YWdlLXRpbWVvdXQifQ==", + "byte_length": 79, + "sha256": "17ac8a409c4d3099f84a85617aa0eeda09f891966866933d21003d405fd73485" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": null, + "headers": [], + "body": [], + "completed": false, + "termination": "deadline", + "first_byte_ms": null, + "last_byte_ms": 2003, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": "", + "completed": false, + "headers": {}, + "status": null, + "ttfbMs": null, + "ttlbMs": 2003.0406430000003 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 80, + "tweet_id": null, + "txt": "Generated comment language-timeout", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": false, + "failures": [ + "response timing bound exceeded", + "completion deadline exceeded" + ], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [ + { + "text": "Generated comment language-timeout", + "mode": "timeout" + } + ] + } + } +} diff --git a/server/characterization/post-comments/golden/disabled/cases.json b/server/characterization/post-comments/golden/disabled/cases.json new file mode 100644 index 000000000..30e40d71a --- /dev/null +++ b/server/characterization/post-comments/golden/disabled/cases.json @@ -0,0 +1,277 @@ +[ + { + "caseId": "post-comments/language-disabled", + "case": "language-disabled", + "auth": "participant", + "seed": "afc975edd39a", + "request": { + "method": "POST", + "path": "/api/v3/comments", + "query": {}, + "headers": { + "content-type": "application/json", + "x-forwarded-proto": "https", + "authorization": "$auth:participant" + }, + "body": { + "conversation_id": "2p027generated", + "txt": "Generated comment language-disabled" + } + }, + "credentialBinding": { + "zid": 1, + "oidcSub": "anon:3" + }, + "notificationPolicy": { + "template": "comment-moderation", + "conversationId": "2p027generated", + "pending": 1, + "count": 0, + "recipients": [] + }, + "version": 1, + "wire": { + "request": { + "method": "POST", + "target": { + "base64": "L2FwaS92My9jb21tZW50cw==", + "byte_length": 16, + "sha256": "687f88731c96cd6aff976b597ce4b0262de970d5c59a04734b83511d877bb783" + }, + "headers": [ + { + "name": "host", + "value": "localhost:5000", + "credential_ref": null + }, + { + "name": "content-type", + "value": "application/json", + "credential_ref": null + }, + { + "name": "x-forwarded-proto", + "value": "https", + "credential_ref": null + }, + { + "name": "authorization", + "value": null, + "credential_ref": "$auth:participant" + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Transfer-Encoding", + "value": "chunked", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 0, + "bytes": { + "base64": "eyJjb252ZXJzYXRpb25faWQiOiIycDAyN2dlbmVyYXRlZCIsInR4dCI6IkdlbmVyYXRlZCBjb21tZW50IGxhbmd1YWdlLWRpc2FibGVkIn0=", + "byte_length": 80, + "sha256": "70347d9042abe0a430e15e654913f64c7a2f71a3e0234faaad0d7ab28b79a14a" + } + } + ], + "encoding": "utf8" + }, + "response": { + "status": 200, + "headers": [ + { + "name": "Content-Type", + "value": "application/json; charset=utf-8", + "credential_ref": null + }, + { + "name": "Cache-Control", + "value": "no-cache", + "credential_ref": null + }, + { + "name": "Connection", + "value": "keep-alive", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Origin", + "value": "https://localhost", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Credentials", + "value": "true", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Headers", + "value": "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With", + "credential_ref": null + }, + { + "name": "Access-Control-Allow-Methods", + "value": "GET, PUT, POST, DELETE, OPTIONS", + "credential_ref": null + }, + { + "name": "Content-Length", + "value": "24", + "credential_ref": null + }, + { + "name": "ETag", + "value": "W/\"18-8SXeWElXYLsBVYIi3krn3A\"", + "credential_ref": null + }, + { + "name": "Vary", + "value": "Accept-Encoding", + "credential_ref": null + }, + { + "name": "Date", + "value": "Thu, 22 Oct 2026 20:25:39 GMT", + "credential_ref": null + } + ], + "body": [ + { + "sequence": 0, + "at_ms": 41, + "bytes": { + "base64": "eyJ0aWQiOjIsImN1cnJlbnRQaWQiOjJ9", + "byte_length": 24, + "sha256": "90963a83e0f648e47de77e8a017c16a5c8b853459f7822713db0a7f9b2882cb2" + } + } + ], + "completed": true, + "termination": "end", + "first_byte_ms": 41, + "last_byte_ms": 41, + "process_alive_at_end": true + }, + "encoding": "utf8" + }, + "response": { + "body": { + "currentPid": 2, + "tid": 2 + }, + "completed": true, + "headers": { + "access-control-allow-credentials": "true", + "access-control-allow-origin": "https://localhost", + "cache-control": "no-cache", + "content-type": "application/json; charset=utf-8" + }, + "status": 200, + "ttfbMs": 40.72977100000003, + "ttlbMs": 41.30344100000002 + }, + "effects": { + "db": { + "pg:comments": { + "added": [ + { + "active": true, + "anon": false, + "created": 1700000000000, + "is_meta": false, + "is_seed": false, + "lang": null, + "lang_confidence": null, + "mod": 0, + "modified": 1700000000000, + "original_id": null, + "pid": 2, + "quote_src_url": null, + "tid": 2, + "tweet_id": null, + "txt": "Generated comment language-disabled", + "uid": 3, + "velocity": 1, + "zid": 1 + } + ], + "removed": [] + }, + "pg:notification_tasks": { + "added": [ + { + "modified": 1700000000000, + "zid": 1 + } + ], + "removed": [] + }, + "pg:participants": { + "added": [ + { + "created": 1700000000000, + "last_interaction": 1700000000000, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 2, + "subscribed": 0, + "uid": 3, + "vote_count": 0, + "zid": 1 + } + ], + "removed": [ + { + "created": 1700000000000, + "last_interaction": 0, + "last_notified": 0, + "mod": 0, + "nsli": 0, + "pid": 2, + "subscribed": 0, + "uid": 3, + "vote_count": 0, + "zid": 1 + } + ] + } + }, + "files": {}, + "jwtIssued": 0, + "jwtMinted": 0, + "jwts": [], + "outbound": [], + "participantCreated": 0, + "participants": [] + }, + "process": [], + "oracle": { + "pass": true, + "failures": [], + "flag": null + }, + "routeHits": [ + 1, + 3, + 44 + ], + "commentProof": { + "commentsAdded": 1, + "votesAdded": 0, + "storedMeanings": [], + "fault": { + "armed": null, + "fired": 0, + "languageCalls": [] + } + } + } +] diff --git a/server/characterization/post-comments/observation.cjs b/server/characterization/post-comments/observation.cjs new file mode 100644 index 000000000..265ae88ae --- /dev/null +++ b/server/characterization/post-comments/observation.cjs @@ -0,0 +1,37 @@ +"use strict"; + +const assert = require("node:assert/strict"); +const { oracle } = require("../core.cjs"); + +const PROVIDER_TIMEOUT = Object.freeze({ + name: "post-comments-provider-timeout/1", + deadlineMs: 10000, + nodeDetectionBudgetMs: 5000, +}); + +// This is an eventual-response observation, never a participation latency proof. +// Unmarked cases keep the shared sender and oracle's original two-second bound. +function observation(c, enabled = process.env.P027_COMMENTS_PROFILE === "1") { + if (c.observationProfile === undefined) return { oracle }; + assert.equal(enabled, true, "comments observation requires its sealed profile"); + assert.equal(c.caseId, "post-comments/language-timeout"); + assert.equal(c.case, "language-timeout"); + assert.equal(c.request.method, "POST"); + assert.equal(c.request.path, "/api/v3/comments"); + assert.deepEqual(c.observationProfile, PROVIDER_TIMEOUT); + return { + deadlineMs: PROVIDER_TIMEOUT.deadlineMs, + oracle(response, processErrors) { + const failures = []; + if (response.ttlbMs > PROVIDER_TIMEOUT.deadlineMs || + response.ttfbMs > PROVIDER_TIMEOUT.deadlineMs) + failures.push("provider-timeout observation bound exceeded"); + if (!response.completed) failures.push("completion deadline exceeded"); + if (processErrors.length) failures.push("process error during case"); + return { pass: failures.length === 0, failures, + flag: "eventual provider fallback; not participation latency qualification" }; + }, + }; +} + +module.exports = { PROVIDER_TIMEOUT, observation }; diff --git a/server/characterization/post-comments/observation.test.cjs b/server/characterization/post-comments/observation.test.cjs new file mode 100644 index 000000000..80829973d --- /dev/null +++ b/server/characterization/post-comments/observation.test.cjs @@ -0,0 +1,46 @@ +"use strict"; +const test = require("node:test"); +const assert = require("node:assert/strict"); +const { oracle } = require("../core.cjs"); +const { PROVIDER_TIMEOUT, observation } = require("./observation.cjs"); +const timeoutCase = () => ({ + caseId: "post-comments/language-timeout", case: "language-timeout", + request: { method: "POST", path: "/api/v3/comments" }, + observationProfile: { ...PROVIDER_TIMEOUT }, +}); +const response = { completed: true, ttlbMs: 5100, ttfbMs: 5050 }; + +test("unmarked cases retain the exact default oracle and sender deadline", () => { + assert.deepEqual(observation({}, true), { oracle }); + assert.deepEqual(observation({}, false), { oracle }); + assert.equal(observation({}).oracle(response, []).pass, false); +}); +test("declared provider timeout captures eventual response after Node budget", () => { + const profile = observation(timeoutCase(), true); + assert.equal(profile.deadlineMs, 10000); + assert.equal(profile.oracle(response, []).pass, true); +}); +test("timeout profile rejects every other case and route", () => { + for (const change of [ + { caseId: "post-comments/language-error" }, { case: "language-error" }, + { request: { method: "GET", path: "/api/v3/comments" } }, + { request: { method: "POST", path: "/api/v3/votes" } }, + ]) assert.throws(() => observation({ ...timeoutCase(), ...change }, true)); +}); +test("timeout profile cannot run without comments isolation", () => { + assert.throws(() => observation(timeoutCase(), false)); +}); +test("profile metadata and deadline are exact and cannot be supplied freely", () => { + for (const profile of [{}, { ...PROVIDER_TIMEOUT, deadlineMs: 60000 }, + { ...PROVIDER_TIMEOUT, extra: true }]) { + assert.throws(() => observation({ ...timeoutCase(), observationProfile: profile }, true)); + } +}); +test("eventual observation still fails slow, incomplete and process-error responses", () => { + const profile = observation(timeoutCase(), true); + for (const value of [{ ...response, completed: false }, + { ...response, ttlbMs: 10001 }, { ...response, ttfbMs: 10001 }]) { + assert.equal(profile.oracle(value, []).pass, false); + } + assert.equal(profile.oracle(response, ["unhandled rejection"]).pass, false); +}); diff --git a/server/characterization/post-comments/run.cjs b/server/characterization/post-comments/run.cjs new file mode 100644 index 000000000..4938ab0ce --- /dev/null +++ b/server/characterization/post-comments/run.cjs @@ -0,0 +1,218 @@ +"use strict"; +require("ts-node/register/transpile-only"); +const fs=require("node:fs"), path=require("node:path"), assert=require("node:assert/strict"); +const {Pool}=require("pg"); +const recorder=require("../cli.cjs"); +const {Normalizer}=require("../normalize.cjs"); +const {hash}=require("../core.cjs"); +const {artifactDirectory}=require("./artifact-path.cjs"); +const {records,put,pin}=require("../recording.cjs"); +const {firstDifference,comparable}=require("../compare.cjs"); +const {canonical}=require("../core.cjs"); +const {applyExpectedDifferences}=require("../collective-statement/expected.cjs"); +const convention=require("../../src/votes/convention.ts"); +const pool=new Pool({connectionString:process.env.DATABASE_URL}); +const out=process.argv[2]; +async function get(p){const r=await fetch(process.env.P027_CONTROL_URL+p,{signal:AbortSignal.timeout(10000)});assert.equal(r.status,200);return r.json();} +const cases=[]; +function add(name,auth="participant",body={},status=200,setup=null,fault=null){cases.push({name,auth,body,status,setup,fault});} +add("anonymous-first","unauthenticated"); +for(const actor of ["pid0","participant","standard","xid","owner","admin","site-moderator"]) { + add(actor+"-no-vote",actor); + for(const meaning of ["agree","disagree","pass"]) add(actor+"-"+meaning,actor,{vote:convention.semanticToWire(meaning)}); + add(actor+"-seed",actor,{is_seed:true}); + add(actor+"-seed-explicit-vote",actor,{is_seed:true,vote:convention.semanticToWire("agree")}); + add(actor+"-closed",actor,{},403,"closed"); + add(actor+"-strict",actor,{},200,"strict"); +} +add("oidc-first-use","comments-owner-1"); +add("oidc-repeat","comments-owner-1"); +add("xid-first-use","unauthenticated",{xid:"generated-new-comment-member"}); +add("xid-existing-bare","unauthenticated",{xid:"generated-member"}); +add("xid-request-precedence","xid",{xid:"generated-comment-override"}); +add("xid-required","unauthenticated",{},403,"required"); +add("xid-whitelisted","xid",{},200,"whitelist"); +add("xid-refused","unauthenticated",{xid:"generated-denied"},403,"whitelist"); +for(const actor of ["pid0","participant","standard","xid","owner"]) add("treevite-"+actor,actor,{},200,"treevite"); +add("treevite-anonymous-refused","unauthenticated",{},401,"treevite"); +add("treevite-xid-refused","unauthenticated",{xid:"generated-treevite-new"},401,"treevite"); +add("treevite-oidc-first-refused","comments-owner-2",{},401,"treevite"); +add("foreign-token","foreign"); +for(const actor of ["expired","bad","signature"]) add("auth-"+actor,actor,{},401); +for(const [name,txt] of [["empty",""],["spaces"," "]]) add("text-"+name,"unauthenticated",{txt},400); +for(const [name,txt] of [["null",null],["number",7],["boolean",false],["array",[]],["object",{}],["too-long","x".repeat(998)],["utf16-too-long","😀".repeat(499)]]) add("text-"+name,"unauthenticated",{txt},400); +add("text-max-length","participant",{txt:"x".repeat(997)}); +add("text-utf16-boundary","participant",{txt:"😀".repeat(498)+"x"}); +add("text-tab","participant",{txt:"\t"}); +add("text-trim","participant",{txt:" Generated trimmed text "}); +add("text-trim-duplicate","participant",{txt:"Generated trimmed text"},409); +add("duplicate-before-closed","participant",{txt:"Generated statement A"},409,"closed"); +add("duplicate-exact","participant",{txt:"Generated statement A"},409); +add("duplicate-case-sensitive","participant",{txt:"generated statement A"}); +add("vote-null","participant",{vote:null}); +add("vote-prefix","participant",{vote:String(convention.semanticToWire("pass"))+"suffix"}); +add("vote-fraction-string","participant",{vote:"0.9"}); +for(const vote of [2,0.5,true,"bad",[],{}]) add("vote-invalid-"+JSON.stringify(vote),"participant",{vote},400); +for(const [name,value] of [["number",2],["off","OFF"],["null",null]]) add("seed-"+name,"owner",{is_seed:value}); +add("seed-invalid","participant",{is_seed:" true "},400); +add("ignored-fields","participant",{pid:999,uid:999,tid:999,lang:"fr",weight:123,nextComment:true}); +add("missing-conversation","unauthenticated",{conversation_id:null},400); +add("unknown-conversation","participant",{conversation_id:"2generatedmissing"},400); +add("invalid-xid","unauthenticated",{xid:3},400); +for(const [name,status] of [["insert",500],["participant",500],["foreign",500],["duplicate",409],["allocator",500]]) add("sql-"+name,"unauthenticated",{},status,null,name); +add("author-vote-failure-after-commit","participant",{txt:"Generated durable before vote",vote:convention.semanticToWire("agree")},500,null,"vote"); +add("retry-after-vote-failure","participant",{txt:"Generated durable before vote",vote:convention.semanticToWire("agree")},409); +for (const mode of ["success", "error", "malformed", "timeout"]) { + add("language-"+mode,"participant"); cases[cases.length - 1].language=mode; +} +add("notification-task-failure","participant",{},200,null,"notification"); +add("notification-interaction-failure","participant",{},200,null,"interaction"); +add("moderation-count-failure","participant",{},200,"strict","moderation"); +// Append coverage cases so existing serial observations keep their fixture order. +add("standard-first-join","standard-nonmember"); +add("standard-repeat-join","standard-nonmember"); +add("text-absent","unauthenticated",{},400); +add("site-moderator-recipient","participant",{},200,"strict"); + +if(process.env.COMMENTS_ADDITIONAL === "1") { + cases.splice(0,cases.length); + for(const actor of ["pid0","participant","standard","xid","owner","admin","site-moderator"]) + for(const meaning of ["disagree","pass"]) + add(actor+"-seed-"+meaning,actor,{is_seed:true,vote:convention.semanticToWire(meaning)}); + for(const [fault,status] of [["account",500],["account-conflict",429],["account-load",429]]) { + add("oidc-"+fault,"comments-owner-2",{},status);cases[cases.length - 1].accountFault=fault; + } + add("oidc-missing-email","oidc-missing-email",{},400); + for(const kind of ["expired","issuer","audience","signature","unknown-key"]) + add("oidc-"+kind,"oidc-"+kind,{},401); +} +if(process.env.COMMENTS_LANGUAGE_DISABLED === "1") { + cases.splice(0,cases.length,{name:"language-disabled",auth:"participant",body:{},status:200,language:"disabled"}); +} +async function main(){ + assert.equal(new URL(process.env.DATABASE_URL).pathname,"/p027"); + assert.ok(out && out.startsWith("/artifacts/comments-")); + fs.mkdirSync(out,{recursive:true}); + await pool.query("INSERT INTO users(uid,hname,site_id) VALUES(100004,'Generated moderator','p027-owner')"); + const moderator=await pool.query("INSERT INTO participants(zid,uid,created) VALUES(1,100004,1700000000000) RETURNING pid"); + await pool.query("INSERT INTO xids(owner,uid,xid,zid,pid) VALUES(1,3,'generated-member',1,2)"); + await pool.query("INSERT INTO xid_whitelist(owner,xid) VALUES(1,'generated-member')"); + const tokens={...await get("/tokens"),...await get("/votes-tokens?moderatorPid="+moderator.rows[0].pid)}; + const tables=[...new Set((await recorder.schema()).map(r=>r.table_name))]; + const normalizer=new Normalizer(), actual=[], failures=[]; + let firstStandardPid; + for(const spec of cases){ + if(spec.name === "standard-first-join") { + await pool.query("INSERT INTO users(uid,hname,site_id) VALUES(100005,'Generated first standard','generated-first-standard')"); + assert.equal((await pool.query("SELECT pid FROM participants WHERE zid=1 AND uid=100005")).rowCount,0); + } + if(spec.name === "site-moderator-recipient") { + await pool.query("UPDATE users SET email='moderator@example.invalid' WHERE uid=100004"); + await pool.query("INSERT INTO page_ids(site_id,page_id,zid) VALUES('p027-owner','generated-comments-page',1)"); + // The owner belongs to both recipient SELECTs; UNION must send it only once. + const siteUsers=await pool.query("SELECT uid FROM users WHERE site_id=(SELECT site_id FROM page_ids WHERE zid=1) ORDER BY uid"); + assert.deepEqual(siteUsers.rows.map(r=>r.uid),[1,100004]); + } + await pool.query("UPDATE conversations SET is_active=$1,strict_moderation=$2,treevite_enabled=$3,xid_required=$4,use_xid_whitelist=$5 WHERE zid=1",[spec.setup!=="closed",spec.setup==="strict",spec.setup==="treevite",spec.setup==="required",spec.setup==="whitelist"]); + if(process.env.COMMENTS_ADDITIONAL === "1")await get("/votes-fault?kind="+(spec.accountFault||"none")); + await get("/comments-fault?kind="+(spec.fault||"none")+"&language="+(spec.language||"null-fallback")); + const c={caseId:"post-comments/"+spec.name,case:spec.name,auth:spec.auth,seed:hash(spec.name).slice(0,12), + request:{method:"POST",path:"/api/v3/comments",query:{},headers:{"content-type":"application/json","x-forwarded-proto":"https",...(spec.auth==="unauthenticated"?{}:{authorization:"$auth:"+spec.auth})},body:{conversation_id:"2p027generated",txt:"Generated comment "+spec.name,...spec.body}}}; + if(spec.name === "text-absent") delete c.request.body.txt; + if(tokens[spec.auth]?.includes(".")) { + const claims=JSON.parse(Buffer.from(tokens[spec.auth].split(".")[1],"base64url")); + c.credentialBinding={zid:1,oidcSub:claims.oidc_sub||claims.sub,xid:typeof spec.body.xid==="string"&&spec.body.xid.trim()?spec.body.xid:claims.xid}; + } + if(spec.language === "timeout") + c.observationProfile = require("./observation.cjs").PROVIDER_TIMEOUT; + assert.ok(spec.auth === "unauthenticated" || tokens[spec.auth], spec.name+" fixture token"); + const pending=Number((await pool.query("SELECT count(*) FROM comments WHERE zid=1 AND mod=0")).rows[0].count); + const moderator=["pid0","owner","admin","site-moderator"].includes(spec.auth); + const willCommit=spec.status===200||spec.fault==="vote"; + const waiting=pending+(willCommit&&!moderator?1:0); + c.notificationPolicy={template:"comment-moderation",conversationId:"2p027generated",pending:waiting, + count:spec.setup==="strict" && spec.fault!=="moderation" && waiting>0?1:0, + recipients:spec.setup==="strict" && spec.fault!=="moderation" && waiting>0?[{class:"owner",address:"Generated Owner "}]:[]}; + if(spec.name === "site-moderator-recipient") { + c.notificationPolicy.recipients.push({class:"site-moderator",address:"Generated moderator "}); + c.notificationPolicy.count=2; + } + let r; + try { r=await recorder.runCase(c,tokens,tables,normalizer); } + catch(error) { + failures.push({case:spec.name,phase:"recorder",error:String(error)}); + put(out,"failures.json",failures); console.error(JSON.stringify(failures[failures.length - 1])); continue; + } + const after=await recorder.snapshot(tables), fault=await get("/comments-fault-state"); + const comments=r.effects.db["pg:comments"]?.added||[], votes=r.effects.db["pg:votes"]?.added||[]; + r.commentProof={commentsAdded:comments.length,votesAdded:votes.length,storedMeanings:votes.map(v=>convention.storageToSemantic(v.vote)),fault}; + const dest=path.join(out,artifactDirectory(String(actual.length).padStart(3,"0")+"-"+spec.name)); + fs.mkdirSync(dest,{recursive:true});put(dest,"comparison.json",r); + for(const [name,value] of Object.entries(records(r)))put(dest,name+".json",value); + actual.push(r);put(out,"cases.json",actual); + console.log(JSON.stringify({case:spec.name,status:r.response.status,comments:comments.length,votes:votes.length,oracle:r.oracle})); + try { + assert.equal(r.response.status,spec.status,spec.name+" status"); + assert.equal(r.oracle.pass,true,JSON.stringify(r.oracle)); + if(["text-absent","text-null"].includes(spec.name)) { + assert.equal(r.response.body,"Bad Request\n"); + assert.equal(r.response.headers["content-type"],"text/html; charset=utf-8"); + assert.equal(r.effects.participantCreated,1); + assert.equal(r.effects.jwtIssued,0); + } + if(["standard-first-join","standard-repeat-join"].includes(spec.name)) { + assert.equal(r.effects.participantCreated,spec.name === "standard-first-join"?1:0); + const memberships=await pool.query("SELECT pid FROM participants WHERE zid=1 AND uid=100005"); + assert.equal(memberships.rowCount,1); + assert.deepEqual(r.response.body,{tid:comments[0].tid,currentPid:memberships.rows[0].pid}); + assert.equal(r.effects.jwtIssued,0); + if(spec.name === "standard-first-join") firstStandardPid=r.response.body.currentPid; + else assert.equal(r.response.body.currentPid,firstStandardPid); + } + assert.equal(fault.fired,spec.fault?1:0); + if(spec.accountFault)assert.equal((await get("/votes-fault-state")).fired,1); + const committed=spec.status===200||spec.fault==="vote"; + assert.equal(comments.length,committed?1:0,spec.name+" comment durability"); + const suppliedVote=spec.body.vote!==undefined&&spec.body.vote!==null; + assert.equal(votes.length,spec.status===200&&suppliedVote?1:0,spec.name+" explicit-only author vote"); + if(committed) { + const row=comments[0]; + assert.equal(row.txt,c.request.body.txt.replace(/^ */,"").replace(/ *$/,"")); + assert.equal(row.active,true); assert.equal(row.anon,false); assert.equal(row.velocity,1); + const moderator=["pid0","owner","admin","site-moderator"].includes(spec.auth); + assert.equal(row.mod,moderator?1:0); + assert.equal(row.is_seed,moderator&&[true,2].includes(spec.body.is_seed)); + assert.equal(row.lang,spec.language==="success"?"fr":null); assert.equal(row.lang_confidence,spec.language==="success"?0.5:null); + if(spec.status===200){assert.equal(r.response.body.tid,row.tid);assert.equal(r.response.body.currentPid,row.pid);assert.equal(Object.hasOwn(r.response.body,"nextComment"),false);} + assert.equal(after["pg:comments"].filter(x=>x.zid===row.zid&&x.tid===row.tid).length,1); + for(const v of votes) { + assert.equal(v.tid,row.tid);assert.equal(v.pid,row.pid); + assert.equal(convention.storageToSemantic(v.vote),convention.wireToSemantic(Number.parseInt(String(spec.body.vote),10))); + assert.equal(v.weight_x_32767,0); assert.equal(v.high_priority,false); + const latest=after["pg:votes_latest_unique"].filter(x=>x.zid===v.zid&&x.tid===v.tid&&x.pid===v.pid); + assert.equal(latest.length,1);assert.equal(latest[0].vote,v.vote);assert.equal(latest[0].modified,v.created); + } + } + } catch(error) { + failures.push({case:spec.name,phase:"assertion",error:String(error)}); + put(out,"failures.json",failures); console.error(JSON.stringify(failures[failures.length - 1])); + } + } + put(out,"failures.json",failures); + if(process.argv[3]){ + const before=JSON.parse(fs.readFileSync(path.join(process.argv[3],"cases.json"))); + assert.equal(before.length,actual.length); + const entries=JSON.parse(fs.readFileSync(path.join(__dirname,"expected-differences.json"))).entries; + const baseline=Object.fromEntries(before.map(r=>[r.case,canonical(comparable(r))])); + const expected=applyExpectedDifferences(baseline,entries); + assert.deepEqual(expected.problems,[]); + const differences=actual.flatMap((r,i)=>{const value=canonical(comparable(r));return expected.expected[r.case]===value?[]:[{case:r.case,difference:firstDifference(before[i],r)}];}); + put(out,"replay.json",{cases:actual.length,differences});assert.deepEqual(differences,[]); + } + const files=[]; + function visit(dir){for(const e of fs.readdirSync(dir,{withFileTypes:true})){const f=path.join(dir,e.name);if(e.isDirectory())visit(f);else files.push(pin(out,path.relative(out,f)));}} + visit(out);put(out,"index.json",{format:"post-comments-recordings/1",source_commit:process.env.P027_SOURCE_COMMIT,files}); + console.log(JSON.stringify({cases:actual.length,failed:failures.length,replay:!!process.argv[3]})); + if(failures.length)process.exitCode=1; +} +main().catch(e=>{console.error(e);process.exitCode=1;}).finally(async()=>{await pool.end();await recorder.close();}); diff --git a/server/characterization/post-comments/ses.cjs b/server/characterization/post-comments/ses.cjs new file mode 100644 index 000000000..6078b5273 --- /dev/null +++ b/server/characterization/post-comments/ses.cjs @@ -0,0 +1,22 @@ +"use strict"; +// Local capture only: no SDK, forwarding, credentials or outbound client. +const http = require("node:http"); +const messages = []; +http.createServer(async (req, res) => { + if (req.method === "GET" && req.url === "/messages") { + res.setHeader("content-type", "application/json"); + return res.end(JSON.stringify(messages)); + } + if (req.method !== "POST" || req.url !== "/v2/email/outbound-emails") { + res.statusCode = 404; return res.end(); + } + const chunks = []; + for await (const chunk of req) chunks.push(chunk); + try { + messages.push(JSON.parse(Buffer.concat(chunks).toString())); + res.setHeader("content-type", "application/json"); + res.end(JSON.stringify({ MessageId: "generated-local-message" })); + } catch { + res.statusCode = 400; res.end("{}"); + } +}).listen(8025, "0.0.0.0"); From 9758c85bec6d1982c3254e4e668530e7f5c65209 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Sat, 24 Oct 2026 09:46:13 -0700 Subject: [PATCH 28/30] polis-api: twelve more typed read routes, each behind its own switch (#3257) * polis-api: typed read routes for /iip and /iim, each behind its own switch Recorded byte for byte against unchanged Node and replayed; the public conversation id is resolved by one indexed lookup per request. Off by default: nothing is served until its switch is named. Co-Authored-By: Claude Opus 5.5 * polis-api: a typed read route for GET /api/v3/participants, behind its own switch Recorded byte for byte against unchanged Node and replayed; the public conversation id is resolved by one indexed lookup per request. Off by default: nothing is served until its switch is named. Co-Authored-By: Claude Opus 5.5 * polis-api: a typed read route for GET /api/v3/ptptois, behind its own switch Recorded byte for byte against unchanged Node and replayed; the public conversation id is resolved by one indexed lookup per request. Off by default: nothing is served until its switch is named. Co-Authored-By: Claude Opus 5.5 * polis-api: a typed read route for GET /api/v3/treevite/myInvites/csv, behind its own switch Recorded byte for byte against unchanged Node and replayed; the public conversation id is resolved by one indexed lookup per request. Off by default: nothing is served until its switch is named. Co-Authored-By: Claude Opus 5.5 * polis-api: typed read routes for GET /api/v3/bid and /api/v3/locations, each behind its own switch Recorded byte for byte against unchanged Node and replayed; the public conversation id is resolved by one indexed lookup per request. Off by default: nothing is served until its switch is named. Co-Authored-By: Claude Opus 5.5 * polis-api: typed routes for the conversation pages (root, explore, share, summary, ot), each behind its own switch Recorded byte for byte against unchanged Node and replayed; the public conversation id is resolved by one indexed lookup per request. Off by default: nothing is served until its switch is named. Co-Authored-By: Claude Opus 5.5 * differential: scenarios and serving assertions for the twelve new read routes Each new selector is inventoried with its serving counts with the switch off and on: the five API routes through the real CLI, the seven HTML routes through GET, HEAD and query hand-back scenarios comparing complete bodies, status and type. Test-only. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- file-server/nginx/render-rust-api.sh | 74 ++- .../nginx/rust-api/bid.location.conf.template | 29 + .../conversationPage.location.conf.template | 29 + .../explorePage.location.conf.template | 29 + .../nginx/rust-api/iim.location.conf.template | 29 + .../nginx/rust-api/iip.location.conf.template | 29 + .../rust-api/locations.location.conf.template | 29 + .../myInvitesCsv.location.conf.template | 29 + .../oneTimePage.location.conf.template | 29 + .../participantsRead.location.conf.template | 29 + .../rust-api/ptptois.location.conf.template | 29 + .../rust-api/sharePage.location.conf.template | 29 + .../summaryPage.location.conf.template | 29 + polis-cli/tests/differential/README.md | 12 + polis-cli/tests/differential/compose.yml | 25 +- polis-cli/tests/differential/harness.py | 2 +- polis-cli/tests/differential/page-static.cjs | 12 + polis-cli/tests/differential/pages.py | 50 ++ polis-cli/tests/differential/routes.json | 110 ++++ polis-cli/tests/differential/run.py | 29 +- polis-cli/tests/differential/test_contract.py | 27 + queue-rs/polis-api/CONVERSATION-PAGES.md | 9 + queue-rs/polis-api/LINK-PAGES.md | 54 ++ queue-rs/polis-api/MATH-MEMBERSHIP.md | 13 + queue-rs/polis-api/MY-INVITES-CSV.md | 11 + queue-rs/polis-api/PARTICIPANTS-READ.md | 11 + queue-rs/polis-api/PTPTOIS.md | 11 + queue-rs/polis-api/README.md | 12 + .../conversation-pages-compose.yml | 35 + .../conformance/conversation-pages-replay.cjs | 160 +++++ .../conformance/conversation-pages-run.sh | 51 ++ .../conformance/conversation-pages-static.cjs | 15 + .../conformance/link-pages-compose.yml | 20 + .../conformance/link-pages-replay.cjs | 181 +++++ .../polis-api/conformance/link-pages-run.sh | 45 ++ .../conformance/math-membership-compose.yml | 25 + .../conformance/math-membership-replay.cjs | 183 ++++++ .../conformance/math-membership-run.sh | 51 ++ .../conformance/my-invites-csv-compose.yml | 27 + .../conformance/my-invites-csv-replay.cjs | 171 +++++ .../conformance/my-invites-csv-run.sh | 51 ++ .../polis-api/conformance/nginx-routing.sh | 156 +++++ .../conformance/participants-read-compose.yml | 23 + .../conformance/participants-read-replay.cjs | 189 ++++++ .../conformance/participants-read-run.sh | 51 ++ .../polis-api/conformance/ptptois-compose.yml | 24 + .../polis-api/conformance/ptptois-replay.cjs | 174 +++++ queue-rs/polis-api/conformance/ptptois-run.sh | 51 ++ queue-rs/polis-api/src/conversation_pages.rs | 616 ++++++++++++++++++ queue-rs/polis-api/src/link_pages.rs | 115 ++++ queue-rs/polis-api/src/link_pages_tests.rs | 118 ++++ queue-rs/polis-api/src/main.rs | 214 ++++++ queue-rs/polis-api/src/math_bundle.rs | 195 ++++++ queue-rs/polis-api/src/math_membership.rs | 194 ++++++ .../polis-api/src/math_membership_tests.rs | 129 ++++ queue-rs/polis-api/src/my_invites_csv.rs | 200 ++++++ .../polis-api/src/my_invites_csv_tests.rs | 102 +++ queue-rs/polis-api/src/participants_read.rs | 128 ++++ .../polis-api/src/participants_read_tests.rs | 96 +++ queue-rs/polis-api/src/ptptois.rs | 150 +++++ queue-rs/polis-api/src/ptptois_tests.rs | 110 ++++ queue-rs/polis-api/src/route.rs | 452 +++++++++++++ .../polis-contracts/src/conversation_pages.rs | 34 + .../src/fixtures/conversation-pages.json | 34 + .../src/fixtures/link-pages.json | 57 ++ .../src/fixtures/math-membership.json | 37 ++ .../src/fixtures/my-invites-csv.json | 14 + .../src/fixtures/participants-read.json | 29 + .../polis-contracts/src/fixtures/ptptois.json | 6 + queue-rs/polis-contracts/src/lib.rs | 6 + queue-rs/polis-contracts/src/link_pages.rs | 85 +++ .../polis-contracts/src/math_membership.rs | 55 ++ .../polis-contracts/src/my_invites_csv.rs | 50 ++ .../polis-contracts/src/participants_read.rs | 41 ++ queue-rs/polis-contracts/src/ptptois.rs | 50 ++ 75 files changed, 5805 insertions(+), 5 deletions(-) create mode 100644 file-server/nginx/rust-api/bid.location.conf.template create mode 100644 file-server/nginx/rust-api/conversationPage.location.conf.template create mode 100644 file-server/nginx/rust-api/explorePage.location.conf.template create mode 100644 file-server/nginx/rust-api/iim.location.conf.template create mode 100644 file-server/nginx/rust-api/iip.location.conf.template create mode 100644 file-server/nginx/rust-api/locations.location.conf.template create mode 100644 file-server/nginx/rust-api/myInvitesCsv.location.conf.template create mode 100644 file-server/nginx/rust-api/oneTimePage.location.conf.template create mode 100644 file-server/nginx/rust-api/participantsRead.location.conf.template create mode 100644 file-server/nginx/rust-api/ptptois.location.conf.template create mode 100644 file-server/nginx/rust-api/sharePage.location.conf.template create mode 100644 file-server/nginx/rust-api/summaryPage.location.conf.template create mode 100644 polis-cli/tests/differential/page-static.cjs create mode 100644 polis-cli/tests/differential/pages.py create mode 100644 queue-rs/polis-api/CONVERSATION-PAGES.md create mode 100644 queue-rs/polis-api/LINK-PAGES.md create mode 100644 queue-rs/polis-api/MATH-MEMBERSHIP.md create mode 100644 queue-rs/polis-api/MY-INVITES-CSV.md create mode 100644 queue-rs/polis-api/PARTICIPANTS-READ.md create mode 100644 queue-rs/polis-api/PTPTOIS.md create mode 100644 queue-rs/polis-api/conformance/conversation-pages-compose.yml create mode 100644 queue-rs/polis-api/conformance/conversation-pages-replay.cjs create mode 100755 queue-rs/polis-api/conformance/conversation-pages-run.sh create mode 100644 queue-rs/polis-api/conformance/conversation-pages-static.cjs create mode 100644 queue-rs/polis-api/conformance/link-pages-compose.yml create mode 100644 queue-rs/polis-api/conformance/link-pages-replay.cjs create mode 100755 queue-rs/polis-api/conformance/link-pages-run.sh create mode 100644 queue-rs/polis-api/conformance/math-membership-compose.yml create mode 100644 queue-rs/polis-api/conformance/math-membership-replay.cjs create mode 100755 queue-rs/polis-api/conformance/math-membership-run.sh create mode 100644 queue-rs/polis-api/conformance/my-invites-csv-compose.yml create mode 100644 queue-rs/polis-api/conformance/my-invites-csv-replay.cjs create mode 100755 queue-rs/polis-api/conformance/my-invites-csv-run.sh create mode 100644 queue-rs/polis-api/conformance/participants-read-compose.yml create mode 100644 queue-rs/polis-api/conformance/participants-read-replay.cjs create mode 100755 queue-rs/polis-api/conformance/participants-read-run.sh create mode 100644 queue-rs/polis-api/conformance/ptptois-compose.yml create mode 100644 queue-rs/polis-api/conformance/ptptois-replay.cjs create mode 100755 queue-rs/polis-api/conformance/ptptois-run.sh create mode 100644 queue-rs/polis-api/src/conversation_pages.rs create mode 100644 queue-rs/polis-api/src/link_pages.rs create mode 100644 queue-rs/polis-api/src/link_pages_tests.rs create mode 100644 queue-rs/polis-api/src/math_bundle.rs create mode 100644 queue-rs/polis-api/src/math_membership.rs create mode 100644 queue-rs/polis-api/src/math_membership_tests.rs create mode 100644 queue-rs/polis-api/src/my_invites_csv.rs create mode 100644 queue-rs/polis-api/src/my_invites_csv_tests.rs create mode 100644 queue-rs/polis-api/src/participants_read.rs create mode 100644 queue-rs/polis-api/src/participants_read_tests.rs create mode 100644 queue-rs/polis-api/src/ptptois.rs create mode 100644 queue-rs/polis-api/src/ptptois_tests.rs create mode 100644 queue-rs/polis-contracts/src/conversation_pages.rs create mode 100644 queue-rs/polis-contracts/src/fixtures/conversation-pages.json create mode 100644 queue-rs/polis-contracts/src/fixtures/link-pages.json create mode 100644 queue-rs/polis-contracts/src/fixtures/math-membership.json create mode 100644 queue-rs/polis-contracts/src/fixtures/my-invites-csv.json create mode 100644 queue-rs/polis-contracts/src/fixtures/participants-read.json create mode 100644 queue-rs/polis-contracts/src/fixtures/ptptois.json create mode 100644 queue-rs/polis-contracts/src/link_pages.rs create mode 100644 queue-rs/polis-contracts/src/math_membership.rs create mode 100644 queue-rs/polis-contracts/src/my_invites_csv.rs create mode 100644 queue-rs/polis-contracts/src/participants_read.rs create mode 100644 queue-rs/polis-contracts/src/ptptois.rs diff --git a/file-server/nginx/render-rust-api.sh b/file-server/nginx/render-rust-api.sh index 144e14ba8..28479e160 100644 --- a/file-server/nginx/render-rust-api.sh +++ b/file-server/nginx/render-rust-api.sh @@ -72,6 +72,78 @@ for route in $(echo "${RUST_API_ROUTES:-}" | tr ',' ' '); do " rust_api_locations="${rust_api_locations} metadataAnswers" ;; + conversationPage) + case " $rust_api_locations " in *" conversationPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/[0-9][0-9A-Za-z]+ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} conversationPage" + ;; + explorePage) + case " $rust_api_locations " in *" explorePage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/explore/[0-9][0-9A-Za-z]+ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} explorePage" + ;; + sharePage) + case " $rust_api_locations " in *" sharePage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/share/[0-9][0-9A-Za-z]+ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} sharePage" + ;; + summaryPage) + case " $rust_api_locations " in *" summaryPage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/summary/[0-9][0-9A-Za-z]+ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} summaryPage" + ;; + oneTimePage) + case " $rust_api_locations " in *" oneTimePage "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/ot/[0-9][0-9A-Za-z]+ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} oneTimePage" + ;; + iip) + case " $rust_api_locations " in *" iip "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/iip/[^/]+/?$ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} iip" + ;; + iim) + case " $rust_api_locations " in *" iim "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} ~^/iim/[^/]+/?$ ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} iim" + ;; + participantsRead) + case " $rust_api_locations " in *" participantsRead "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/participants ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} participantsRead" + ;; + ptptois) + case " $rust_api_locations " in *" ptptois "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/ptptois ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} ptptois" + ;; + myInvitesCsv) + case " $rust_api_locations " in *" myInvitesCsv "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/treevite/myInvites/csv ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} myInvitesCsv" + ;; + bid) + case " $rust_api_locations " in *" bid "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/bid ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} bid" + ;; + locations) + case " $rust_api_locations " in *" locations "*) continue ;; esac + RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/locations ${RUST_API_UPSTREAM}; +" + rust_api_locations="${rust_api_locations} locations" + ;; votesRead) case " $rust_api_locations " in *" votesRead "*) continue ;; esac RUST_API_MAP_ENTRIES="${RUST_API_MAP_ENTRIES} /api/v3/votes ${RUST_API_UPSTREAM}; @@ -350,7 +422,7 @@ for route in $(echo "${RUST_API_ROUTES:-}" | tr ',' ' '); do done export RUST_API_RESOLVER=${RUST_API_RESOLVER:-127.0.0.11} if [ -n "$rust_api_unknown" ]; then - echo "ERROR RUST_API_ROUTES: unknown route(s):${rust_api_unknown} (known: pca2 owner-conversations comments nextComment testConnection testDatabase contexts domainWhitelist metadataQuestions metadataAnswers votesRead metadataRead metadataChoices recentStarted recentActivity legacyPca treeviteWaves treeviteInvites treeviteCsv conversationPreload participationRead allConversations reportsRead bidToPid conversationStats statementImportance topicSelections treeviteMyInvites treeviteMe topicPrioritize xidReport opsCatchall opsPage opsWhoami collectiveStatement topicStats delphiLogs delphiRun delphiResult delphiVisualizations delphiReports delphiRead otherConversationsPage integratePage adminPage userLogoutPage settingsPage userLoginPage userCreatePage createPage einvitesRead legacyConversations robots about). Selection rejected." >&2 + echo "ERROR RUST_API_ROUTES: unknown route(s):${rust_api_unknown} (known: pca2 owner-conversations comments nextComment testConnection testDatabase contexts domainWhitelist metadataQuestions metadataAnswers conversationPage explorePage sharePage summaryPage oneTimePage iip iim locations bid myInvitesCsv participantsRead ptptois votesRead metadataRead metadataChoices recentStarted recentActivity legacyPca treeviteWaves treeviteInvites treeviteCsv conversationPreload participationRead allConversations reportsRead bidToPid conversationStats statementImportance topicSelections treeviteMyInvites treeviteMe topicPrioritize xidReport opsCatchall opsPage opsWhoami collectiveStatement topicStats delphiLogs delphiRun delphiResult delphiVisualizations delphiReports delphiRead otherConversationsPage integratePage adminPage userLogoutPage settingsPage userLoginPage userCreatePage createPage einvitesRead legacyConversations robots about). Selection rejected." >&2 exit 1 elif [ -n "$RUST_API_MAP_ENTRIES" ] && ! echo "$RUST_API_UPSTREAM" | grep -Eqx '[A-Za-z0-9._-]+:[0-9]{1,5}'; then diff --git a/file-server/nginx/rust-api/bid.location.conf.template b/file-server/nginx/rust-api/bid.location.conf.template new file mode 100644 index 000000000..cdce31cec --- /dev/null +++ b/file-server/nginx/rust-api/bid.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /api/v3/bid without a body go to polis-api +# (RUST_API_ROUTES contains bid); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location = /api/v3/bid { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/conversationPage.location.conf.template b/file-server/nginx/rust-api/conversationPage.location.conf.template new file mode 100644 index 000000000..ac4700ba3 --- /dev/null +++ b/file-server/nginx/rust-api/conversationPage.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD / without a body go to polis-api +# (RUST_API_ROUTES contains conversationPage); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location ~ ^/[0-9][0-9A-Za-z]+ { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/explorePage.location.conf.template b/file-server/nginx/rust-api/explorePage.location.conf.template new file mode 100644 index 000000000..604a5a7b3 --- /dev/null +++ b/file-server/nginx/rust-api/explorePage.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /explore/ without a body go to polis-api +# (RUST_API_ROUTES contains explorePage); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location ~ ^/explore/[0-9][0-9A-Za-z]+ { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/iim.location.conf.template b/file-server/nginx/rust-api/iim.location.conf.template new file mode 100644 index 000000000..ce44db093 --- /dev/null +++ b/file-server/nginx/rust-api/iim.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /iim/ without a body go to polis-api +# (RUST_API_ROUTES contains iim); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location ~ ^/iim/[^/]+/?$ { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/iip.location.conf.template b/file-server/nginx/rust-api/iip.location.conf.template new file mode 100644 index 000000000..ced02e8dc --- /dev/null +++ b/file-server/nginx/rust-api/iip.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /iip/ without a body go to polis-api +# (RUST_API_ROUTES contains iip); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location ~ ^/iip/[^/]+/?$ { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/locations.location.conf.template b/file-server/nginx/rust-api/locations.location.conf.template new file mode 100644 index 000000000..1dbd721b3 --- /dev/null +++ b/file-server/nginx/rust-api/locations.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /api/v3/locations without a body go to polis-api +# (RUST_API_ROUTES contains locations); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location = /api/v3/locations { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/myInvitesCsv.location.conf.template b/file-server/nginx/rust-api/myInvitesCsv.location.conf.template new file mode 100644 index 000000000..4be0172d8 --- /dev/null +++ b/file-server/nginx/rust-api/myInvitesCsv.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /api/v3/treevite/myInvites/csv without a body go to polis-api +# (RUST_API_ROUTES contains myInvitesCsv); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location = /api/v3/treevite/myInvites/csv { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/oneTimePage.location.conf.template b/file-server/nginx/rust-api/oneTimePage.location.conf.template new file mode 100644 index 000000000..fd9a7a2e2 --- /dev/null +++ b/file-server/nginx/rust-api/oneTimePage.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /ot/ without a body go to polis-api +# (RUST_API_ROUTES contains oneTimePage); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location ~ ^/ot/[0-9][0-9A-Za-z]+ { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/participantsRead.location.conf.template b/file-server/nginx/rust-api/participantsRead.location.conf.template new file mode 100644 index 000000000..ac8211f89 --- /dev/null +++ b/file-server/nginx/rust-api/participantsRead.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /api/v3/participants without a body go to polis-api +# (RUST_API_ROUTES contains participantsRead); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location = /api/v3/participants { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/ptptois.location.conf.template b/file-server/nginx/rust-api/ptptois.location.conf.template new file mode 100644 index 000000000..657d3b448 --- /dev/null +++ b/file-server/nginx/rust-api/ptptois.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /api/v3/ptptois without a body go to polis-api +# (RUST_API_ROUTES contains ptptois); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location = /api/v3/ptptois { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/sharePage.location.conf.template b/file-server/nginx/rust-api/sharePage.location.conf.template new file mode 100644 index 000000000..163b13c62 --- /dev/null +++ b/file-server/nginx/rust-api/sharePage.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /share/ without a body go to polis-api +# (RUST_API_ROUTES contains sharePage); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location ~ ^/share/[0-9][0-9A-Za-z]+ { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/file-server/nginx/rust-api/summaryPage.location.conf.template b/file-server/nginx/rust-api/summaryPage.location.conf.template new file mode 100644 index 000000000..22f156f71 --- /dev/null +++ b/file-server/nginx/rust-api/summaryPage.location.conf.template @@ -0,0 +1,29 @@ +# GET and HEAD /summary/ without a body go to polis-api +# (RUST_API_ROUTES contains summaryPage); any other request on this path goes +# straight to Node (418 here is only an internal hand-over, never sent). +# +# Node also answers when polis-api gives no response: no such host, refused, +# slower than the timeouts below before sending its status line, or its own +# 502 (database unreachable, or a request it does not model). This fallback +# covers failures BEFORE polis-api starts its response. Once its status line +# and headers have gone to the client (buffering is off), nginx cannot switch +# to Node: a response cut short after that reaches the client as a truncated +# reply (shorter than its Content-Length, or a chunked body without its end), +# which an HTTP client reports as a failed request. polis-api's own 500 +# answers are passed through as Node would send them. +location ~ ^/summary/[0-9][0-9A-Za-z]+ { + error_page 418 = @polis_node_api; + if ($polis_api_plain = 0) { + return 418; + } + proxy_pass http://$polis_api_target; + proxy_intercept_errors on; + error_page 502 503 504 = @polis_node_api; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_connect_timeout 100ms; + proxy_send_timeout 100ms; + proxy_read_timeout 100ms; + proxy_buffering off; + proxy_request_buffering off; +} diff --git a/polis-cli/tests/differential/README.md b/polis-cli/tests/differential/README.md index 0c3786a8f..d39a5efed 100644 --- a/polis-cli/tests/differential/README.md +++ b/polis-cli/tests/differential/README.md @@ -99,6 +99,18 @@ checks each path independently as well as the selector total. `votesRead` exercises `vote list` and `vote mine` with empty and single-row results served from Rust, then requires a Node handoff for each multi-row read. Vote POSTs remain Node requests and count separately from the read successes. +The current-participant, social-profile, bucket, location and participant-owned +CSV selectors exercise the corresponding CLI reads, including missing membership, +filtered profiles, owner bucket and absent-group cases. Their process switches +and independent read pools are enabled only in the generated Compose fixture. +Seven HTML selectors have supplemental HTTP scenarios because the CLI accepts +API paths only: GET and HEAD must serve from Rust, while a query parameter must +hand back to Node. Each case requires HTTP 200 and HTML, and compares status, +content type and full body bytes between phases. These are reported separately +under `pages`, without response values; complete header/wire equivalence remains +the separate byte gate. A fixed participation-page static service runs only on +its own port, preserving unrelated missing-static scenarios. Every route's exact +request count is also checked with switches off, with no Rust contact allowed. Each entry requires an exact request count, a minimum number of sole Rust HTTP200 responses, and an exact count of scoped Node handoffs with a reason. These counts cover this generated fixture only. Unexercised routes explicitly diff --git a/polis-cli/tests/differential/compose.yml b/polis-cli/tests/differential/compose.yml index 78c6f4453..a68c6cbfd 100644 --- a/polis-cli/tests/differential/compose.yml +++ b/polis-cli/tests/differential/compose.yml @@ -15,8 +15,11 @@ services: P027_MARKERS: '0' ADMIN_UIDS: '[2]' CLI_DIFFERENTIAL_FIXTURE: '1' + STATIC_FILES_PARTICIPATION_PORT: "8081" file-server: - profiles: [unused] + image: ${CLI_DIFF_NODE_IMAGE:?build the local Node image} + command: [node, /differential/page-static.cjs] + volumes: [../../polis-cli/tests/differential:/differential:ro] driver: profiles: [unused] polis-api: @@ -30,6 +33,26 @@ services: AUTH_ISSUER: https://oidc-simulator:3000/ AUTH_AUDIENCE: users POLIS_API_PARTICIPANT_READS: "1" + POLIS_API_PARTICIPANTS_READS: "1" + POLIS_API_PTPTOIS_READS: "1" + POLIS_API_BID_READS: "1" + POLIS_API_LOCATIONS_READS: "1" + POLIS_API_MY_INVITES_CSV_READS: "1" + POLIS_API_IIP_READS: "1" + POLIS_API_IIM_READS: "1" + POLIS_API_CONVERSATION_PAGE_READS: "1" + POLIS_API_EXPLORE_PAGE_READS: "1" + POLIS_API_SHARE_PAGE_READS: "1" + POLIS_API_SUMMARY_PAGE_READS: "1" + POLIS_API_ONE_TIME_PAGE_READS: "1" + POLIS_API_PARTICIPANTS_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_PTPTOIS_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_BID_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_LOCATIONS_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_MY_INVITES_CSV_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_LINK_PAGES_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_CONVERSATION_PAGES_DATABASE_URL: postgres://postgres@postgres:5432/p027 + STATIC_FILES_PARTICIPATION_PORT: "8081" POLIS_API_VOTES_READS: "1" POLIS_API_VOTES_READ_DATABASE_URL: postgres://postgres@postgres:5432/p027 POLIS_API_PARTICIPANT_PUBLIC_KEY_FILE: /artifacts/participant-public.pem diff --git a/polis-cli/tests/differential/harness.py b/polis-cli/tests/differential/harness.py index 0aa452227..42e62fd9c 100644 --- a/polis-cli/tests/differential/harness.py +++ b/polis-cli/tests/differential/harness.py @@ -167,7 +167,7 @@ def publish_keys(self): def up(self): """Start every service; return the control port's generated tokens.""" - self.dc('up','-d','--pull','never','postgres','dynamodb','oidc-simulator','server') + self.dc('up','-d','--pull','never','postgres','dynamodb','oidc-simulator','server','file-server') self.publish_keys() self.dc('up','-d','--pull','never','polis-api','proxy','gateway') self.ready();self.tokens=self.get('/tokens') diff --git a/polis-cli/tests/differential/page-static.cjs b/polis-cli/tests/differential/page-static.cjs new file mode 100644 index 000000000..21fd2caa0 --- /dev/null +++ b/polis-cli/tests/differential/page-static.cjs @@ -0,0 +1,12 @@ +'use strict'; +// Only the participation static port is present; unrelated missing static +// routes retain their existing transport-failure scenarios. +const http = require('node:http'); +const body = '' + + '' + + '

Generated conversation page

'; +http.createServer((req, res) => { + if (req.url !== '/index.html') { req.socket.destroy(); return; } + res.writeHead(200, {'Content-Type':'text/html', 'Content-Length':Buffer.byteLength(body)}); + res.end(req.method === 'HEAD' ? undefined : body); +}).listen(8081, '0.0.0.0'); diff --git a/polis-cli/tests/differential/pages.py b/polis-cli/tests/differential/pages.py new file mode 100644 index 000000000..e6a7c53ae --- /dev/null +++ b/polis-cli/tests/differential/pages.py @@ -0,0 +1,50 @@ +"""Supplemental HTML reads through the same proxy and generated fixture. + +The CLI only accepts API paths. These page requests compare full body bytes, +status and content type without redirects; the separate wire gate owns the +complete HTTP envelope. No response values enter the structured report. +""" +import http.client +from urllib.parse import urlsplit + +CID = '2p027generated' +PAGES = {'iip': '/iip/', 'iim': '/iim/', 'conversationPage': '/', + 'explorePage': '/explore/', 'sharePage': '/share/', + 'summaryPage': '/summary/', 'oneTimePage': '/ot/'} + + +def capture_pages(origin): + url = urlsplit(origin) + if url.scheme != 'http' or url.hostname != '127.0.0.1': + raise RuntimeError('page scenarios require the local gateway') + values = {} + for route, prefix in PAGES.items(): + for method, suffix, kind in [('GET', '', 'get'), ('HEAD', '', 'head'), + ('GET', '?generated=1', 'handoff')]: + name = route + ':' + kind + connection = http.client.HTTPConnection(url.hostname, url.port, timeout=5) + try: + connection.request(method, prefix + CID + suffix, + headers={'Accept-Encoding': 'identity'}) + response = connection.getresponse() + body = response.read(65537) + content_type = response.getheader('Content-Type', '') + if (response.status != 200 or not content_type.startswith('text/html') + or len(body) > 65536 or (method == 'GET' and not body) + or (method == 'HEAD' and body)): + raise RuntimeError('page response contract failed: ' + name) + values[name] = {'status': response.status, 'content_type': content_type, + 'body': body} + finally: + connection.close() + return values + + +def compare_pages(node, rust): + expected = {route + ':' + kind for route in PAGES for kind in ['get', 'head', 'handoff']} + if set(node) != expected or set(rust) != expected: + raise RuntimeError('page scenario census changed') + return [{'scenario': name, 'equal': node[name] == rust[name], + 'different_fields': [key for key in ['status', 'content_type', 'body'] + if node[name][key] != rust[name][key]]} + for name in sorted(expected)] diff --git a/polis-cli/tests/differential/routes.json b/polis-cli/tests/differential/routes.json index 30047acce..24d5f4467 100644 --- a/polis-cli/tests/differential/routes.json +++ b/polis-cli/tests/differential/routes.json @@ -478,5 +478,115 @@ "delphi logs" ], "scope": "The shared differential uses DynamoDB job fixtures, so this Postgres-only route remains disabled and the request hands back to Node. Dedicated Postgres conformance proves archived and native authorized logs and counts every Rust-served case." + }, + "participantsRead": { + "path": "/api/v3/participants", + "minimum_rust_successes": 3, + "expected_requests": 3, + "expected_node_handoffs": 0, + "commands": [ + "participant list", + "participant status", + "participant status missing" + ], + "scope": "Existing owner membership and missing membership both serve from Rust." + }, + "ptptois": { + "path": "/api/v3/ptptois", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 0, + "commands": [ + "participant highlight list", + "participant highlight list filtered", + "participant highlight set" + ], + "scope": "Empty social rows with and without a moderation filter serve from Rust; the moderation PUT stays on Node." + }, + "bid": { + "path": "/api/v3/bid", + "minimum_rust_successes": 2, + "expected_requests": 2, + "expected_node_handoffs": 0, + "commands": [ + "participant group", + "participant group owner" + ], + "scope": "Participant and owner reads preserve the missing-bundle null bucket." + }, + "locations": { + "path": "/api/v3/locations", + "minimum_rust_successes": 2, + "expected_requests": 2, + "expected_node_handoffs": 0, + "commands": [ + "participant locations", + "participant locations missing group" + ], + "scope": "Empty location arrays for the generated group and an absent group serve from Rust." + }, + "myInvitesCsv": { + "path": "/api/v3/treevite/myInvites/csv", + "minimum_rust_successes": 1, + "expected_requests": 2, + "expected_node_handoffs": 1, + "commands": ["invite mine export empty", "invite mine export"], + "scope": "Before another conversation code is created, the participant's empty CSV serves from Rust. The later download hands to Node because multiple reverse codes are ambiguous. Both file hashes must match across phases." + }, + "iip": { + "path": "^/iip/", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 1, + "commands": [], + "scope": "Supplemental page requests compare status, content type and full body bytes for GET, HEAD and an unsupported-query Node handoff. These are HTTP scenarios, not CLI commands." + }, + "iim": { + "path": "^/iim/", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 1, + "commands": [], + "scope": "Supplemental page requests compare status, content type and full body bytes for GET, HEAD and an unsupported-query Node handoff. These are HTTP scenarios, not CLI commands." + }, + "conversationPage": { + "path": "^/[0-9][0-9A-Za-z]+", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 1, + "commands": [], + "scope": "Supplemental page requests compare status, content type and full body bytes for GET, HEAD and an unsupported-query Node handoff. These are HTTP scenarios, not CLI commands." + }, + "explorePage": { + "path": "^/explore/", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 1, + "commands": [], + "scope": "Supplemental page requests compare status, content type and full body bytes for GET, HEAD and an unsupported-query Node handoff. These are HTTP scenarios, not CLI commands." + }, + "sharePage": { + "path": "^/share/", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 1, + "commands": [], + "scope": "Supplemental page requests compare status, content type and full body bytes for GET, HEAD and an unsupported-query Node handoff. These are HTTP scenarios, not CLI commands." + }, + "summaryPage": { + "path": "^/summary/", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 1, + "commands": [], + "scope": "Supplemental page requests compare status, content type and full body bytes for GET, HEAD and an unsupported-query Node handoff. These are HTTP scenarios, not CLI commands." + }, + "oneTimePage": { + "path": "^/ot/", + "minimum_rust_successes": 2, + "expected_requests": 3, + "expected_node_handoffs": 1, + "commands": [], + "scope": "Supplemental page requests compare status, content type and full body bytes for GET, HEAD and an unsupported-query Node handoff. These are HTTP scenarios, not CLI commands." } } diff --git a/polis-cli/tests/differential/run.py b/polis-cli/tests/differential/run.py index 194e71a51..37bfefd10 100644 --- a/polis-cli/tests/differential/run.py +++ b/polis-cli/tests/differential/run.py @@ -18,6 +18,7 @@ from harness import (HERE, RUST_ONLY, Cli, Stack, differences, load_routes, route_lines, # noqa: F401 route_contracts, routing_counts, run_phases, rust_only_checks, serving_matches) from cases import cases +from pages import capture_pages, compare_pages def census(schema): @@ -76,6 +77,24 @@ def main(): actor='owner' if command=='vote list' or state=='empty' else 'participant', participant_pid=command=='vote list', vote_rows={'empty':0,'single':1,'multiple':2}[state]) for command in commands] + # Additional reads keep the existing command census intact. + index = next(i for i, row in enumerate(rows) if row['command'] == 'vote') + rows[index:index] = [ + dict(command=command, scenario=scenario, args=args, + expected_exit=0, scope='live', actor='owner') + for command, scenario, args in [ + ('participant status', 'participant status missing', ['participant','status','--conversation','2generatedjoin']), + ('participant highlight list', 'participant highlight list filtered', ['participant','highlight','list','--conversation','2p027generated','--mod','1']), + ('api', 'participant group owner', ['api','/api/v3/bid?conversation_id=2p027generated']), + ('participant locations', 'participant locations missing group', ['participant','locations','--conversation','2p027generated','--group','99']), + ]] + # A second invitation code makes reverse lookup ambiguous. Prove + # the admitted CSV first, then retain the later Node handoff. + rows.insert(next(i for i, row in enumerate(rows) if row['command'] == 'invite code create'), + dict(command='invite mine export', scenario='invite mine export empty', + args=['invite','mine','export','--conversation','2p027generated','--output','mine-empty.csv'], + expected_exit=0, scope='live', actor='participant')) + page_values = {} rows += [dict(command=name,args=name.split(),expected_exit=8,scope='planned',actor='owner') for name,implemented in sorted(nodes.items()) if not implemented] captured={} for phase in run_phases(stack,cli,[('node',''),('rust',','.join(sorted(routes)))]): @@ -96,6 +115,7 @@ def main(): 'activity':'open','listing':'listed','join':{'invitations':{'mode':'optional','waves':[]},'external_identity':{'mode':'optional'}}, 'moderation':'after_submission','visibility':'hide_social_list','data_access':'owner', 'profanity_filter':False,'short_url':False,'seeds':['Generated setup statement']})) + page_values[phase] = capture_pages(stack.origin) phase_start=time.monotonic();phase_values=[];timings=[] for index,row in enumerate(rows): if row['scope']=='planned':continue @@ -169,7 +189,10 @@ def main(): served=counts['rust_200'];fallback=counts['rust_fallbacks'] report[phase+'_routing'][route]=counts if phase=='rust' and not serving_matches(counts, contract):serving_failures.append(route) - if phase=='node' and served:raise RuntimeError('off switch still served Rust: '+route) + if phase=='node' and any(':5100' in line for line in matched_lines): + raise RuntimeError('off switch still reached Rust: '+route) + if phase=='node' and counts['requests'] != contract['expected_requests']: + raise RuntimeError('off switch request count failed: '+route) if serving_failures:report['serving_failures']=serving_failures for row,a,b in zip(rows,captured['node'],captured['rust']): if row['scope']=='rust-only': @@ -178,6 +201,8 @@ def main(): continue diff=differences(a,b) report['rows'].append({'command':row['command'],'scenario':row.get('scenario',row['command']),'scope':row['scope'],'node_exit':a['exit'],'rust_exit':b['exit'],'equal':not diff,'different_paths':diff,'node_error':(a['json'].get('error') or {}).get('code'),'node_status':((a['json'].get('error') or {}).get('upstream') or {}).get('status'),'rust_status':((b['json'].get('error') or {}).get('upstream') or {}).get('status'),'rust_error':(b['json'].get('error') or {}).get('code')}) + report['pages'] = compare_pages(page_values['node'], page_values['rust']) + report['page_mismatches'] = sum(not row['equal'] for row in report['pages']) report['scenarios']=len(rows);report['commands']=len(nodes);report['implemented']=sum(nodes.values()) report['planned']=sum(not v for v in nodes.values()) report['rust_only_failures']=sum(not row['passed'] for row in report['rust_only']) @@ -194,6 +219,6 @@ def main(): output.parent.mkdir(parents=True,exist_ok=True) output.write_text(json.dumps(report,indent=2)+'\n') print(json.dumps({k:v for k,v in report.items() if k not in ['rows','rust_only']},indent=2)) - return 0 if report['complete'] and not report['mismatches'] and not report.get('rust_only_failures') and not report.get('unexpected_outcomes') and report['cleanup_passed'] and not report.get('serving_failures') else 1 + return 0 if report['complete'] and not report['mismatches'] and not report.get('page_mismatches') and not report.get('rust_only_failures') and not report.get('unexpected_outcomes') and report['cleanup_passed'] and not report.get('serving_failures') else 1 if __name__=='__main__':sys.exit(main()) diff --git a/polis-cli/tests/differential/test_contract.py b/polis-cli/tests/differential/test_contract.py index 2af31710d..f949bec69 100644 --- a/polis-cli/tests/differential/test_contract.py +++ b/polis-cli/tests/differential/test_contract.py @@ -80,6 +80,33 @@ def test_rust_only_requires_the_exact_clean_refusal(self): def test_unknown_rust_only_contract_cannot_bypass_comparison(self): with self.assertRaises(KeyError):rust_only_checks({'contract':'unknown'}, {}, {}) +class PageComparisonTests(unittest.TestCase): + def fixture(self): + from pages import PAGES + return {route + ':' + kind: {'status':200, 'content_type':'text/html', + 'body':b'' if kind == 'head' else b'

Generated

'} + for route in PAGES for kind in ['get', 'head', 'handoff']} + + def test_page_body_status_and_type_changes_fail(self): + import copy + from pages import compare_pages + node = self.fixture() + self.assertTrue(all(row['equal'] for row in compare_pages(node, node))) + for field, value in [('body', b'

Changed

'), ('status', 302), + ('content_type', 'application/json')]: + rust = copy.deepcopy(node) + rust['iip:get'][field] = value + failed = [row for row in compare_pages(node, rust) if not row['equal']] + self.assertEqual(failed, [{'scenario':'iip:get', 'equal':False, + 'different_fields':[field]}]) + + def test_missing_page_case_cannot_pass(self): + from pages import compare_pages + node, rust = self.fixture(), self.fixture() + del rust['summaryPage:handoff'] + with self.assertRaises(RuntimeError): + compare_pages(node, rust) + if __name__=='__main__':unittest.main() diff --git a/queue-rs/polis-api/CONVERSATION-PAGES.md b/queue-rs/polis-api/CONVERSATION-PAGES.md new file mode 100644 index 000000000..6373bfffd --- /dev/null +++ b/queue-rs/polis-api/CONVERSATION-PAGES.md @@ -0,0 +1,9 @@ +# Conversation HTML pages + +Observable changes: none while off. + +The numeric conversation root and `/explore/`, `/share/`, `/summary/`, `/ot/` prefixes have independent default-off switches `POLIS_API_CONVERSATION_PAGE_READS`, `POLIS_API_EXPLORE_PAGE_READS`, `POLIS_API_SHARE_PAGE_READS`, `POLIS_API_SUMMARY_PAGE_READS`, `POLIS_API_ONE_TIME_PAGE_READS` (set each to1) and nginx selectors `conversationPage`, `explorePage`, `sharePage`, `summaryPage`, `oneTimePage`. Configure `POLIS_API_CONVERSATION_PAGES_DATABASE_URL`, `STATIC_FILES_HOST`, `STATIC_FILES_PARTICIPATION_PORT` (or STATIC_FILES_PORT). Reads prefer READ_ONLY_DATABASE_URL. Each route has its own size-one read-only DB pool and four static transport slots. + +Every request directly resolves the extracted public ID. GET/HEAD ASCII paths with source-compatible digit-first ID prefix and optional suffix are admitted. Query, cookie, authorization, unknown headers, compression and body inputs hand back. Preload projection, nulls, bigint strings, browser redirects, HTML entities and the two case-insensitive literal stream replacements preserve current Node behavior. DB strings total at most8KiB; preload16KiB; static body16KiB; transformed output64KiB. Uncertain upstream status/encoding/length, fragmented or non-ASCII bodies, unsupported browsers or resource pressure hand back. + +DB work has15ms acquire/50ms statement/75ms stage deadline. The DB lease is returned before the independent75ms static deadline; no participation writer pool is used. Static DNS resolves at startup only. No new locks, migrations, participant creation, Node changes or rollout. Tests exercise independent switches, bounded transport, blocked reads and whole unchanged-Node HTTP bytes. The JS-to-TS review found no semantic conversion slip; later HTML escaping and build-selection removal are preserved as current behavior. diff --git a/queue-rs/polis-api/LINK-PAGES.md b/queue-rs/polis-api/LINK-PAGES.md new file mode 100644 index 000000000..3e671e6ae --- /dev/null +++ b/queue-rs/polis-api/LINK-PAGES.md @@ -0,0 +1,54 @@ +# Conversation link pages + +Observable changes: none while the switches are off (the default). + +`GET /iip/:conversation_id` returns a participation anchor. `GET +/iim/:conversation_id` returns the same anchor with the conversation's topic +(or its creation timestamp), a moderation anchor and an optional description. +The contract follows `server/app.ts` and +`server/src/routes/conversations.ts` on the recorded source. HEAD, ETag +freshness, CORS and compression use the existing Express-compatible envelope. + +Each route has an independent nginx selector (`iip`, `iim`) and process switch +(`POLIS_API_IIP_READS=1`, `POLIS_API_IIM_READS=1`). Both default off. The common +`POLIS_API_LINK_PAGES_DATABASE_URL` configures their independent read-only +pools; no write pool is used. Choosing a selector does not enable the handler. +The nginx method/body gate sends writes directly to Node. Unavailable Rust, +resource pressure and unsupported requests return to Node before any response +is started. After headers have reached the client, a truncated response cannot +be retried by nginx. + +Admitted requests have one ASCII alphanumeric path ID (1–100 bytes), an optional +trailing slash, no query parameters, no credentials and no body. The ID is +resolved with an indexed `zinvites.zinvite` lookup on every request. Missing IDs, +unsupported encodings, cookies, authorization, parameter variants and database +errors stay with Node. The moderation route admits exactly one conversation, +and at most 16 KiB of combined topic/description data. It preserves bigint +creation timestamps as decimal strings. + +The source sends topic and description markup verbatim and constructs the +moderation URL with `m` immediately followed by the ID. These behaviors predate +the JavaScript-to-TypeScript conversion (the 2021 conversion) and remain unchanged here. +The conversion added types and formatting on these handlers and their parameter +and conversation helpers; no semantic conversion slip was found. + +Known cache difference: Node has process-local conversation-ID caches. Rust +performs a direct lookup. A warm reverse cache may retain the previous code +when an owner adds one. These pages use the path's supplied ID without a reverse +lookup, so that difference does not alter their successful link output. + +Participation isolation: each enabled page has one read-only connection, a +15 ms pool acquisition deadline, a 50 ms statement deadline and a 75 ms request +deadline. No transaction or row lock is acquired. Cancellation retains the pool +slot until the blocking database operation actually finishes. No database +connection is held across network or model work. The real-database test parks a +moderation read behind a table lock and verifies an independent participation +pool continues to answer; the shared pool's cancellation tests remain in force. + +`conformance/link-pages-run.sh` records complete HTTP bytes against unchanged +Node, compares admitted Rust responses without normalization, checks explicit +Node handbacks and replays every case against a process with both switches off. +A Date-only rollover causes a fresh capture, never a masked comparison. +`conformance/nginx-routing.sh` checks both independent selectors, default-off, +method/body boundaries and the pre-response fallback. The contracts crate +shares the page request/HTML response types with the route. diff --git a/queue-rs/polis-api/MATH-MEMBERSHIP.md b/queue-rs/polis-api/MATH-MEMBERSHIP.md new file mode 100644 index 000000000..057eb7154 --- /dev/null +++ b/queue-rs/polis-api/MATH-MEMBERSHIP.md @@ -0,0 +1,13 @@ +# Bucket membership and group locations + +Observable changes: none while off. + +GET/HEAD `/api/v3/bid` and `/api/v3/locations` have independent default-off process switches `POLIS_API_BID_READS=1` and `POLIS_API_LOCATIONS_READS=1`, DSNs `POLIS_API_BID_DATABASE_URL` and `POLIS_API_LOCATIONS_DATABASE_URL`, and nginx selectors `bid` and `locations`. Reads prefer READ_ONLY_DATABASE_URL. Each has independent size-one read-only identity/data pools,15ms acquire/50ms statement/75ms request limits. Every request resolves its supplied public ID directly; there is no ID cache. No DB lease crosses external work; no writer pool, new lock or migration is used. + +A bounded, shared three-second cache retains a whole coherent math generation by environment and numeric conversation. One SQL snapshot joins main, mapping, participant stats and tick, each with matching generation. The current Node implementation loads bundles on demand; it has no active prefetch timer. Missing/incoherent generations preserve the source's empty responses and tick checks; malformed/oversized data, stale bid requests and unsupported inputs hand back. Main/mapping JSON is bounded at64KiB each. Typed mapping preserves unplaced buckets, missing labels (-1), first PID mapping, final duplicate bucket index and numeric group index. + +Bid requires verified scoped participant/OIDC identity and existing membership; locations accepts optional identity. XID/cookie/creation paths remain on Node. Locations preserve JS number rendering and source row shape. With no final source ordering, at most one matching location is admitted; multiple matching rows hand back. PID lists are capped at16384. Distinct switches and pools preserve participation under resource pressure. Raw recordings compare whole unchanged-Node HTTP bytes across ticks, cache expiry, identity and admission boundaries; DB tests verify cache behavior, readonly enforcement and independent service during a stalled read. + +The cache is local to this process and shared by these two Rust routes. Node participation/report callers can warm its separate cache; concurrent publications can therefore yield different generations within the three-second window, as documented for the existing Rust math routes. The recordings prove controlled cold/warm/expiry behavior, not equivalence under every cross-process publication schedule. + +The JS-to-TS comparison found no semantic conversion slip. Current coherent-bundle and default-tick behavior are later changes and are preserved. No Node/schema change or rollout is included. diff --git a/queue-rs/polis-api/MY-INVITES-CSV.md b/queue-rs/polis-api/MY-INVITES-CSV.md new file mode 100644 index 000000000..9d18e4c96 --- /dev/null +++ b/queue-rs/polis-api/MY-INVITES-CSV.md @@ -0,0 +1,11 @@ +# Participant-owned invitation CSV + +Observable changes: none while off. + +GET/HEAD `/api/v3/treevite/myInvites/csv` has its own default-off `POLIS_API_MY_INVITES_CSV_READS=1` process switch and nginx `RUST_API_ROUTES=myInvitesCsv` selector. Configure `POLIS_API_MY_INVITES_CSV_DATABASE_URL`; reads prefer READ_ONLY_DATABASE_URL. Independent size-one read-only auth/data pools have15ms acquire/50ms statement/75ms request limits. No connection crosses external work, no participation writer pool or new lock/schema is used. + +Existing verified participant and OIDC users only; XID/cookie/creation paths, unsupported inputs or resource failures hand back. Every request resolves its supplied capability directly. A single canonical reverse row supplies the filename; ambiguity hands back. The known warm reverse-cache difference after an owner adds a code is retained as a limitation of direct lookup. No participant or invite is created or updated. + +A missing participant receives the source's header plus newline; an existing participant with no active invites receives the header without a newline. Populated downloads admit at most200 active, participant-owned invites ordered by id,64KiB output, and explicit TZ=UTC or Etc/UTC. Dates outside1970–9999 or other timezone environments hand back; empty downloads are timezone-independent. Nullable dates stay empty; comma/quote/newline CSV escaping, Unicode, the unquoted carriage-return case and the millisecond ISO filename are preserved. + +The route originated in TypeScript after the server conversion. No pre-conversion JS handler exists; its origin and current helper path were checked. The raw recorder compares complete unchanged-Node HTTP bytes and all-off responses; no header/body normalization. DB tests cover membership, dates, escaping, readonly enforcement and independent service during a stalled CSV read. No rollout, Node or schema change is included. diff --git a/queue-rs/polis-api/PARTICIPANTS-READ.md b/queue-rs/polis-api/PARTICIPANTS-READ.md new file mode 100644 index 000000000..69753f17c --- /dev/null +++ b/queue-rs/polis-api/PARTICIPANTS-READ.md @@ -0,0 +1,11 @@ +# Current participant row + +Observable changes: none while off. + +`POLIS_API_PARTICIPANTS_READS=1` and nginx `RUST_API_ROUTES=participantsRead` independently opt into GET/HEAD `/api/v3/participants`. Both default off. The database variable is `POLIS_API_PARTICIPANTS_DATABASE_URL`; reads prefer `READ_ONLY_DATABASE_URL` when present. The public conversation ID is resolved by an indexed lookup on every request. There is no process-local ID cache. The known warm reverse-cache difference after an owner adds a code does not affect this response: it retains the numeric internal ID and never reverse-resolves it. + +A mandatory verified participant or OIDC identity and one conversation_id query are admitted. XID, cookies, malformed identities, ambiguous rows/schema, extra query arguments, body, unsupported methods, missing IDs and resource failures hand back to Node before a response. Missing membership returns JSON null. A single row preserves SQL column order, nullable values and bigint strings. The history COUNT overrides the stored vote_count in its original property position. No reverse-ID or field cleanup is applied. + +Separate size-one read-only authentication and data pools use 15ms acquisition and 50ms statement limits, inside a 75ms overall deadline. No participation writer slots, new locks, schema or Node edits. No database connection crosses external I/O. A blocked read sheds itself while an independent pool answers. + +`conformance/participants-read-run.sh` records unchanged Node and compares entire HTTP bytes with Rust. Date-only rollover causes recapture, never normalization. All cases also exercise a process with this switch off. The fixture exercises anonymous/standard participant and OIDC identities, pid zero/nonzero, empty/history counts, HEAD, CORS and unsupported boundaries. Historical JavaScript and conversion TypeScript retain the same registration and first-row-or-null behavior; current hybrid authentication and vote-history projection are subsequent changes, preserved here. diff --git a/queue-rs/polis-api/PTPTOIS.md b/queue-rs/polis-api/PTPTOIS.md new file mode 100644 index 000000000..75f7b61fa --- /dev/null +++ b/queue-rs/polis-api/PTPTOIS.md @@ -0,0 +1,11 @@ +# Social participant rows + +Observable changes: none while off. + +GET/HEAD `/api/v3/ptptois` has independent default-off `POLIS_API_PTPTOIS_READS=1` and nginx `RUST_API_ROUTES=ptptois` selectors. Configure `POLIS_API_PTPTOIS_DATABASE_URL`; data reads prefer `READ_ONLY_DATABASE_URL`, authentication uses its own pool. Both pools are read-only,size one,15ms acquire/50ms statements; requests have75ms overall bounds. Nothing shares a participation writer pool or holds a connection across external work. + +The public ID is resolved directly each request with no cache. The response appends that supplied ID, so the known warm reverse-cache difference after an owner adds a code does not affect this route. Optional verified participant/OIDC authentication is scoped to the requested conversation. XID, cookie, malformed or unsupported identities hand back. `mod` admits canonical integers; extra/duplicate query fields, bodies and unsupported methods hand back. + +The source permits owner, configured ADMIN_UIDS developer, or open-data access. Others receive[]. Optional moderation filtering, the source's99999 participant limit and profile-not-null/XID-not-null join are retained. At most99999 matching participants and one visible social row are admitted because the source has no final order. Oversized strings or multiple visible rows hand back to Node. Top-level nulls disappear; nested xInfo.x_name may remain null. Empty XID/profile strings retain the source's flat shape. Stored markup and Unicode stay intact. + +`conformance/ptptois-run.sh` compares unchanged Node and Rust whole HTTP bytes, including HEAD, all auth classes, visibility, moderation, empty/flat/nested/null/multiple rows and all-off cases. Date-only rollovers recapture rather than normalize. DB tests cover permissions, nesting, nulls, read-only enforcement and independent service during a blocked social read. No Node/schema change or rollout is included. diff --git a/queue-rs/polis-api/README.md b/queue-rs/polis-api/README.md index 24e3dc523..8f56f458b 100644 --- a/queue-rs/polis-api/README.md +++ b/queue-rs/polis-api/README.md @@ -1478,3 +1478,15 @@ It requires unique compose/port settings and the three local fixture images. The staged [vote read routes](VOTES-READ.md) cover latest/history responses under `votesRead`, off by default. The route note names the identity quirks, bounded read pools, exact response subset and Node hand-back conditions. + +Conversation link pages (`/iip/:conversation_id`, `/iim/:conversation_id`) have independent default-off switches and read-only pools. See [LINK-PAGES.md](LINK-PAGES.md) for the contract, admission limits and replay. + +Current participant rows: [contract and admission](PARTICIPANTS-READ.md). + +Social participant rows: [contract and admission](PTPTOIS.md). + +Participant invitation CSV: [contract and admission](MY-INVITES-CSV.md). + +Bucket membership and group locations: [contract and admission](MATH-MEMBERSHIP.md). + +Conversation HTML pages: [contract and bounded admission](CONVERSATION-PAGES.md). diff --git a/queue-rs/polis-api/conformance/conversation-pages-compose.yml b/queue-rs/polis-api/conformance/conversation-pages-compose.yml new file mode 100644 index 000000000..1177f9d54 --- /dev/null +++ b/queue-rs/polis-api/conformance/conversation-pages-compose.yml @@ -0,0 +1,35 @@ +# Test-only opt-in; production defaults stay off. +services: + polis-api: + environment: + POLIS_API_CONVERSATION_PAGE_READS: "1" + POLIS_API_EXPLORE_PAGE_READS: "1" + POLIS_API_SHARE_PAGE_READS: "1" + POLIS_API_SUMMARY_PAGE_READS: "1" + POLIS_API_ONE_TIME_PAGE_READS: "1" + POLIS_API_CONVERSATION_PAGES_DATABASE_URL: postgres://postgres@postgres:5432/p027 + STATIC_FILES_HOST: file-server + STATIC_FILES_PARTICIPATION_PORT: "8080" + polis-api-off: + image: ${X54_POLIS_API_IMAGE:-x54pca2-polis-api:conformance} + networks: [sealed] + environment: + MATH_ENV: p027 + DEV_MODE: "true" + NODE_ENV: production + DOMAIN_OVERRIDE: localhost + DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + POLIS_API_LISTEN: 0.0.0.0:5100 + POLIS_API_FIXTURE_CLOCK: "1700000000000" + server: + environment: + STATIC_FILES_HOST: file-server + STATIC_FILES_PARTICIPATION_PORT: "8080" + file-server: + image: ${P027_SERVER_IMAGE:-polis-server:conformance} + entrypoint: [node, /conformance/conversation-pages-static.cjs] + networks: [sealed] + volumes: + - ../../queue-rs/polis-api/conformance:/conformance:ro diff --git a/queue-rs/polis-api/conformance/conversation-pages-replay.cjs b/queue-rs/polis-api/conformance/conversation-pages-replay.cjs new file mode 100644 index 000000000..55b2eae8e --- /dev/null +++ b/queue-rs/polis-api/conformance/conversation-pages-replay.cjs @@ -0,0 +1,160 @@ +"use strict"; +// Raw HTTP fixture proof; no response normalization. Node source and fixture +// writers are unchanged. Boundary handoffs are counted separately. +const fs = require("node:fs"); +const net = require("node:net"); +const zlib = require("node:zlib"); + +const NODE = { host: "server", port: 5000 }; +const RUST = { host: "polis-api", port: 5100 }; + + +function exchange(target, bytes, headOnly) { + return new Promise((resolve, reject) => { + const socket = net.connect(target.port, target.host); + const chunks = []; + let done = false; + const timer = setTimeout(() => finish(new Error("response deadline")), 10000); + function finish(err, value) { + if (done) return; + done = true; + clearTimeout(timer); + socket.destroy(); + if (err) reject(err); + else resolve(value); + } + socket.on("connect", () => socket.write(bytes)); + socket.on("data", (b) => { + chunks.push(b); + const all = Buffer.concat(chunks); + const end = complete(all, headOnly); + if (end !== null) finish(null, all.subarray(0, end)); + }); + socket.on("end", () => finish(null, Buffer.concat(chunks))); + socket.on("error", (e) => finish(e)); + }); +} + +// Offset just past one complete response in `buf`, or null if more is needed. +function complete(buf, headOnly) { + const headEnd = buf.indexOf("\r\n\r\n"); + if (headEnd < 0) return null; + const head = buf.subarray(0, headEnd).toString("latin1"); + const status = Number(head.split(" ")[1]); + const header = (name) => { + const line = head + .split("\r\n") + .slice(1) + .find((l) => l.toLowerCase().startsWith(name + ":")); + return line === undefined ? undefined : line.slice(name.length + 1).trim(); + }; + let at = headEnd + 4; + if (headOnly || status === 204 || status === 304 || (status >= 100 && status < 200)) return at; + if ((header("transfer-encoding") || "").toLowerCase() === "chunked") { + for (;;) { + const lineEnd = buf.indexOf("\r\n", at); + if (lineEnd < 0) return null; + const size = parseInt(buf.subarray(at, lineEnd).toString("latin1"), 16); + at = lineEnd + 2 + size + 2; + if (at > buf.length) return null; + if (size === 0) return at; + } + } + const length = header("content-length"); + if (length !== undefined) { + const end = at + Number(length); + return end <= buf.length ? end : null; + } + return null; // delimited by close +} + +function requestBytes(method, target, headers, body) { + let text = `${method} ${target} HTTP/1.1\r\n`; + for (const [name, value] of headers) text += `${name}: ${value}\r\n`; + return Buffer.concat([Buffer.from(text + "\r\n", "latin1"), body]); +} + +const dateLine = /\r\nDate: [^\r]*\r\n/; +function sameButDate(a, b) { + const ma = a.toString("latin1").match(dateLine); + const mb = b.toString("latin1").match(dateLine); + if (!ma || !mb || ma[0] === mb[0]) return false; + return a.toString("latin1").replace(dateLine, "\r\n") === b.toString("latin1").replace(dateLine, "\r\n"); +} + +function firstDifference(a, b) { + const n = Math.min(a.length, b.length); + let i = 0; + while (i < n && a[i] === b[i]) i++; + return i; +} + +function show(buf) { + const head = buf.subarray(0, Math.max(0, buf.indexOf("\r\n\r\n"))).toString("latin1"); + return { head: head.split("\r\n"), bodyBytes: buf.length - head.length - 4 }; +} + + +let dateRetries=0; +const records=[]; +async function reset(seed,id) { + const r=await fetch(`http://server:5001/begin?seed=${seed}&case=${encodeURIComponent(id)}`); + if (!r.ok) throw Error("entropy reset failed"); +} +async function compare(c) { + const bytes=requestBytes(c.method||"GET",c.target,c.headers,c.body||Buffer.alloc(0)); + for(let attempt=0;attempt<5;attempt++) { + await reset(c.seed,c.id); + const node=await exchange(NODE,bytes,c.method==="HEAD"); + const rust=await exchange(RUST,bytes,c.method==="HEAD"); + const fallback=rust.toString("latin1",0,16).startsWith("HTTP/1.1 502"); + const status=Number(node.toString("latin1").split(" ")[1]); + const unexpectedFallback=!!c.served&&(fallback||status!==(c.status||200)); + if(!fallback&&!node.equals(rust)&&sameButDate(node,rust)){dateRetries++;continue;} + const equal=node.equals(rust); + records.push({id:c.id,method:c.method||"GET",target:c.target,seed:c.seed,expectedServed:c.served,node:node.toString("base64"),rust:rust.toString("base64"),fallback,equal,unexpectedFallback}); + return {id:c.id,fallback,equal,unexpectedFallback,...(!fallback&&!equal?{node:node.toString(),rust:rust.toString()}:{}),...(!c.served&&!fallback?{unexpectedServe:true}:{})}; + } + throw Error(`${c.id}: Date differed five times`); +} +async function main(){ + const {fixtures}=require("/app/characterization/comments-cases.cjs");const f=fixtures.find(f=>f.shape==="content-edges"); + const {Pool}=require("/app/node_modules/pg");const pool=new Pool({connectionString:process.env.DATABASE_URL}); + if(new URL(process.env.DATABASE_URL).pathname!=="/p027")throw Error("disposable fixture database required"); + const prefixes=["/","/explore/","/share/","/summary/","/ot/"];const cases=[],results=[]; + async function run(id,prefix,served=true,method="GET",extra=[],suffix="",status=200,body=""){ + const c={id,seed:"7ac001000001",method,target:prefix+f.capability+suffix,served,status, + headers:[["Host","localhost"],["Connection","close"],...extra],body:Buffer.from(body)};cases.push(c);results.push(await compare(c)); + } + const control=async(mode)=>{const r=await fetch(`http://file-server:8080/control?mode=${mode}`);if(!r.ok)throw Error("static fixture control failed");}; + try{ + for(const shape of ["plain","markup","null","unicode"]){ + const topic=shape==="plain"?"Generated topic":shape==="markup"?'Quote " & apostrophe\'':shape==="null"?null:"Generated 🙂"; + const description=shape==="null"?null:shape==="markup"?"First line\nSecond & line":"Generated description"; + await pool.query("UPDATE conversations SET topic=$2,description=$3,created=9223372036854775807 WHERE zid=$1",[f.zid,topic,description]); + for(const prefix of prefixes){ + for(const method of ["GET","HEAD"])await run(`${shape}/${prefix}/${method}`,prefix,shape!=="unicode",method); + await run(`${shape}/${prefix}/suffix`,prefix,shape!=="unicode","GET",[],"/extra"); + for(const ua of ["MSIE 8.0","MSIE 9.0"])await run(`${shape}/${prefix}/${ua}`,prefix,shape!=="unicode","GET",[["User-Agent",ua]],"",302); + } + } + await pool.query("UPDATE conversations SET topic='Generated topic',description='Generated description' WHERE zid=$1",[f.zid]); + for(const mode of ["multiple","large","unicode","slow"]){ + await control(mode); + for(const prefix of prefixes)for(const method of ["GET","HEAD"])await run(`static/${mode}/${prefix}/${method}`,prefix,mode==="multiple"||(mode==="unicode"&&method==="HEAD"),method); + } + await control("normal"); + for(const prefix of prefixes){ + for(const method of ["POST","OPTIONS"])await run(`boundary/${prefix}/${method}`,prefix,false,method); + for(const ua of ["MSIE 7.0","MSIE 8.0 MSIE 6.0"])await run(`boundary/${prefix}/${ua}`,prefix,false,"GET",[["User-Agent",ua]]); + for(const header of [["Cookie","x=y"],["Authorization","Bearer malformed"],["Accept-Encoding","gzip"],["Origin","https://example.invalid"]])await run(`boundary/${prefix}/${header[0]}`,prefix,false,"GET",[header]); + await run(`boundary/${prefix}/query`,prefix,false,"GET",[],"?extra=1"); + await run(`boundary/${prefix}/body`,prefix,false,"GET",[["Content-Length","2"]],"",200,"{}"); + } + let off=0;for(const c of cases){const response=await exchange({host:"polis-api-off",port:5100},requestBytes(c.method,c.target,c.headers,c.body),c.method==="HEAD");if(!response.toString("latin1").startsWith("HTTP/1.1 502"))throw Error(`off switch served ${c.id}`);off++;} + const failed=results.filter(r=>r.unexpectedFallback||r.unexpectedServe||(!r.fallback&&!r.equal)); + fs.writeFileSync("/artifacts/conversation-pages-recordings.json",JSON.stringify({records},null,2)+"\n"); + console.log(JSON.stringify({cases:cases.length,exact:results.filter(r=>r.equal).length,handbacks:results.filter(r=>r.fallback).length,off,dateRetries,failed},null,2));if(failed.length)process.exitCode=1; + }finally{await pool.end();} +} +main().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/queue-rs/polis-api/conformance/conversation-pages-run.sh b/queue-rs/polis-api/conformance/conversation-pages-run.sh new file mode 100755 index 000000000..3743939e4 --- /dev/null +++ b/queue-rs/polis-api/conformance/conversation-pages-run.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Record social participant rows under anonymous, participant and OIDC auth and +# compare complete Node/Rust HTTP bytes. Uses only the isolated generated stack. +# Usage: conversation-pages-run.sh [result.json], with unique project and P027 ports. +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:-/dev/stdout} +here="$root/server/characterization" +# Require an explicitly named disposable project and three distinct loopback ports. +python3 - <<'CHECK' +import os,re +project=os.environ.get("COMPOSE_PROJECT_NAME", "") +assert re.fullmatch(r"[a-z][a-z0-9_-]{5,63}",project), "unique project required" +ports=[int(os.environ[k]) for k in ["POLIS_RECOVERY_PG_PORT","P027_HTTP_PORT","P027_CONTROL_PORT"]] +assert len(set(ports))==3 and all(55432<=p<=65535 for p in ports) +CHECK +export P027_POSTGRES_IMAGE=${P027_POSTGRES_IMAGE:-x54pca2-postgres:local} +compose=(docker compose -f "$here/compose.yml" -f "$root/queue-rs/polis-api/conformance/compose.yml" -f "$root/queue-rs/polis-api/conformance/participant-compose.yml" -f "$root/queue-rs/polis-api/conformance/conversation-pages-compose.yml") +if [[ -n $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]]; then + echo "project $COMPOSE_PROJECT_NAME already has containers" >&2 + exit 1 +fi +cleanup() { "${compose[@]}" logs --no-color server polis-api file-server >"${out%.json}-services.log" 2>&1 || true; "${compose[@]}" --profile seed down -v --remove-orphans >/dev/null 2>&1 || true; } +trap cleanup EXIT INT TERM +ready() { + for _ in $(seq 60); do + if "${compose[@]}" exec -T server node -e "fetch('http://localhost:5001/ready',{signal:AbortSignal.timeout(3000)}).then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))" >/dev/null 2>&1; then + return 0 + fi + sleep 1 + done + echo "Node readiness deadline" >&2 + return 1 +} +"${compose[@]}" up -d --pull never postgres dynamodb oidc-simulator server driver file-server +"${compose[@]}" restart server +ready +"${compose[@]}" exec -T driver node characterization/cli.cjs seed +"${compose[@]}" exec -T driver node /conformance/votes-read-seed.cjs +"${compose[@]}" exec -T driver node characterization/cli.cjs seed-comments +# Fresh caches on both sides before the first replayed request. +"${compose[@]}" restart server dynamodb +ready +"${compose[@]}" exec -T driver node -e 'fetch("http://server:5001/public-key").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/participant-public.pem",v.publicKey))' +"${compose[@]}" exec -T driver node -e 'fetch("https://oidc-simulator:3000/.well-known/jwks.json").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/read-jwks.json",JSON.stringify(v)))' +"${compose[@]}" up -d --pull never polis-api polis-api-off +for _ in $(seq 60); do + if "${compose[@]}" exec -T driver node -e 'fetch("http://polis-api:5100/health").then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))'; then break; fi + sleep 1 +done +"${compose[@]}" exec -T driver node /conformance/conversation-pages-replay.cjs >"$out" diff --git a/queue-rs/polis-api/conformance/conversation-pages-static.cjs b/queue-rs/polis-api/conformance/conversation-pages-static.cjs new file mode 100644 index 000000000..a46e94f0c --- /dev/null +++ b/queue-rs/polis-api/conformance/conversation-pages-static.cjs @@ -0,0 +1,15 @@ +"use strict"; +// Fixed, generated static service for the sealed raw-response proof only. +const http=require("node:http"); +let mode="normal"; +const html=''+"a".repeat(100)+''; +http.createServer((req,res)=>{ + if(req.url.startsWith("/control?mode=")){mode=new URL(req.url,"http://fixture").searchParams.get("mode");res.end("ok");return;} + let body=req.url==="/index.html"?html:req.url==="/unsupportedBrowser.html"?"Unsupported generated browser":"Missing generated conversation"; + if(mode==="multiple")body=html+html.toLowerCase(); + if(mode==="large")body="a".repeat(20000); + if(mode==="unicode")body=html+"🙂"; + if(mode==="error"){res.writeHead(404,{"Content-Length":0});res.end();return;} + const send=()=>{res.writeHead(200,{"Content-Type":"text/html","Content-Length":Buffer.byteLength(body)});res.end(req.method==="HEAD"?undefined:body);}; + if(mode==="slow")setTimeout(send,150);else send(); +}).listen(8080,"0.0.0.0"); diff --git a/queue-rs/polis-api/conformance/link-pages-compose.yml b/queue-rs/polis-api/conformance/link-pages-compose.yml new file mode 100644 index 000000000..03c2c72b3 --- /dev/null +++ b/queue-rs/polis-api/conformance/link-pages-compose.yml @@ -0,0 +1,20 @@ +# Both page switches enabled only inside this generated fixture stack. +services: + polis-api: + environment: + POLIS_API_IIP_READS: "1" + POLIS_API_IIM_READS: "1" + POLIS_API_LINK_PAGES_DATABASE_URL: postgres://postgres@postgres:5432/p027 + polis-api-off: + image: ${X54_POLIS_API_IMAGE:-x54pca2-polis-api:conformance} + networks: [sealed] + environment: + MATH_ENV: p027 + DEV_MODE: "true" + NODE_ENV: production + DOMAIN_OVERRIDE: localhost + DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + POLIS_API_LISTEN: 0.0.0.0:5100 + POLIS_API_FIXTURE_CLOCK: "1700000000000" diff --git a/queue-rs/polis-api/conformance/link-pages-replay.cjs b/queue-rs/polis-api/conformance/link-pages-replay.cjs new file mode 100644 index 000000000..9867febb3 --- /dev/null +++ b/queue-rs/polis-api/conformance/link-pages-replay.cjs @@ -0,0 +1,181 @@ +"use strict"; +// Raw HTTP fixture proof; no response normalization. Node source and fixture +// writers are unchanged. Boundary handoffs are counted separately. +const fs = require("node:fs"); +const net = require("node:net"); +const zlib = require("node:zlib"); + +const NODE = { host: "server", port: 5000 }; +const RUST = { host: "polis-api", port: 5100 }; + + +function exchange(target, bytes, headOnly) { + return new Promise((resolve, reject) => { + const socket = net.connect(target.port, target.host); + const chunks = []; + let done = false; + const timer = setTimeout(() => finish(new Error("response deadline")), 10000); + function finish(err, value) { + if (done) return; + done = true; + clearTimeout(timer); + socket.destroy(); + if (err) reject(err); + else resolve(value); + } + socket.on("connect", () => socket.write(bytes)); + socket.on("data", (b) => { + chunks.push(b); + const all = Buffer.concat(chunks); + const end = complete(all, headOnly); + if (end !== null) finish(null, all.subarray(0, end)); + }); + socket.on("end", () => finish(null, Buffer.concat(chunks))); + socket.on("error", (e) => finish(e)); + }); +} + +// Offset just past one complete response in `buf`, or null if more is needed. +function complete(buf, headOnly) { + const headEnd = buf.indexOf("\r\n\r\n"); + if (headEnd < 0) return null; + const head = buf.subarray(0, headEnd).toString("latin1"); + const status = Number(head.split(" ")[1]); + const header = (name) => { + const line = head + .split("\r\n") + .slice(1) + .find((l) => l.toLowerCase().startsWith(name + ":")); + return line === undefined ? undefined : line.slice(name.length + 1).trim(); + }; + let at = headEnd + 4; + if (headOnly || status === 204 || status === 304 || (status >= 100 && status < 200)) return at; + if ((header("transfer-encoding") || "").toLowerCase() === "chunked") { + for (;;) { + const lineEnd = buf.indexOf("\r\n", at); + if (lineEnd < 0) return null; + const size = parseInt(buf.subarray(at, lineEnd).toString("latin1"), 16); + at = lineEnd + 2 + size + 2; + if (at > buf.length) return null; + if (size === 0) return at; + } + } + const length = header("content-length"); + if (length !== undefined) { + const end = at + Number(length); + return end <= buf.length ? end : null; + } + return null; // delimited by close +} + +function requestBytes(method, target, headers, body) { + let text = `${method} ${target} HTTP/1.1\r\n`; + for (const [name, value] of headers) text += `${name}: ${value}\r\n`; + return Buffer.concat([Buffer.from(text + "\r\n", "latin1"), body]); +} + +const dateLine = /\r\nDate: [^\r]*\r\n/; +function sameButDate(a, b) { + const ma = a.toString("latin1").match(dateLine); + const mb = b.toString("latin1").match(dateLine); + if (!ma || !mb || ma[0] === mb[0]) return false; + return a.toString("latin1").replace(dateLine, "\r\n") === b.toString("latin1").replace(dateLine, "\r\n"); +} + +function firstDifference(a, b) { + const n = Math.min(a.length, b.length); + let i = 0; + while (i < n && a[i] === b[i]) i++; + return i; +} + +function show(buf) { + const head = buf.subarray(0, Math.max(0, buf.indexOf("\r\n\r\n"))).toString("latin1"); + return { head: head.split("\r\n"), bodyBytes: buf.length - head.length - 4 }; +} + + +let dateRetries=0; +const records=[]; +async function reset(seed,id) { + const r=await fetch(`http://server:5001/begin?seed=${seed}&case=${encodeURIComponent(id)}`); + if (!r.ok) throw Error("entropy reset failed"); +} +async function compare(c) { + const bytes=requestBytes(c.method||"GET",c.target,c.headers,c.body||Buffer.alloc(0)); + for(let attempt=0;attempt<5;attempt++) { + await reset(c.seed,c.id); + const node=await exchange(NODE,bytes,c.method==="HEAD"); + const rust=await exchange(RUST,bytes,c.method==="HEAD"); + const fallback=rust.toString("latin1",0,16).startsWith("HTTP/1.1 502"); + const status=Number(node.toString("latin1").split(" ")[1]); + const unexpectedFallback=!!c.served&&(fallback||status!==(c.status||200)); + if(!fallback&&!node.equals(rust)&&sameButDate(node,rust)){dateRetries++;continue;} + const equal=node.equals(rust); + records.push({id:c.id,method:c.method||"GET",target:c.target,seed:c.seed,expectedServed:c.served,node:node.toString("base64"),rust:rust.toString("base64"),fallback,equal,unexpectedFallback}); + return {id:c.id,fallback,equal,unexpectedFallback,...(!fallback&&!equal?{node:node.toString(),rust:rust.toString()}:{}),...(!c.served&&!fallback?{unexpectedServe:true}:{})}; + } + throw Error(`${c.id}: Date differed five times`); +} +async function main() { + const { Pool } = require("/app/node_modules/pg"); + const pool = new Pool({connectionString:process.env.DATABASE_URL}); + if(new URL(process.env.DATABASE_URL).pathname!=="/p027") throw Error("disposable fixture database required"); + const cases=[], results=[]; + const ids=["4linkplain","4linkempty","4linkmarkup","4linklarge","4linknull","4linkbigint"]; + try { + await pool.query("INSERT INTO users(uid,hname,email,site_id,created) VALUES(280001,'Generated link owner','links@example.invalid','generated-link-site',1700000000000)"); + for (let i=0;iTopic & 🙂","Large description",null,""][i]; + const description=["Generated description",null,"raw markup","x".repeat(16385),"",null][i]; + await pool.query("INSERT INTO conversations(zid,owner,topic,description,created,modified) VALUES($1,280001,$2,$3,$4,1700000000000)",[280001+i,topic,description,i===4?null:i===5?"9223372036854775807":"1700000000000"]); + await pool.query("INSERT INTO zinvites(zid,zinvite) VALUES($1,$2)",[280001+i,ids[i]]); + } + function add(id,target,served=true,method="GET",extra=[],body="",status=200) { + cases.push({id,seed:"7ac001000001",target,served,method,status,headers:[["Host","localhost"],["Connection","close"],...extra],body:Buffer.from(body)}); + } + for(const route of ["iip","iim"]) { + for(const cid of ids) { + const served=route==="iip"||cid!=="4linklarge"; + const path=`/${route}/${cid}`; + add(`${route}/${cid}`,path,served); + add(`${route}/${cid}/head`,path,served,"HEAD"); + add(`${route}/${cid}/slash`,path+"/",served); + add(`${route}/${cid}/origin`,path,served,"GET",[["Origin","https://example.invalid"]]); + add(`${route}/${cid}/gzip`,path,served,"GET",[["Accept-Encoding","gzip"]]); + } + const path=`/${route}/4linkplain`; + for(const suffix of ["?conversation_id=4linkempty","?other=1","/extra","%20","%2Fmore"]) add(`${route}/boundary/${suffix}`,path+suffix,false); + add(`${route}/missing`,`/${route}/4linkmissing`,false); + for(const method of ["POST","OPTIONS"]) add(`${route}/${method}`,path,false,method); + add(`${route}/body`,path,false,"GET",[["Content-Length","2"]],"{}"); + add(`${route}/cookie`,path,false,"GET",[["Cookie","x=y"]]); + add(`${route}/authorization`,path,false,"GET",[["Authorization","Bearer malformed"]]); + // ETag is acquired from unchanged Node, then both responses are compared. + const first=await exchange(NODE,requestBytes("GET",path,[["Host","localhost"],["Connection","close"]],Buffer.alloc(0)),false); + const etag=first.toString("latin1").match(/\r\nETag: ([^\r]+)/i)[1]; + add(`${route}/fresh`,path,true,"GET",[["If-None-Match",etag]],"",304); + } + for(const c of cases) { + const compressed=c.id==="iim/4linkmarkup/gzip"; + if(compressed) await pool.query("UPDATE conversations SET description=$1 WHERE zid=280003",["compressible text ".repeat(128)]); + results.push(await compare(c)); + if(compressed) { + const wire=Buffer.from(records[records.length-1].node,"base64").toString("latin1"); + if(!/\r\nContent-Encoding: gzip\r\n/i.test(wire))throw Error("compression case did not produce gzip"); + await pool.query("UPDATE conversations SET description=$1 WHERE zid=280003",["raw markup"]); + } + } + let off=0; + for(const c of cases) { + const r=await exchange({host:"polis-api-off",port:5100},requestBytes(c.method,c.target,c.headers,c.body),c.method==="HEAD"); + if(!r.toString("latin1").startsWith("HTTP/1.1 502"))throw Error(`off switch served ${c.id}`); + off++; + } + const failed=results.filter(r=>r.unexpectedFallback||r.unexpectedServe||(!r.fallback&&!r.equal)); + fs.writeFileSync("/artifacts/link-pages-recordings.json",JSON.stringify({records},null,2)+"\n"); + console.log(JSON.stringify({cases:cases.length,exact:results.filter(r=>r.equal).length,handbacks:results.filter(r=>r.fallback).length,off,dateRetries,failed},null,2)); + if(failed.length)process.exitCode=1; + } finally { await pool.end(); } +} +main().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/queue-rs/polis-api/conformance/link-pages-run.sh b/queue-rs/polis-api/conformance/link-pages-run.sh new file mode 100755 index 000000000..a35d6d36d --- /dev/null +++ b/queue-rs/polis-api/conformance/link-pages-run.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Record conversation link pages and +# compare complete Node/Rust HTTP bytes. Uses only the isolated generated stack. +# Usage: link-pages-run.sh [result.json], with unique project and P027 ports. +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:-/dev/stdout} +here="$root/server/characterization" +# Require an explicitly named disposable project and three distinct loopback ports. +python3 - <<'CHECK' +import os,re +project=os.environ.get("COMPOSE_PROJECT_NAME", "") +assert re.fullmatch(r"[a-z][a-z0-9_-]{5,63}",project), "unique project required" +ports=[int(os.environ[k]) for k in ["POLIS_RECOVERY_PG_PORT","P027_HTTP_PORT","P027_CONTROL_PORT"]] +assert len(set(ports))==3 and all(55432<=p<=65535 for p in ports) +CHECK +export P027_POSTGRES_IMAGE=${P027_POSTGRES_IMAGE:-x54pca2-postgres:local} +compose=(docker compose -f "$here/compose.yml" -f "$root/queue-rs/polis-api/conformance/compose.yml" -f "$root/queue-rs/polis-api/conformance/link-pages-compose.yml") +if [[ -n $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]]; then + echo "project $COMPOSE_PROJECT_NAME already has containers" >&2 + exit 1 +fi +cleanup() { "${compose[@]}" logs --no-color server polis-api >"${out%.json}-services.log" 2>&1 || true; "${compose[@]}" --profile seed down -v --remove-orphans >/dev/null 2>&1 || true; } +trap cleanup EXIT INT TERM +ready() { + for _ in $(seq 60); do + if "${compose[@]}" exec -T server node -e "fetch('http://localhost:5001/ready',{signal:AbortSignal.timeout(3000)}).then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))" >/dev/null 2>&1; then + return 0 + fi + sleep 1 + done + echo "Node readiness deadline" >&2 + return 1 +} +"${compose[@]}" up -d --pull never postgres dynamodb oidc-simulator server driver +"${compose[@]}" restart server +ready +"${compose[@]}" up -d --pull never polis-api polis-api-off +for service in polis-api polis-api-off; do + for _ in $(seq 60); do + if "${compose[@]}" exec -T driver node -e "fetch('http://$service:5100/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"; then break; fi + sleep 1 + done +done +"${compose[@]}" exec -T driver node /conformance/link-pages-replay.cjs >"$out" diff --git a/queue-rs/polis-api/conformance/math-membership-compose.yml b/queue-rs/polis-api/conformance/math-membership-compose.yml new file mode 100644 index 000000000..6ad1d8ba0 --- /dev/null +++ b/queue-rs/polis-api/conformance/math-membership-compose.yml @@ -0,0 +1,25 @@ +# Test-only opt-in; production defaults stay off. +services: + polis-api: + environment: + POLIS_API_BID_READS: "1" + POLIS_API_LOCATIONS_READS: "1" + POLIS_API_BID_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_LOCATIONS_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_READ_JWKS_FILE: /artifacts/read-jwks.json + AUTH_ISSUER: https://oidc-simulator:3000/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ + polis-api-off: + image: ${X54_POLIS_API_IMAGE:-x54pca2-polis-api:conformance} + networks: [sealed] + environment: + MATH_ENV: p027 + DEV_MODE: "true" + NODE_ENV: production + DOMAIN_OVERRIDE: localhost + DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + POLIS_API_LISTEN: 0.0.0.0:5100 + POLIS_API_FIXTURE_CLOCK: "1700000000000" diff --git a/queue-rs/polis-api/conformance/math-membership-replay.cjs b/queue-rs/polis-api/conformance/math-membership-replay.cjs new file mode 100644 index 000000000..f21ecc391 --- /dev/null +++ b/queue-rs/polis-api/conformance/math-membership-replay.cjs @@ -0,0 +1,183 @@ +"use strict"; +// Raw HTTP fixture proof; no response normalization. Node source and fixture +// writers are unchanged. Boundary handoffs are counted separately. +const fs = require("node:fs"); +const net = require("node:net"); +const zlib = require("node:zlib"); + +const NODE = { host: "server", port: 5000 }; +const RUST = { host: "polis-api", port: 5100 }; + + +function exchange(target, bytes, headOnly) { + return new Promise((resolve, reject) => { + const socket = net.connect(target.port, target.host); + const chunks = []; + let done = false; + const timer = setTimeout(() => finish(new Error("response deadline")), 10000); + function finish(err, value) { + if (done) return; + done = true; + clearTimeout(timer); + socket.destroy(); + if (err) reject(err); + else resolve(value); + } + socket.on("connect", () => socket.write(bytes)); + socket.on("data", (b) => { + chunks.push(b); + const all = Buffer.concat(chunks); + const end = complete(all, headOnly); + if (end !== null) finish(null, all.subarray(0, end)); + }); + socket.on("end", () => finish(null, Buffer.concat(chunks))); + socket.on("error", (e) => finish(e)); + }); +} + +// Offset just past one complete response in `buf`, or null if more is needed. +function complete(buf, headOnly) { + const headEnd = buf.indexOf("\r\n\r\n"); + if (headEnd < 0) return null; + const head = buf.subarray(0, headEnd).toString("latin1"); + const status = Number(head.split(" ")[1]); + const header = (name) => { + const line = head + .split("\r\n") + .slice(1) + .find((l) => l.toLowerCase().startsWith(name + ":")); + return line === undefined ? undefined : line.slice(name.length + 1).trim(); + }; + let at = headEnd + 4; + if (headOnly || status === 204 || status === 304 || (status >= 100 && status < 200)) return at; + if ((header("transfer-encoding") || "").toLowerCase() === "chunked") { + for (;;) { + const lineEnd = buf.indexOf("\r\n", at); + if (lineEnd < 0) return null; + const size = parseInt(buf.subarray(at, lineEnd).toString("latin1"), 16); + at = lineEnd + 2 + size + 2; + if (at > buf.length) return null; + if (size === 0) return at; + } + } + const length = header("content-length"); + if (length !== undefined) { + const end = at + Number(length); + return end <= buf.length ? end : null; + } + return null; // delimited by close +} + +function requestBytes(method, target, headers, body) { + let text = `${method} ${target} HTTP/1.1\r\n`; + for (const [name, value] of headers) text += `${name}: ${value}\r\n`; + return Buffer.concat([Buffer.from(text + "\r\n", "latin1"), body]); +} + +const dateLine = /\r\nDate: [^\r]*\r\n/; +function sameButDate(a, b) { + const ma = a.toString("latin1").match(dateLine); + const mb = b.toString("latin1").match(dateLine); + if (!ma || !mb || ma[0] === mb[0]) return false; + return a.toString("latin1").replace(dateLine, "\r\n") === b.toString("latin1").replace(dateLine, "\r\n"); +} + +function firstDifference(a, b) { + const n = Math.min(a.length, b.length); + let i = 0; + while (i < n && a[i] === b[i]) i++; + return i; +} + +function show(buf) { + const head = buf.subarray(0, Math.max(0, buf.indexOf("\r\n\r\n"))).toString("latin1"); + return { head: head.split("\r\n"), bodyBytes: buf.length - head.length - 4 }; +} + + +let dateRetries=0; +const records=[]; +async function reset(seed,id,clock) { + const r=await fetch(`http://server:5001/begin?seed=${seed}&case=${encodeURIComponent(id)}&clock=${clock}`); + if (!r.ok) throw Error("entropy reset failed"); +} +async function compare(c) { + const bytes=requestBytes(c.method||"GET",c.target,c.headers,c.body||Buffer.alloc(0)); + for(let attempt=0;attempt<5;attempt++) { + await reset(c.seed,c.id,c.clock); + const node=await exchange(NODE,bytes,c.method==="HEAD"); + const rust=await exchange(RUST,bytes,c.method==="HEAD"); + const fallback=rust.toString("latin1",0,16).startsWith("HTTP/1.1 502"); + const status=Number(node.toString("latin1").split(" ")[1]); + const unexpectedFallback=!!c.served&&(fallback||status!==(c.status||200)); + if(!fallback&&!node.equals(rust)&&sameButDate(node,rust)){dateRetries++;continue;} + const equal=node.equals(rust); + records.push({id:c.id,method:c.method||"GET",target:c.target,seed:c.seed,expectedServed:c.served,node:node.toString("base64"),rust:rust.toString("base64"),fallback,equal,unexpectedFallback}); + return {id:c.id,fallback,equal,unexpectedFallback,...(!fallback&&!equal?{node:node.toString(),rust:rust.toString()}:{}),...(!c.served&&!fallback?{unexpectedServe:true}:{})}; + } + throw Error(`${c.id}: Date differed five times`); +} +async function main(){ + const tokens=await fetch("http://server:5001/participant-read-tokens").then(r=>r.json()); + const oidc=await fetch("http://server:5001/tokens").then(r=>r.json()); + const {fixtures}=require("/app/characterization/comments-cases.cjs"); + const f=fixtures.find(f=>f.shape==="content-edges"); + const {Pool}=require("/app/node_modules/pg");const pool=new Pool({connectionString:process.env.DATABASE_URL}); + if(new URL(process.env.DATABASE_URL).pathname!=="/p027")throw Error("disposable fixture database required"); + const cases=[],results=[];let clock=1700000000000; + async function run(id,kind,auth,tail="",served=true,method="GET",extra=[],body=""){ + const c={id,clock,seed:"7ac001000001",method,target:`/api/v3/${kind}?conversation_id=${f.capability}${kind==="locations"?"&gid=0":""}${tail}`,served, + headers:[["Host","localhost"],["Connection","close"],["X-Polis-Fixture-Clock",String(clock)],...(auth?[["Authorization",auth]]:[]),...extra],body:Buffer.from(body)}; + cases.push(c);results.push(await compare(c)); + } + async function seed(shape,tick=0,bid=42){ + for(const table of ["math_main","math_bidtopid","math_ptptstats","math_ticks"])await pool.query(`DELETE FROM ${table} WHERE zid=$1 AND math_env='p027'`,[f.zid]); + await pool.query("DELETE FROM participant_locations WHERE zid=$1",[f.zid]); + if(shape==="absent")return; + const main={"math_tick":999,"base-clusters":{id:shape==="gap"?[]:[bid,99]},"group-clusters":[{members:shape==="multiple"?[bid,99]:[bid]}]}; + const mapping={math_tick:999,bidToPid:shape==="unplaced"?[[2]]:shape==="malformed"?[[f.participantPid],"invalid"]:[[f.participantPid],[2]]}; + await pool.query("INSERT INTO math_main(zid,math_env,data,last_vote_timestamp,math_tick,caching_tick) VALUES($1,'p027',$2::jsonb,0,$3,$3)",[f.zid,JSON.stringify(main),tick]); + await pool.query("INSERT INTO math_bidtopid(zid,math_env,data,math_tick) VALUES($1,'p027',$2::jsonb,$3)",[f.zid,JSON.stringify(mapping),shape==="incoherent"?tick+1:tick]); + if(shape!=="missing-companion")await pool.query("INSERT INTO math_ptptstats(zid,math_env,data,math_tick) VALUES($1,'p027','{}',$2)",[f.zid,tick]); + await pool.query("INSERT INTO math_ticks(zid,math_env,math_tick,caching_tick) VALUES($1,'p027',$2,$2)",[f.zid,tick]); + await pool.query("INSERT INTO participant_locations(zid,uid,pid,lat,lng,source) VALUES($1,3,$2,0,1e21,1)",[f.zid,f.participantPid]); + if(shape==="multiple")await pool.query("INSERT INTO participant_locations(zid,uid,pid,lat,lng,source) VALUES($1,2,2,10.125,-20.5,1)",[f.zid]); + } + try{ + for(const shape of ["absent","zero","gap","incoherent","missing-companion","unplaced","multiple","malformed"]){ + await seed(shape);clock+=4000; + for(const kind of ["bid","locations"]){ + const served=shape!=="malformed"&&!(shape==="multiple"&&kind==="locations"); + for(const identity of ["anonymous","standard","admin"]){ + const auth=`Bearer ${identity==="admin"?oidc.admin:tokens[`${identity}-${f.zid}`]}`; + await run(`${shape}/${kind}/${identity}`,kind,auth,"",served); + await run(`${shape}/${kind}/${identity}/head`,kind,auth,"",served,"HEAD"); + await run(`${shape}/${kind}/${identity}/origin`,kind,auth,"",served,"GET",[["Origin","https://example.invalid"]]); + } + await run(`${shape}/${kind}/no-auth`,kind,null,"",served&&kind==="locations"); + } + const auth=`Bearer ${tokens[`anonymous-${f.zid}`]}`; + await run(`${shape}/bid/stale`,"bid",auth,"&math_tick=0",false); + } + const auth=`Bearer ${tokens[`anonymous-${f.zid}`]}`; + await seed("zero",9,42);clock+=4000; + await run("cache/cold/bid","bid",auth);await run("cache/cold/locations","locations",null); + await seed("zero",10,55);clock+=1000; + await run("cache/warm/bid","bid",auth);await run("cache/warm/locations","locations",null); + clock+=2000; + await run("cache/expired/bid","bid",auth);await run("cache/expired/locations","locations",null); + for(const kind of ["bid","locations"]){ + for(const tail of ["&pid=0","&unknown=1","&conversation_id=other"])await run(`boundary/${kind}/${tail}`,kind,auth,tail,false); + for(const method of ["POST","OPTIONS"])await run(`boundary/${kind}/${method}`,kind,auth,"",false,method); + await run(`boundary/${kind}/cookie`,kind,auth,"",false,"GET",[["Cookie","x=y"]]); + await run(`boundary/${kind}/body`,kind,auth,"",false,"GET",[["Content-Length","2"]],"{}"); + await run(`boundary/${kind}/bad-auth`,kind,"Bearer malformed","",false); + await run(`boundary/${kind}/xid`,kind,`Bearer ${tokens[`xid-${f.zid}`]}`,"",false); + } + let off=0;for(const c of cases){const response=await exchange({host:"polis-api-off",port:5100},requestBytes(c.method,c.target,c.headers,c.body),c.method==="HEAD");if(!response.toString("latin1").startsWith("HTTP/1.1 502"))throw Error(`off switch served ${c.id}`);off++;} + const failed=results.filter(r=>r.unexpectedFallback||r.unexpectedServe||(!r.fallback&&!r.equal)); + fs.writeFileSync("/artifacts/math-membership-recordings.json",JSON.stringify({records},null,2)+"\n"); + console.log(JSON.stringify({cases:cases.length,exact:results.filter(r=>r.equal).length,handbacks:results.filter(r=>r.fallback).length,off,dateRetries,failed},null,2));if(failed.length)process.exitCode=1; + }finally{await pool.end();} +} +main().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/queue-rs/polis-api/conformance/math-membership-run.sh b/queue-rs/polis-api/conformance/math-membership-run.sh new file mode 100755 index 000000000..043eee745 --- /dev/null +++ b/queue-rs/polis-api/conformance/math-membership-run.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Record bucket and location rows under anonymous, participant and OIDC auth and +# compare complete Node/Rust HTTP bytes. Uses only the isolated generated stack. +# Usage: math-membership-run.sh [result.json], with unique project and P027 ports. +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:-/dev/stdout} +here="$root/server/characterization" +# Require an explicitly named disposable project and three distinct loopback ports. +python3 - <<'CHECK' +import os,re +project=os.environ.get("COMPOSE_PROJECT_NAME", "") +assert re.fullmatch(r"[a-z][a-z0-9_-]{5,63}",project), "unique project required" +ports=[int(os.environ[k]) for k in ["POLIS_RECOVERY_PG_PORT","P027_HTTP_PORT","P027_CONTROL_PORT"]] +assert len(set(ports))==3 and all(55432<=p<=65535 for p in ports) +CHECK +export P027_POSTGRES_IMAGE=${P027_POSTGRES_IMAGE:-x54pca2-postgres:local} +compose=(docker compose -f "$here/compose.yml" -f "$root/queue-rs/polis-api/conformance/compose.yml" -f "$root/queue-rs/polis-api/conformance/participant-compose.yml" -f "$root/queue-rs/polis-api/conformance/math-membership-compose.yml") +if [[ -n $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]]; then + echo "project $COMPOSE_PROJECT_NAME already has containers" >&2 + exit 1 +fi +cleanup() { "${compose[@]}" logs --no-color server polis-api >"${out%.json}-services.log" 2>&1 || true; "${compose[@]}" --profile seed down -v --remove-orphans >/dev/null 2>&1 || true; } +trap cleanup EXIT INT TERM +ready() { + for _ in $(seq 60); do + if "${compose[@]}" exec -T server node -e "fetch('http://localhost:5001/ready',{signal:AbortSignal.timeout(3000)}).then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))" >/dev/null 2>&1; then + return 0 + fi + sleep 1 + done + echo "Node readiness deadline" >&2 + return 1 +} +"${compose[@]}" up -d --pull never postgres dynamodb oidc-simulator server driver +"${compose[@]}" restart server +ready +"${compose[@]}" exec -T driver node characterization/cli.cjs seed +"${compose[@]}" exec -T driver node /conformance/votes-read-seed.cjs +"${compose[@]}" exec -T driver node characterization/cli.cjs seed-comments +# Fresh caches on both sides before the first replayed request. +"${compose[@]}" restart server dynamodb +ready +"${compose[@]}" exec -T driver node -e 'fetch("http://server:5001/public-key").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/participant-public.pem",v.publicKey))' +"${compose[@]}" exec -T driver node -e 'fetch("https://oidc-simulator:3000/.well-known/jwks.json").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/read-jwks.json",JSON.stringify(v)))' +"${compose[@]}" up -d --pull never polis-api polis-api-off +for _ in $(seq 60); do + if "${compose[@]}" exec -T driver node -e 'fetch("http://polis-api:5100/health").then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))'; then break; fi + sleep 1 +done +"${compose[@]}" exec -T driver node /conformance/math-membership-replay.cjs >"$out" diff --git a/queue-rs/polis-api/conformance/my-invites-csv-compose.yml b/queue-rs/polis-api/conformance/my-invites-csv-compose.yml new file mode 100644 index 000000000..821b7dd51 --- /dev/null +++ b/queue-rs/polis-api/conformance/my-invites-csv-compose.yml @@ -0,0 +1,27 @@ +# Test-only opt-in; production defaults stay off. +services: + polis-api: + environment: + POLIS_API_MY_INVITES_CSV_READS: "1" + TZ: UTC + POLIS_API_MY_INVITES_CSV_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_READ_JWKS_FILE: /artifacts/read-jwks.json + AUTH_ISSUER: https://oidc-simulator:3000/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ + polis-api-off: + image: ${X54_POLIS_API_IMAGE:-x54pca2-polis-api:conformance} + networks: [sealed] + environment: + MATH_ENV: p027 + DEV_MODE: "true" + NODE_ENV: production + DOMAIN_OVERRIDE: localhost + DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + POLIS_API_LISTEN: 0.0.0.0:5100 + POLIS_API_FIXTURE_CLOCK: "1700000000000" + server: + environment: + TZ: UTC diff --git a/queue-rs/polis-api/conformance/my-invites-csv-replay.cjs b/queue-rs/polis-api/conformance/my-invites-csv-replay.cjs new file mode 100644 index 000000000..10a4208ed --- /dev/null +++ b/queue-rs/polis-api/conformance/my-invites-csv-replay.cjs @@ -0,0 +1,171 @@ +"use strict"; +// Raw HTTP fixture proof; no response normalization. Node source and fixture +// writers are unchanged. Boundary handoffs are counted separately. +const fs = require("node:fs"); +const net = require("node:net"); +const zlib = require("node:zlib"); + +const NODE = { host: "server", port: 5000 }; +const RUST = { host: "polis-api", port: 5100 }; + + +function exchange(target, bytes, headOnly) { + return new Promise((resolve, reject) => { + const socket = net.connect(target.port, target.host); + const chunks = []; + let done = false; + const timer = setTimeout(() => finish(new Error("response deadline")), 10000); + function finish(err, value) { + if (done) return; + done = true; + clearTimeout(timer); + socket.destroy(); + if (err) reject(err); + else resolve(value); + } + socket.on("connect", () => socket.write(bytes)); + socket.on("data", (b) => { + chunks.push(b); + const all = Buffer.concat(chunks); + const end = complete(all, headOnly); + if (end !== null) finish(null, all.subarray(0, end)); + }); + socket.on("end", () => finish(null, Buffer.concat(chunks))); + socket.on("error", (e) => finish(e)); + }); +} + +// Offset just past one complete response in `buf`, or null if more is needed. +function complete(buf, headOnly) { + const headEnd = buf.indexOf("\r\n\r\n"); + if (headEnd < 0) return null; + const head = buf.subarray(0, headEnd).toString("latin1"); + const status = Number(head.split(" ")[1]); + const header = (name) => { + const line = head + .split("\r\n") + .slice(1) + .find((l) => l.toLowerCase().startsWith(name + ":")); + return line === undefined ? undefined : line.slice(name.length + 1).trim(); + }; + let at = headEnd + 4; + if (headOnly || status === 204 || status === 304 || (status >= 100 && status < 200)) return at; + if ((header("transfer-encoding") || "").toLowerCase() === "chunked") { + for (;;) { + const lineEnd = buf.indexOf("\r\n", at); + if (lineEnd < 0) return null; + const size = parseInt(buf.subarray(at, lineEnd).toString("latin1"), 16); + at = lineEnd + 2 + size + 2; + if (at > buf.length) return null; + if (size === 0) return at; + } + } + const length = header("content-length"); + if (length !== undefined) { + const end = at + Number(length); + return end <= buf.length ? end : null; + } + return null; // delimited by close +} + +function requestBytes(method, target, headers, body) { + let text = `${method} ${target} HTTP/1.1\r\n`; + for (const [name, value] of headers) text += `${name}: ${value}\r\n`; + return Buffer.concat([Buffer.from(text + "\r\n", "latin1"), body]); +} + +const dateLine = /\r\nDate: [^\r]*\r\n/; +function sameButDate(a, b) { + const ma = a.toString("latin1").match(dateLine); + const mb = b.toString("latin1").match(dateLine); + if (!ma || !mb || ma[0] === mb[0]) return false; + return a.toString("latin1").replace(dateLine, "\r\n") === b.toString("latin1").replace(dateLine, "\r\n"); +} + +function firstDifference(a, b) { + const n = Math.min(a.length, b.length); + let i = 0; + while (i < n && a[i] === b[i]) i++; + return i; +} + +function show(buf) { + const head = buf.subarray(0, Math.max(0, buf.indexOf("\r\n\r\n"))).toString("latin1"); + return { head: head.split("\r\n"), bodyBytes: buf.length - head.length - 4 }; +} + + +let dateRetries=0; +const records=[]; +async function reset(seed,id) { + const r=await fetch(`http://server:5001/begin?seed=${seed}&case=${encodeURIComponent(id)}`); + if (!r.ok) throw Error("entropy reset failed"); +} +async function compare(c) { + const bytes=requestBytes(c.method||"GET",c.target,c.headers,c.body||Buffer.alloc(0)); + for(let attempt=0;attempt<5;attempt++) { + await reset(c.seed,c.id); + const node=await exchange(NODE,bytes,c.method==="HEAD"); + const rust=await exchange(RUST,bytes,c.method==="HEAD"); + const fallback=rust.toString("latin1",0,16).startsWith("HTTP/1.1 502"); + const status=Number(node.toString("latin1").split(" ")[1]); + const unexpectedFallback=!!c.served&&(fallback||status!==(c.status||200)); + if(!fallback&&!node.equals(rust)&&sameButDate(node,rust)){dateRetries++;continue;} + const equal=node.equals(rust); + records.push({id:c.id,method:c.method||"GET",target:c.target,seed:c.seed,expectedServed:c.served,node:node.toString("base64"),rust:rust.toString("base64"),fallback,equal,unexpectedFallback}); + return {id:c.id,fallback,equal,unexpectedFallback,...(!fallback&&!equal?{node:node.toString(),rust:rust.toString()}:{}),...(!c.served&&!fallback?{unexpectedServe:true}:{})}; + } + throw Error(`${c.id}: Date differed five times`); +} +async function main(){ + const tokens=await fetch("http://server:5001/participant-read-tokens").then(r=>r.json()); + const oidc=await fetch("http://server:5001/tokens").then(r=>r.json()); + const {fixtures}=require("/app/characterization/comments-cases.cjs"); + const {Pool}=require("/app/node_modules/pg"); + const pool=new Pool({connectionString:process.env.DATABASE_URL}); + if(new URL(process.env.DATABASE_URL).pathname!=="/p027")throw Error("disposable fixture database required"); + const f=fixtures.find(f=>f.shape==="content-edges"); + const cases=[],results=[]; + function add(id,f,auth,tail="",served=true,method="GET",extra=[],body="") { + const c={id,seed:"7ac001000001",method,target:`/api/v3/treevite/myInvites/csv?conversation_id=${f.capability}${tail}`,served, + headers:[["Host","localhost"],["Connection","close"],...(auth?[["Authorization",auth]]:[]),...extra],body:Buffer.from(body)}; + cases.push(c);return c; + } + async function run(...args){results.push(await compare(add(...args)));} + try { + await pool.query("INSERT INTO treevite_waves(id,zid,wave,invites_per_user,owner_invites) VALUES(990020,$1,3,4,5)",[f.zid]); + for(const phase of ["empty","populated","used"]){ + if(phase==="populated") { + const codes=["generated invite",'comma,quote"line\nnext',"carriage\rreturn","unicode 🙂"]; + for(let i=0;ir.unexpectedFallback||r.unexpectedServe||(!r.fallback&&!r.equal)); + fs.writeFileSync("/artifacts/my-invites-csv-recordings.json",JSON.stringify({records},null,2)+"\n"); + console.log(JSON.stringify({cases:cases.length,exact:results.filter(r=>r.equal).length,handbacks:results.filter(r=>r.fallback).length,off,dateRetries,failed},null,2)); + if(failed.length)process.exitCode=1; + }finally{await pool.end();} +} +main().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/queue-rs/polis-api/conformance/my-invites-csv-run.sh b/queue-rs/polis-api/conformance/my-invites-csv-run.sh new file mode 100755 index 000000000..d33823126 --- /dev/null +++ b/queue-rs/polis-api/conformance/my-invites-csv-run.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Record participant-owned invitation CSV under anonymous, participant and OIDC auth and +# compare complete Node/Rust HTTP bytes. Uses only the isolated generated stack. +# Usage: my-invites-csv-run.sh [result.json], with unique project and P027 ports. +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:-/dev/stdout} +here="$root/server/characterization" +# Require an explicitly named disposable project and three distinct loopback ports. +python3 - <<'CHECK' +import os,re +project=os.environ.get("COMPOSE_PROJECT_NAME", "") +assert re.fullmatch(r"[a-z][a-z0-9_-]{5,63}",project), "unique project required" +ports=[int(os.environ[k]) for k in ["POLIS_RECOVERY_PG_PORT","P027_HTTP_PORT","P027_CONTROL_PORT"]] +assert len(set(ports))==3 and all(55432<=p<=65535 for p in ports) +CHECK +export P027_POSTGRES_IMAGE=${P027_POSTGRES_IMAGE:-x54pca2-postgres:local} +compose=(docker compose -f "$here/compose.yml" -f "$root/queue-rs/polis-api/conformance/compose.yml" -f "$root/queue-rs/polis-api/conformance/participant-compose.yml" -f "$root/queue-rs/polis-api/conformance/my-invites-csv-compose.yml") +if [[ -n $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]]; then + echo "project $COMPOSE_PROJECT_NAME already has containers" >&2 + exit 1 +fi +cleanup() { "${compose[@]}" logs --no-color server polis-api >"${out%.json}-services.log" 2>&1 || true; "${compose[@]}" --profile seed down -v --remove-orphans >/dev/null 2>&1 || true; } +trap cleanup EXIT INT TERM +ready() { + for _ in $(seq 60); do + if "${compose[@]}" exec -T server node -e "fetch('http://localhost:5001/ready',{signal:AbortSignal.timeout(3000)}).then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))" >/dev/null 2>&1; then + return 0 + fi + sleep 1 + done + echo "Node readiness deadline" >&2 + return 1 +} +"${compose[@]}" up -d --pull never postgres dynamodb oidc-simulator server driver +"${compose[@]}" restart server +ready +"${compose[@]}" exec -T driver node characterization/cli.cjs seed +"${compose[@]}" exec -T driver node /conformance/votes-read-seed.cjs +"${compose[@]}" exec -T driver node characterization/cli.cjs seed-comments +# Fresh caches on both sides before the first replayed request. +"${compose[@]}" restart server dynamodb +ready +"${compose[@]}" exec -T driver node -e 'fetch("http://server:5001/public-key").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/participant-public.pem",v.publicKey))' +"${compose[@]}" exec -T driver node -e 'fetch("https://oidc-simulator:3000/.well-known/jwks.json").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/read-jwks.json",JSON.stringify(v)))' +"${compose[@]}" up -d --pull never polis-api polis-api-off +for _ in $(seq 60); do + if "${compose[@]}" exec -T driver node -e 'fetch("http://polis-api:5100/health").then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))'; then break; fi + sleep 1 +done +"${compose[@]}" exec -T driver node /conformance/my-invites-csv-replay.cjs >"$out" diff --git a/queue-rs/polis-api/conformance/nginx-routing.sh b/queue-rs/polis-api/conformance/nginx-routing.sh index 017fdf4c8..27160d153 100755 --- a/queue-rs/polis-api/conformance/nginx-routing.sh +++ b/queue-rs/polis-api/conformance/nginx-routing.sh @@ -1364,3 +1364,159 @@ sleep 6 expect /api/v3/votes node "vote reads handoff" expect /api/v3/votes/me node "personal reads handoff" echo "ok vote read routes: off/on/deduplicated, methods/body, fallback" + +# Each conversation link page has an independent switch. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +expect /iip/4fixture node "participation link off" +expect /iim/4fixture node "moderation link off" +for route in iip iim; do + start "$route,$route" + expect "/$route/4fixture" rust "link page on" + expect "/$route/4fixture/" rust "link page trailing slash" + expect_upstream polis-api HEAD "/$route/4fixture" + expect_upstream server POST "/$route/4fixture" $'Content-Length: 2\r\n' '{}' + expect_upstream server OPTIONS "/$route/4fixture" + expect_upstream server GET "/$route/4fixture" $'Content-Length: 2\r\n' '{}' + expect /api/v3/votes node "link leaves votes alone" + expect /api/v3/nextComment node "link leaves next statement alone" + if [[ $route == iip ]]; then expect /iim/4fixture node "moderation switch independent"; else expect /iip/4fixture node "participation switch independent"; fi +done +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 handoff +sleep 6 +start iip,iim +expect /iip/4fixture node "participation link fallback" +expect /iim/4fixture node "moderation link fallback" +echo "ok conversation links: independent off/on, methods/body, fallback" + +# Current participant rows have their own default-off selector. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +expect /api/v3/participants node "participants off" +start participantsRead,participantsRead +expect /api/v3/participants rust "participants on" +[[ $(included | grep -c 'location = /api/v3/participants {') == 1 ]] || fail "participants duplicated" +expect_upstream polis-api HEAD /api/v3/participants +expect_upstream server OPTIONS /api/v3/participants +expect_upstream server POST /api/v3/participants $'Content-Length: 2\r\n' '{}' +expect_upstream server GET /api/v3/participants $'Content-Length: 2\r\n' '{}' +expect /api/v3/votes node "participants leave votes alone" +expect /api/v3/nextComment node "participants leave next statement alone" +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 handoff +sleep 6 +expect /api/v3/participants node "participants fallback" +echo "ok current participant: off/on/deduplicated, methods/body, fallback" + +# Social participant rows have their own default-off selector. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +expect /api/v3/ptptois node "social off" +start ptptois,ptptois +expect /api/v3/ptptois rust "social on" +[[ $(included | grep -c 'location = /api/v3/ptptois {') == 1 ]] || fail "social duplicated" +expect_upstream polis-api HEAD /api/v3/ptptois +expect_upstream server OPTIONS /api/v3/ptptois +expect_upstream server PUT /api/v3/ptptois +expect_upstream server POST /api/v3/ptptois $'Content-Length: 2\r\n' '{}' +expect_upstream server GET /api/v3/ptptois $'Content-Length: 2\r\n' '{}' +expect /api/v3/votes node "social leave votes alone" +expect /api/v3/nextComment node "social leave next statement alone" +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 handoff +sleep 6 +expect /api/v3/ptptois node "social fallback" +echo "ok social participant: off/on/deduplicated, methods/body, fallback" + +# Participant-owned CSV have their own default-off selector. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +expect /api/v3/treevite/myInvites/csv node "invitation CSV off" +start myInvitesCsv,myInvitesCsv +expect /api/v3/treevite/myInvites/csv rust "invitation CSV on" +[[ $(included | grep -c 'location = /api/v3/treevite/myInvites/csv {') == 1 ]] || fail "invitation CSV duplicated" +expect_upstream polis-api HEAD /api/v3/treevite/myInvites/csv +expect_upstream server OPTIONS /api/v3/treevite/myInvites/csv +expect_upstream server POST /api/v3/treevite/myInvites/csv $'Content-Length: 2\r\n' '{}' +expect_upstream server GET /api/v3/treevite/myInvites/csv $'Content-Length: 2\r\n' '{}' +expect /api/v3/votes node "invitation CSV leave votes alone" +expect /api/v3/nextComment node "invitation CSV leave next statement alone" +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 handoff +sleep 6 +expect /api/v3/treevite/myInvites/csv node "invitation CSV fallback" +echo "ok participant invitation CSV: off/on/deduplicated, methods/body, fallback" + +# Bid rows have their own default-off selector. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +expect /api/v3/bid node "bid off" +start bid,bid +expect /api/v3/bid rust "bid on" +expect /api/v3/locations node "other math selector remains off" +[[ $(included | grep -c 'location = /api/v3/bid {') == 1 ]] || fail "bid duplicated" +expect_upstream polis-api HEAD /api/v3/bid +expect_upstream server OPTIONS /api/v3/bid +expect_upstream server POST /api/v3/bid $'Content-Length: 2\r\n' '{}' +expect_upstream server GET /api/v3/bid $'Content-Length: 2\r\n' '{}' +expect /api/v3/votes node "bid leave votes alone" +expect /api/v3/nextComment node "bid leave next statement alone" +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 handoff +sleep 6 +expect /api/v3/bid node "bid fallback" +echo "ok bid: off/on/deduplicated, methods/body, fallback" + +# Locations rows have their own default-off selector. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +expect /api/v3/locations node "locations off" +start locations,locations +expect /api/v3/locations rust "locations on" +expect /api/v3/bid node "other math selector remains off" +[[ $(included | grep -c 'location = /api/v3/locations {') == 1 ]] || fail "locations duplicated" +expect_upstream polis-api HEAD /api/v3/locations +expect_upstream server OPTIONS /api/v3/locations +expect_upstream server POST /api/v3/locations $'Content-Length: 2\r\n' '{}' +expect_upstream server GET /api/v3/locations $'Content-Length: 2\r\n' '{}' +expect /api/v3/votes node "locations leave votes alone" +expect /api/v3/nextComment node "locations leave next statement alone" +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 handoff +sleep 6 +expect /api/v3/locations node "locations fallback" +echo "ok locations: off/on/deduplicated, methods/body, fallback" + +# Conversation HTML routes retain independent default-off selectors. +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 200 rust +start "" +for prefix in / /explore/ /share/ /summary/ /ot/; do expect "${prefix}4fixture" node "conversation page off"; done +for selector in conversationPage explorePage sharePage summaryPage oneTimePage; do + case "$selector" in conversationPage) prefix=/ ;; explorePage) prefix=/explore/ ;; sharePage) prefix=/share/ ;; summaryPage) prefix=/summary/ ;; oneTimePage) prefix=/ot/ ;; esac + start "$selector,$selector" + expect "${prefix}4fixture" rust "conversation page on" + expect "${prefix}4fixture/suffix" rust "conversation page prefix suffix" + expect_upstream polis-api HEAD "${prefix}4fixture" + expect_upstream server OPTIONS "${prefix}4fixture" + expect_upstream server POST "${prefix}4fixture" $'Content-Length: 2\r\n' '{}' + expect_upstream server GET "${prefix}4fixture" $'Content-Length: 2\r\n' '{}' + for other in / /explore/ /share/ /summary/ /ot/; do + if [[ $other != "$prefix" ]]; then expect "${other}4fixture" node "other conversation switch off"; fi + done + expect /api/v3/votes node "page leaves votes alone" + expect /api/v3/nextComment node "page leaves next statement alone" +done +docker rm -f "$p-rust" >/dev/null +stub "$p-rust" polis-api 5100 502 handoff +sleep 6 +start conversationPage,explorePage,sharePage,summaryPage,oneTimePage +for prefix in / /explore/ /share/ /summary/ /ot/; do expect "${prefix}4fixture" node "conversation page handback"; done +echo "ok conversation HTML: five independent switches, suffix, methods/body, fallback" diff --git a/queue-rs/polis-api/conformance/participants-read-compose.yml b/queue-rs/polis-api/conformance/participants-read-compose.yml new file mode 100644 index 000000000..65ed27693 --- /dev/null +++ b/queue-rs/polis-api/conformance/participants-read-compose.yml @@ -0,0 +1,23 @@ +# Test-only opt-in; production defaults stay off. +services: + polis-api: + environment: + POLIS_API_PARTICIPANTS_READS: "1" + POLIS_API_PARTICIPANTS_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_READ_JWKS_FILE: /artifacts/read-jwks.json + AUTH_ISSUER: https://oidc-simulator:3000/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ + polis-api-off: + image: ${X54_POLIS_API_IMAGE:-x54pca2-polis-api:conformance} + networks: [sealed] + environment: + MATH_ENV: p027 + DEV_MODE: "true" + NODE_ENV: production + DOMAIN_OVERRIDE: localhost + DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + POLIS_API_LISTEN: 0.0.0.0:5100 + POLIS_API_FIXTURE_CLOCK: "1700000000000" diff --git a/queue-rs/polis-api/conformance/participants-read-replay.cjs b/queue-rs/polis-api/conformance/participants-read-replay.cjs new file mode 100644 index 000000000..c4f882a86 --- /dev/null +++ b/queue-rs/polis-api/conformance/participants-read-replay.cjs @@ -0,0 +1,189 @@ +"use strict"; +// Raw HTTP fixture proof; no response normalization. Node source and fixture +// writers are unchanged. Boundary handoffs are counted separately. +const fs = require("node:fs"); +const net = require("node:net"); +const zlib = require("node:zlib"); + +const NODE = { host: "server", port: 5000 }; +const RUST = { host: "polis-api", port: 5100 }; + + +function exchange(target, bytes, headOnly) { + return new Promise((resolve, reject) => { + const socket = net.connect(target.port, target.host); + const chunks = []; + let done = false; + const timer = setTimeout(() => finish(new Error("response deadline")), 10000); + function finish(err, value) { + if (done) return; + done = true; + clearTimeout(timer); + socket.destroy(); + if (err) reject(err); + else resolve(value); + } + socket.on("connect", () => socket.write(bytes)); + socket.on("data", (b) => { + chunks.push(b); + const all = Buffer.concat(chunks); + const end = complete(all, headOnly); + if (end !== null) finish(null, all.subarray(0, end)); + }); + socket.on("end", () => finish(null, Buffer.concat(chunks))); + socket.on("error", (e) => finish(e)); + }); +} + +// Offset just past one complete response in `buf`, or null if more is needed. +function complete(buf, headOnly) { + const headEnd = buf.indexOf("\r\n\r\n"); + if (headEnd < 0) return null; + const head = buf.subarray(0, headEnd).toString("latin1"); + const status = Number(head.split(" ")[1]); + const header = (name) => { + const line = head + .split("\r\n") + .slice(1) + .find((l) => l.toLowerCase().startsWith(name + ":")); + return line === undefined ? undefined : line.slice(name.length + 1).trim(); + }; + let at = headEnd + 4; + if (headOnly || status === 204 || status === 304 || (status >= 100 && status < 200)) return at; + if ((header("transfer-encoding") || "").toLowerCase() === "chunked") { + for (;;) { + const lineEnd = buf.indexOf("\r\n", at); + if (lineEnd < 0) return null; + const size = parseInt(buf.subarray(at, lineEnd).toString("latin1"), 16); + at = lineEnd + 2 + size + 2; + if (at > buf.length) return null; + if (size === 0) return at; + } + } + const length = header("content-length"); + if (length !== undefined) { + const end = at + Number(length); + return end <= buf.length ? end : null; + } + return null; // delimited by close +} + +function requestBytes(method, target, headers, body) { + let text = `${method} ${target} HTTP/1.1\r\n`; + for (const [name, value] of headers) text += `${name}: ${value}\r\n`; + return Buffer.concat([Buffer.from(text + "\r\n", "latin1"), body]); +} + +const dateLine = /\r\nDate: [^\r]*\r\n/; +function sameButDate(a, b) { + const ma = a.toString("latin1").match(dateLine); + const mb = b.toString("latin1").match(dateLine); + if (!ma || !mb || ma[0] === mb[0]) return false; + return a.toString("latin1").replace(dateLine, "\r\n") === b.toString("latin1").replace(dateLine, "\r\n"); +} + +function firstDifference(a, b) { + const n = Math.min(a.length, b.length); + let i = 0; + while (i < n && a[i] === b[i]) i++; + return i; +} + +function show(buf) { + const head = buf.subarray(0, Math.max(0, buf.indexOf("\r\n\r\n"))).toString("latin1"); + return { head: head.split("\r\n"), bodyBytes: buf.length - head.length - 4 }; +} + + +let dateRetries=0; +const records=[]; +async function reset(seed,id) { + const r=await fetch(`http://server:5001/begin?seed=${seed}&case=${encodeURIComponent(id)}`); + if (!r.ok) throw Error("entropy reset failed"); +} +async function compare(c) { + const bytes=requestBytes(c.method||"GET",c.target,c.headers,c.body||Buffer.alloc(0)); + for(let attempt=0;attempt<5;attempt++) { + await reset(c.seed,c.id); + const node=await exchange(NODE,bytes,c.method==="HEAD"); + const rust=await exchange(RUST,bytes,c.method==="HEAD"); + const fallback=rust.toString("latin1",0,16).startsWith("HTTP/1.1 502"); + const status=Number(node.toString("latin1").split(" ")[1]); + const unexpectedFallback=!!c.served&&(fallback||status!==(c.status||200)); + if(!fallback&&!node.equals(rust)&&sameButDate(node,rust)){dateRetries++;continue;} + const equal=node.equals(rust); + records.push({id:c.id,method:c.method||"GET",target:c.target,seed:c.seed,expectedServed:c.served,node:node.toString("base64"),rust:rust.toString("base64"),fallback,equal,unexpectedFallback}); + return {id:c.id,fallback,equal,unexpectedFallback,...(!fallback&&!equal?{node:node.toString(),rust:rust.toString()}:{}),...(!c.served&&!fallback?{unexpectedServe:true}:{})}; + } + throw Error(`${c.id}: Date differed five times`); +} +async function main(){ + const tokens=await fetch("http://server:5001/participant-read-tokens").then(r=>r.json()); + const oidc=await fetch("http://server:5001/tokens").then(r=>r.json()); + const {fixtures}=require("/app/characterization/comments-cases.cjs"); + const {seedVote}=require("/app/characterization/seed-vote.cjs"); + const {Pool}=require("/app/node_modules/pg"); + const pool=new Pool({connectionString:process.env.DATABASE_URL}); + if(new URL(process.env.DATABASE_URL).pathname!=="/p027")throw Error("disposable fixture database required"); + const chosen=[fixtures.find(f=>f.shape==="content-edges"),fixtures.find(f=>f.participantPid>0)]; + const cases=[],results=[]; + function add(id,f,auth,tail="",served=true,method="GET",extra=[],body="") { + const c={id,seed:"7ac001000001",method,target:`/api/v3/participants?conversation_id=${f.capability}${tail}`,served, + headers:[["Host","localhost"],["Connection","close"],...(auth?[["Authorization",auth]]:[]),...extra],body:Buffer.from(body)}; + cases.push(c);return c; + } + async function run(...args){results.push(await compare(add(...args)));} + try { + for (const phase of ["empty-history","history","null-metadata","bigint-metadata"]) { + for (const f of chosen) { + if(phase==="empty-history") { + await pool.query("DELETE FROM votes WHERE zid=$1",[f.zid]); + await pool.query("DELETE FROM votes_latest_unique WHERE zid=$1",[f.zid]); + } else if(phase==="history") { + await pool.query("INSERT INTO votes(zid,pid,tid,vote,weight_x_32767,created,high_priority) VALUES($1,$2,700,$3,123,1700000000123,true)",[f.zid,f.participantPid,seedVote("agree")]); + } + // Historical event count, not the retained metadata column, is served. + await pool.query("UPDATE participants SET vote_count=777 WHERE zid=$1",[f.zid]); + if(phase==="null-metadata") { + await pool.query("DELETE FROM votes WHERE zid=$1",[f.zid]); + await pool.query("UPDATE participants SET last_notified=NULL,created=NULL WHERE zid=$1",[f.zid]); + } + if(phase==="bigint-metadata") { + await pool.query("UPDATE participants SET last_interaction=9223372036854775807,last_notified=-9223372036854775808,created=9007199254740993 WHERE zid=$1",[f.zid]); + } + const label=`${phase}/${f===chosen[0]?"pid-zero":"pid-nonzero"}`; + for (const kind of ["anonymous","standard"]) { + const auth=`Bearer ${tokens[`${kind}-${f.zid}`]}`; + await run(`${label}/${kind}`,f,auth); + await run(`${label}/${kind}/head`,f,auth,"",true,"HEAD"); + await run(`${label}/${kind}/origin`,f,auth,"",true,"GET",[["Origin","https://example.invalid"]]); + } + for(const role of ["owner","admin","comments-owner-1","comments-moderator"]) { + const auth=`Bearer ${oidc[role]}`; + await run(`${label}/${role}`,f,auth); + await run(`${label}/${role}/head`,f,auth,"",true,"HEAD"); + } + await run(`${label}/no-auth`,f,null,"",false); + await run(`${label}/xid`,f,`Bearer ${tokens[`xid-${f.zid}`]}`,"",false); + } + } + const f=chosen[0],auth=`Bearer ${tokens[`anonymous-${f.zid}`]}`; + for(const tail of ["&pid=0","&limit=1","&conversation_id=other","&unknown=1"])await run(`boundary/${tail}`,f,auth,tail,false); + for(const method of ["POST","OPTIONS"])await run(`boundary/${method}`,f,auth,"",false,method); + await run("boundary/cookie",f,auth,"",false,"GET",[["Cookie","x=y"]]); + await run("boundary/body",f,auth,"",false,"GET",[["Content-Length","2"]],"{}"); + await run("boundary/bad-auth",f,"Bearer malformed","",false); + await run("boundary/missing",{capability:"4missing"},auth,"",false); + let off=0; + for(const c of cases){ + const response=await exchange({host:"polis-api-off",port:5100},requestBytes(c.method,c.target,c.headers,c.body),c.method==="HEAD"); + if(!response.toString("latin1").startsWith("HTTP/1.1 502"))throw Error(`off switch served ${c.id}`); + off++; + } + const failed=results.filter(r=>r.unexpectedFallback||r.unexpectedServe||(!r.fallback&&!r.equal)); + fs.writeFileSync("/artifacts/participants-read-recordings.json",JSON.stringify({records},null,2)+"\n"); + console.log(JSON.stringify({cases:cases.length,exact:results.filter(r=>r.equal).length,handbacks:results.filter(r=>r.fallback).length,off,dateRetries,failed},null,2)); + if(failed.length)process.exitCode=1; + }finally{await pool.end();} +} +main().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/queue-rs/polis-api/conformance/participants-read-run.sh b/queue-rs/polis-api/conformance/participants-read-run.sh new file mode 100755 index 000000000..b6214ae7d --- /dev/null +++ b/queue-rs/polis-api/conformance/participants-read-run.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Record current participant rows under anonymous, participant and OIDC auth and +# compare complete Node/Rust HTTP bytes. Uses only the isolated generated stack. +# Usage: participants-read-run.sh [result.json], with unique project and P027 ports. +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:-/dev/stdout} +here="$root/server/characterization" +# Require an explicitly named disposable project and three distinct loopback ports. +python3 - <<'CHECK' +import os,re +project=os.environ.get("COMPOSE_PROJECT_NAME", "") +assert re.fullmatch(r"[a-z][a-z0-9_-]{5,63}",project), "unique project required" +ports=[int(os.environ[k]) for k in ["POLIS_RECOVERY_PG_PORT","P027_HTTP_PORT","P027_CONTROL_PORT"]] +assert len(set(ports))==3 and all(55432<=p<=65535 for p in ports) +CHECK +export P027_POSTGRES_IMAGE=${P027_POSTGRES_IMAGE:-x54pca2-postgres:local} +compose=(docker compose -f "$here/compose.yml" -f "$root/queue-rs/polis-api/conformance/compose.yml" -f "$root/queue-rs/polis-api/conformance/participant-compose.yml" -f "$root/queue-rs/polis-api/conformance/participants-read-compose.yml") +if [[ -n $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]]; then + echo "project $COMPOSE_PROJECT_NAME already has containers" >&2 + exit 1 +fi +cleanup() { "${compose[@]}" logs --no-color server polis-api >"${out%.json}-services.log" 2>&1 || true; "${compose[@]}" --profile seed down -v --remove-orphans >/dev/null 2>&1 || true; } +trap cleanup EXIT INT TERM +ready() { + for _ in $(seq 60); do + if "${compose[@]}" exec -T server node -e "fetch('http://localhost:5001/ready',{signal:AbortSignal.timeout(3000)}).then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))" >/dev/null 2>&1; then + return 0 + fi + sleep 1 + done + echo "Node readiness deadline" >&2 + return 1 +} +"${compose[@]}" up -d --pull never postgres dynamodb oidc-simulator server driver +"${compose[@]}" restart server +ready +"${compose[@]}" exec -T driver node characterization/cli.cjs seed +"${compose[@]}" exec -T driver node /conformance/votes-read-seed.cjs +"${compose[@]}" exec -T driver node characterization/cli.cjs seed-comments +# Fresh caches on both sides before the first replayed request. +"${compose[@]}" restart server dynamodb +ready +"${compose[@]}" exec -T driver node -e 'fetch("http://server:5001/public-key").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/participant-public.pem",v.publicKey))' +"${compose[@]}" exec -T driver node -e 'fetch("https://oidc-simulator:3000/.well-known/jwks.json").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/read-jwks.json",JSON.stringify(v)))' +"${compose[@]}" up -d --pull never polis-api polis-api-off +for _ in $(seq 60); do + if "${compose[@]}" exec -T driver node -e 'fetch("http://polis-api:5100/health").then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))'; then break; fi + sleep 1 +done +"${compose[@]}" exec -T driver node /conformance/participants-read-replay.cjs >"$out" diff --git a/queue-rs/polis-api/conformance/ptptois-compose.yml b/queue-rs/polis-api/conformance/ptptois-compose.yml new file mode 100644 index 000000000..2a988d492 --- /dev/null +++ b/queue-rs/polis-api/conformance/ptptois-compose.yml @@ -0,0 +1,24 @@ +# Test-only opt-in; production defaults stay off. +services: + polis-api: + environment: + POLIS_API_PTPTOIS_READS: "1" + ADMIN_UIDS: "[2]" + POLIS_API_PTPTOIS_DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_READ_JWKS_FILE: /artifacts/read-jwks.json + AUTH_ISSUER: https://oidc-simulator:3000/ + AUTH_AUDIENCE: users + AUTH_NAMESPACE: https://pol.is/ + polis-api-off: + image: ${X54_POLIS_API_IMAGE:-x54pca2-polis-api:conformance} + networks: [sealed] + environment: + MATH_ENV: p027 + DEV_MODE: "true" + NODE_ENV: production + DOMAIN_OVERRIDE: localhost + DATABASE_URL: postgres://postgres@postgres:5432/p027 + POLIS_API_DB_TRANSPORT: docker-internal + POLIS_API_DB_PLAIN_HOSTS: postgres + POLIS_API_LISTEN: 0.0.0.0:5100 + POLIS_API_FIXTURE_CLOCK: "1700000000000" diff --git a/queue-rs/polis-api/conformance/ptptois-replay.cjs b/queue-rs/polis-api/conformance/ptptois-replay.cjs new file mode 100644 index 000000000..c554f8e88 --- /dev/null +++ b/queue-rs/polis-api/conformance/ptptois-replay.cjs @@ -0,0 +1,174 @@ +"use strict"; +// Raw HTTP fixture proof; no response normalization. Node source and fixture +// writers are unchanged. Boundary handoffs are counted separately. +const fs = require("node:fs"); +const net = require("node:net"); +const zlib = require("node:zlib"); + +const NODE = { host: "server", port: 5000 }; +const RUST = { host: "polis-api", port: 5100 }; + + +function exchange(target, bytes, headOnly) { + return new Promise((resolve, reject) => { + const socket = net.connect(target.port, target.host); + const chunks = []; + let done = false; + const timer = setTimeout(() => finish(new Error("response deadline")), 10000); + function finish(err, value) { + if (done) return; + done = true; + clearTimeout(timer); + socket.destroy(); + if (err) reject(err); + else resolve(value); + } + socket.on("connect", () => socket.write(bytes)); + socket.on("data", (b) => { + chunks.push(b); + const all = Buffer.concat(chunks); + const end = complete(all, headOnly); + if (end !== null) finish(null, all.subarray(0, end)); + }); + socket.on("end", () => finish(null, Buffer.concat(chunks))); + socket.on("error", (e) => finish(e)); + }); +} + +// Offset just past one complete response in `buf`, or null if more is needed. +function complete(buf, headOnly) { + const headEnd = buf.indexOf("\r\n\r\n"); + if (headEnd < 0) return null; + const head = buf.subarray(0, headEnd).toString("latin1"); + const status = Number(head.split(" ")[1]); + const header = (name) => { + const line = head + .split("\r\n") + .slice(1) + .find((l) => l.toLowerCase().startsWith(name + ":")); + return line === undefined ? undefined : line.slice(name.length + 1).trim(); + }; + let at = headEnd + 4; + if (headOnly || status === 204 || status === 304 || (status >= 100 && status < 200)) return at; + if ((header("transfer-encoding") || "").toLowerCase() === "chunked") { + for (;;) { + const lineEnd = buf.indexOf("\r\n", at); + if (lineEnd < 0) return null; + const size = parseInt(buf.subarray(at, lineEnd).toString("latin1"), 16); + at = lineEnd + 2 + size + 2; + if (at > buf.length) return null; + if (size === 0) return at; + } + } + const length = header("content-length"); + if (length !== undefined) { + const end = at + Number(length); + return end <= buf.length ? end : null; + } + return null; // delimited by close +} + +function requestBytes(method, target, headers, body) { + let text = `${method} ${target} HTTP/1.1\r\n`; + for (const [name, value] of headers) text += `${name}: ${value}\r\n`; + return Buffer.concat([Buffer.from(text + "\r\n", "latin1"), body]); +} + +const dateLine = /\r\nDate: [^\r]*\r\n/; +function sameButDate(a, b) { + const ma = a.toString("latin1").match(dateLine); + const mb = b.toString("latin1").match(dateLine); + if (!ma || !mb || ma[0] === mb[0]) return false; + return a.toString("latin1").replace(dateLine, "\r\n") === b.toString("latin1").replace(dateLine, "\r\n"); +} + +function firstDifference(a, b) { + const n = Math.min(a.length, b.length); + let i = 0; + while (i < n && a[i] === b[i]) i++; + return i; +} + +function show(buf) { + const head = buf.subarray(0, Math.max(0, buf.indexOf("\r\n\r\n"))).toString("latin1"); + return { head: head.split("\r\n"), bodyBytes: buf.length - head.length - 4 }; +} + + +let dateRetries=0; +const records=[]; +async function reset(seed,id) { + const r=await fetch(`http://server:5001/begin?seed=${seed}&case=${encodeURIComponent(id)}`); + if (!r.ok) throw Error("entropy reset failed"); +} +async function compare(c) { + const bytes=requestBytes(c.method||"GET",c.target,c.headers,c.body||Buffer.alloc(0)); + for(let attempt=0;attempt<5;attempt++) { + await reset(c.seed,c.id); + const node=await exchange(NODE,bytes,c.method==="HEAD"); + const rust=await exchange(RUST,bytes,c.method==="HEAD"); + const fallback=rust.toString("latin1",0,16).startsWith("HTTP/1.1 502"); + const status=Number(node.toString("latin1").split(" ")[1]); + const unexpectedFallback=!!c.served&&(fallback||status!==(c.status||200)); + if(!fallback&&!node.equals(rust)&&sameButDate(node,rust)){dateRetries++;continue;} + const equal=node.equals(rust); + records.push({id:c.id,method:c.method||"GET",target:c.target,seed:c.seed,expectedServed:c.served,node:node.toString("base64"),rust:rust.toString("base64"),fallback,equal,unexpectedFallback}); + return {id:c.id,fallback,equal,unexpectedFallback,...(!fallback&&!equal?{node:node.toString(),rust:rust.toString()}:{}),...(!c.served&&!fallback?{unexpectedServe:true}:{})}; + } + throw Error(`${c.id}: Date differed five times`); +} +async function main(){ + const tokens=await fetch("http://server:5001/participant-read-tokens").then(r=>r.json()); + const oidc=await fetch("http://server:5001/tokens").then(r=>r.json()); + const {fixtures}=require("/app/characterization/comments-cases.cjs"); + const {Pool}=require("/app/node_modules/pg"); + const pool=new Pool({connectionString:process.env.DATABASE_URL}); + if(new URL(process.env.DATABASE_URL).pathname!=="/p027")throw Error("disposable fixture database required"); + const f=fixtures.find(f=>f.shape==="content-edges"); + const cases=[],results=[]; + function add(id,f,auth,tail="",served=true,method="GET",extra=[],body="") { + const c={id,seed:"7ac001000001",method,target:`/api/v3/ptptois?conversation_id=${f.capability}${tail}`,served, + headers:[["Host","localhost"],["Connection","close"],...(auth?[["Authorization",auth]]:[]),...extra],body:Buffer.from(body)}; + cases.push(c);return c; + } + async function run(...args){results.push(await compare(add(...args)));} + try { + for(const shape of ["empty","nested","nested-null","flat","multiple"]){ + await pool.query("DELETE FROM xids WHERE owner=$1",[f.owner]); + if(shape!=="empty") { + await pool.query("INSERT INTO xids(owner,uid,xid,x_profile_image_url,x_name) VALUES($1,3,$2,$3,$4)",[f.owner,shape==="flat"?"":"generated-social",shape==="flat"?"":"https://example.invalid/avatar",shape==="nested"?"Name & 🙂":null]); + if(shape==="multiple")await pool.query("INSERT INTO xids(owner,uid,xid,x_profile_image_url,x_name) VALUES($1,2,'other-social','https://example.invalid/other','Other')",[f.owner]); + } + await pool.query("UPDATE participants SET mod=2 WHERE zid=$1 AND uid=3",[f.zid]); + for(const open of [false,true]) { + await pool.query("UPDATE conversations SET is_data_open=$2 WHERE zid=$1",[f.zid,open]); + for(const role of ["anonymous","participant","owner","admin","moderator"]){ + const auth=role==="anonymous"?null:`Bearer ${role==="participant"?tokens[`anonymous-${f.zid}`]:oidc[role==="owner"?`comments-owner-${f.replicate}`:role==="moderator"?"comments-moderator":"admin"]}`; + const allowed=open||role==="owner"||role==="admin"; + await run(`${shape}/${open}/${role}`,f,auth,"",shape!=="multiple"||!allowed); + await run(`${shape}/${open}/${role}/head`,f,auth,"",shape!=="multiple"||!allowed,"HEAD"); + await run(`${shape}/${open}/${role}/mod-filter`,f,auth,"&mod=1",true); + } + } + } + const auth=`Bearer ${oidc[`comments-owner-${f.replicate}`]}`; + for(const tail of ["&pid=0","&limit=1","&conversation_id=other","&mod=1&mod=2","&unknown=1"])await run(`boundary/${tail}`,f,auth,tail,false); + for(const method of ["POST","PUT","OPTIONS"])await run(`boundary/${method}`,f,auth,"",false,method); + await run("boundary/cookie",f,auth,"",false,"GET",[["Cookie","x=y"]]); + await run("boundary/body",f,auth,"",false,"GET",[["Content-Length","2"]],"{}"); + await run("boundary/bad-auth",f,"Bearer malformed","",false); + await run("boundary/xid",f,`Bearer ${tokens[`xid-${f.zid}`]}`,"",false); + await run("boundary/missing",{capability:"4missing"},auth,"",false); + let off=0; + for(const c of cases){ + const response=await exchange({host:"polis-api-off",port:5100},requestBytes(c.method,c.target,c.headers,c.body),c.method==="HEAD"); + if(!response.toString("latin1").startsWith("HTTP/1.1 502"))throw Error(`off switch served ${c.id}`); + off++; + } + const failed=results.filter(r=>r.unexpectedFallback||r.unexpectedServe||(!r.fallback&&!r.equal)); + fs.writeFileSync("/artifacts/ptptois-recordings.json",JSON.stringify({records},null,2)+"\n"); + console.log(JSON.stringify({cases:cases.length,exact:results.filter(r=>r.equal).length,handbacks:results.filter(r=>r.fallback).length,off,dateRetries,failed},null,2)); + if(failed.length)process.exitCode=1; + }finally{await pool.end();} +} +main().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/queue-rs/polis-api/conformance/ptptois-run.sh b/queue-rs/polis-api/conformance/ptptois-run.sh new file mode 100755 index 000000000..25abc265d --- /dev/null +++ b/queue-rs/polis-api/conformance/ptptois-run.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Record social participant rows under anonymous, participant and OIDC auth and +# compare complete Node/Rust HTTP bytes. Uses only the isolated generated stack. +# Usage: ptptois-run.sh [result.json], with unique project and P027 ports. +set -euo pipefail +root=$(cd "$(dirname "$0")/../../.." && pwd) +out=${1:-/dev/stdout} +here="$root/server/characterization" +# Require an explicitly named disposable project and three distinct loopback ports. +python3 - <<'CHECK' +import os,re +project=os.environ.get("COMPOSE_PROJECT_NAME", "") +assert re.fullmatch(r"[a-z][a-z0-9_-]{5,63}",project), "unique project required" +ports=[int(os.environ[k]) for k in ["POLIS_RECOVERY_PG_PORT","P027_HTTP_PORT","P027_CONTROL_PORT"]] +assert len(set(ports))==3 and all(55432<=p<=65535 for p in ports) +CHECK +export P027_POSTGRES_IMAGE=${P027_POSTGRES_IMAGE:-x54pca2-postgres:local} +compose=(docker compose -f "$here/compose.yml" -f "$root/queue-rs/polis-api/conformance/compose.yml" -f "$root/queue-rs/polis-api/conformance/participant-compose.yml" -f "$root/queue-rs/polis-api/conformance/ptptois-compose.yml") +if [[ -n $(docker ps -aq --filter "label=com.docker.compose.project=$COMPOSE_PROJECT_NAME") ]]; then + echo "project $COMPOSE_PROJECT_NAME already has containers" >&2 + exit 1 +fi +cleanup() { "${compose[@]}" logs --no-color server polis-api >"${out%.json}-services.log" 2>&1 || true; "${compose[@]}" --profile seed down -v --remove-orphans >/dev/null 2>&1 || true; } +trap cleanup EXIT INT TERM +ready() { + for _ in $(seq 60); do + if "${compose[@]}" exec -T server node -e "fetch('http://localhost:5001/ready',{signal:AbortSignal.timeout(3000)}).then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))" >/dev/null 2>&1; then + return 0 + fi + sleep 1 + done + echo "Node readiness deadline" >&2 + return 1 +} +"${compose[@]}" up -d --pull never postgres dynamodb oidc-simulator server driver +"${compose[@]}" restart server +ready +"${compose[@]}" exec -T driver node characterization/cli.cjs seed +"${compose[@]}" exec -T driver node /conformance/votes-read-seed.cjs +"${compose[@]}" exec -T driver node characterization/cli.cjs seed-comments +# Fresh caches on both sides before the first replayed request. +"${compose[@]}" restart server dynamodb +ready +"${compose[@]}" exec -T driver node -e 'fetch("http://server:5001/public-key").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/participant-public.pem",v.publicKey))' +"${compose[@]}" exec -T driver node -e 'fetch("https://oidc-simulator:3000/.well-known/jwks.json").then(r=>r.json()).then(v=>require("fs").writeFileSync("/artifacts/read-jwks.json",JSON.stringify(v)))' +"${compose[@]}" up -d --pull never polis-api polis-api-off +for _ in $(seq 60); do + if "${compose[@]}" exec -T driver node -e 'fetch("http://polis-api:5100/health").then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))'; then break; fi + sleep 1 +done +"${compose[@]}" exec -T driver node /conformance/ptptois-replay.cjs >"$out" diff --git a/queue-rs/polis-api/src/conversation_pages.rs b/queue-rs/polis-api/src/conversation_pages.rs new file mode 100644 index 000000000..f00aa5f77 --- /dev/null +++ b/queue-rs/polis-api/src/conversation_pages.rs @@ -0,0 +1,616 @@ +//! Independent, bounded static transport. Unsupported responses stay on Node. +use crate::{ + http::{Outgoing, Request}, + route::{self, App, Res}, +}; +use anyhow::{Context, Result, bail}; +use std::{ + net::{IpAddr, SocketAddr}, + time::Duration, +}; +use tokio::{ + io::{AsyncReadExt, AsyncWriteExt}, + net::TcpStream, + sync::Semaphore, +}; +#[path = "../../polis-contracts/src/conversation_pages.rs"] +mod contract; +use contract::{Page, Request as PageRequest}; +const MAX_BODY: usize = 16 * 1024; +const MAX_HEAD: usize = 8192; +const MAX_RENDER: usize = 65536; +const PRELOAD_MARKER: &str = "\"REPLACE_THIS_WITH_PRELOAD_DATA\""; +const META_MARKER: &str = ""; +pub struct Client { + host: String, + port: u16, + slots: Semaphore, + address: Option, +} +impl Client { + pub(crate) async fn from_env_for(switch: &str) -> Result> { + if std::env::var(switch).ok().as_deref() != Some("1") { + return Ok(None); + } + let host = std::env::var("STATIC_FILES_HOST").context("STATIC_FILES_HOST required")?; + let port = std::env::var("STATIC_FILES_PARTICIPATION_PORT") + .or_else(|_| std::env::var("STATIC_FILES_PORT")) + .unwrap_or_else(|_| "8080".into()) + .parse()?; + let mut client = Self::new(host, port)?; + if client.address.is_none() { + // Resolve once before listening. A cancelled request must never leave + // resolver work running in the runtime's shared blocking pool. + client.address = match tokio::time::timeout( + Duration::from_millis(75), + tokio::net::lookup_host((client.host.as_str(), client.port)), + ) + .await + { + Ok(Ok(mut addresses)) => addresses.next(), + _ => None, + }; + // Failure disables only this transport; other API routes can serve. + if client.address.is_none() { + eprintln!("{{\"event\":\"conversation_static_upstream_unavailable\"}}"); + } + } + Ok(Some(client)) + } + pub(crate) fn new(host: String, port: u16) -> Result { + if host.is_empty() + || host.len() > 253 + || !host + .bytes() + .all(|b| b.is_ascii_alphanumeric() || b".-".contains(&b)) + || port == 0 + { + bail!("invalid static upstream"); + } + let address = host + .parse::() + .ok() + .map(|ip| SocketAddr::new(ip, port)); + Ok(Self { + address, + host, + port, + slots: Semaphore::new(4), + }) + } + async fn fetch(&self, req: &Request) -> Result> { + let _permit = self.slots.try_acquire().context("static transport busy")?; + tokio::time::timeout(Duration::from_millis(75), self.fetch_inner(req)) + .await + .context("static response deadline")? + } + async fn fetch_inner(&self, req: &Request) -> Result> { + let mut socket = + TcpStream::connect(self.address.context("unresolved static upstream")?).await?; + let mut wire = format!( + "{} /index.html HTTP/1.1\r\nHost: {}:{}\r\nConnection: close\r\n", + req.method, self.host, self.port + ); + for name in ["user-agent", "accept", "accept-language", "accept-encoding"] { + if let Some(value) = req.headers.get(name) { + wire.push_str(&format!("{name}: {value}\r\n")); + } + } + wire.push_str("\r\n"); + socket.write_all(wire.as_bytes()).await?; + let mut bytes = Vec::new(); + let mut buf = [0; MAX_HEAD + MAX_BODY]; + let mut read_ends = Vec::new(); + loop { + let n = socket.read(&mut buf).await?; + if n == 0 { + break; + } + bytes.extend_from_slice(&buf[..n]); + read_ends.push(bytes.len()); + if bytes.len() > MAX_HEAD + MAX_BODY { + bail!("static response too large"); + } + } + let end = bytes + .windows(4) + .position(|s| s == b"\r\n\r\n") + .context("incomplete static head")? + + 4; + if end > MAX_HEAD { + bail!("static head too large"); + } + let mut headers = [httparse::EMPTY_HEADER; 64]; + let mut parsed = httparse::Response::new(&mut headers); + if !parsed.parse(&bytes)?.is_complete() || parsed.code != Some(200) { + bail!("unsupported static status"); + } + let values = |name: &str| { + parsed + .headers + .iter() + .filter(|h| h.name.eq_ignore_ascii_case(name)) + .map(|h| h.value) + .collect::>() + }; + if !values("transfer-encoding").is_empty() || !values("content-encoding").is_empty() { + bail!("unsupported static encoding"); + } + let length = values("content-length"); + if length.len() != 1 { + bail!("static length required"); + } + let length = std::str::from_utf8(length[0])?.parse::()?; + if length > MAX_BODY { + bail!("static body too large"); + } + let body = &bytes[end..]; + if req.method == "HEAD" { + if !body.is_empty() { + bail!("unexpected HEAD body"); + } + return Ok(Vec::new()); + } + if read_ends.iter().filter(|&&at| at > end).count() > 1 { + bail!("segmented static body"); + } + if body.len() != length || !body.is_ascii() { + bail!("unsupported static body"); + } + Ok(body.to_vec()) + } +} + +pub fn page(path: &str) -> Option<(Page, &str)> { + let (page, rest) = if let Some(r) = path.strip_prefix("/explore/") { + (Page::Explore, r) + } else if let Some(r) = path.strip_prefix("/share/") { + (Page::Share, r) + } else if let Some(r) = path.strip_prefix("/summary/") { + (Page::Summary, r) + } else if let Some(r) = path.strip_prefix("/ot/") { + (Page::OneTime, r) + } else { + (Page::Conversation, path.strip_prefix('/')?) + }; + let n = rest.bytes().take_while(u8::is_ascii_alphanumeric).count(); + (n >= 2 && rest.as_bytes()[0].is_ascii_digit()).then_some((page, &rest[..n])) +} +pub fn matches(path: &str) -> bool { + page(path).is_some() +} +pub fn parse(app: &App, req: &Request) -> Option { + let (page, cid) = page(req.path())?; + if app.conversation_pages[page.index()].is_none() + || app.conversation_page_dbs[page.index()].is_none() + || !crate::admin_page::admitted(req) + || cid.len() > 100 + { + return None; + } + let ua = req.headers.get("user-agent").unwrap_or_default(); + if ua + .as_bytes() + .windows(6) + .any(|w| w.starts_with(b"MSIE ") && b"234567".contains(&w[5])) + { + return None; + } + Some(PageRequest { + page, + conversation_id: cid.into(), + path: req.path().into(), + head_only: req.method == "HEAD", + }) +} +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 1, + acquire_timeout: Duration::from_millis(15), + statement_timeout: Duration::from_millis(50), + max_lifetime: Duration::from_secs(300), + } +} +/// ASCII-only admission keeps JS string and stream offsets identical. +fn entity(s: &str) -> String { + s.replace('&', "&") + .replace('<', "<") + .replace('>', ">") + .replace('\"', """) + .replace('\'', "'") +} +fn replace(chunks: Vec>, marker: &str, replacement: &str) -> Option>> { + let mut carry = String::new(); + let mut out = Vec::new(); + let mut total = 0; + for chunk in chunks { + carry.push_str(std::str::from_utf8(&chunk).ok()?); + let mut rest = carry.as_str(); + let mut prefix = String::new(); + while let Some(at) = rest.to_ascii_lowercase().find(&marker.to_ascii_lowercase()) { + if total + prefix.len() + at + replacement.len() > MAX_RENDER { + return None; + } + prefix.push_str(&rest[..at]); + prefix.push_str(replacement); + rest = &rest[at + marker.len()..]; + } + let tail = rest.len().min(marker.len()); + prefix.push_str(&rest[..rest.len() - tail]); + let suffix = rest[rest.len() - tail..].to_owned(); + total += prefix.len(); + if total > MAX_RENDER { + return None; + } + out.push(prefix.into_bytes()); + carry = suffix; + } + if total + carry.len() > MAX_RENDER { + return None; + } + out.push(carry.into_bytes()); + Some(out) +} +fn rewrite( + body: &[u8], + preload: &str, + topic: &str, + description: &str, +) -> Option<(contract::Response, Vec>)> { + if !preload.is_ascii() || !topic.is_ascii() || !description.is_ascii() { + return None; + } + let meta = format!( + "\n \n \n", + entity(topic), + entity(description) + ); + let first = replace(vec![body.to_vec()], PRELOAD_MARKER, preload)?; + let chunks = replace(first, META_MARKER, &meta)?; + let html = String::from_utf8(chunks.concat()).ok()?; + Some((contract::Response { html }, chunks)) +} +pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { + let Some(query) = parse(app, req) else { + return route::bad_gateway(); + }; + let Some(pool) = &app.conversation_page_dbs[query.page.index()] else { + return route::bad_gateway(); + }; + let cid = query.conversation_id; + let read = tokio::time::timeout( + Duration::from_millis(75), + pool.with(move |c| prepare(c, &cid)), + ) + .await; + let Ok(Ok(Some(prepared))) = read else { + return route::bad_gateway(); + }; + let ua = req.headers.get("user-agent").unwrap_or_default(); + if ua + .as_bytes() + .windows(6) + .any(|w| w.starts_with(b"MSIE ") && b"89".contains(&w[5])) + { + let Some(host) = req.headers.get("host").filter(|h| { + !h.is_empty() + && h.len() <= 255 + && h.bytes() + .all(|b| b.is_ascii_alphanumeric() || b".:-".contains(&b)) + }) else { + return route::bad_gateway(); + }; + return route::redirect(req, res, &format!("https://{host}/#{}", query.path)); + } + let Some(client) = &app.conversation_pages[query.page.index()] else { + return route::bad_gateway(); + }; + // The read lease is returned before beginning the independent static request. + let Ok(body) = client.fetch(req).await else { + return route::bad_gateway(); + }; + let Some((_response, chunks)) = rewrite( + &body, + &prepared.json, + &prepared.topic, + &prepared.description, + ) else { + return route::bad_gateway(); + }; + route::conversation_html(req, res, chunks, !app.dev_mode) +} + +pub struct Prepared { + pub json: String, + pub topic: String, + pub description: String, +} +pub fn prepare(c: &mut postgres::Client, cid: &str) -> Result> { + let size=c.query("SELECT coalesce(octet_length(topic),0)+coalesce(octet_length(description),0)+coalesce(octet_length(link_url),0)+coalesce(octet_length(parent_url),0)+coalesce(octet_length(bgcolor),0)+coalesce(octet_length(help_color),0)+coalesce(octet_length(help_bgcolor),0)+coalesce(octet_length(style_btn),0) FROM conversations c JOIN zinvites z ON c.zid=z.zid WHERE z.zinvite=$1 LIMIT 2",&[&cid])?; + if size.len() != 1 || size[0].try_get::<_, i32>(0)? > 8192 { + return Ok(None); + } + let Some(preload) = crate::conversation_preload::read(c, cid)? else { + return Ok(None); + }; + #[derive(serde::Serialize)] + struct Preload { + conversation: T, + } + let topic = preload.topic.clone().unwrap_or_default(); + let description = preload.description.clone().unwrap_or_default(); + let json = serde_json::to_string(&Preload { + conversation: preload, + })?; + if !json.is_ascii() || json.len() > 16384 { + return Ok(None); + } + Ok(Some(Prepared { + json, + topic, + description, + })) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::http::Headers; + async fn fixture(wire: Vec, delay: Duration) -> (Client, tokio::task::JoinHandle<()>) { + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let port = listener.local_addr().unwrap().port(); + let task = tokio::spawn(async move { + let (mut s, _) = listener.accept().await.unwrap(); + let mut b = [0; 4096]; + let n = s.read(&mut b).await.unwrap(); + assert!(String::from_utf8_lossy(&b[..n]).contains(" /index.html HTTP/1.1\r\n")); + tokio::time::sleep(delay).await; + s.write_all(&wire).await.ok(); + }); + (Client::new("127.0.0.1".into(), port).unwrap(), task) + } + fn req(method: &str) -> Request { + Request { + method: method.into(), + target: "/2test".into(), + headers: Headers::default(), + body: vec![], + } + } + #[test] + fn path_prefix_and_fixed_upstream() { + for p in ["/2x", "/2x/suffix", "/2xSuffix", "/2x-"] { + assert!(matches(p)); + } + for p in ["/2", "/x2", "/", "/X/2x", "/prefix/2x"] { + assert!(!matches(p)); + } + for host in ["", "127.0.0.1/path", "user@host", "host\r\nInjected: x"] { + assert!(Client::new(host.into(), 8080).is_err()); + } + } + #[test] + fn stream_replacement_is_case_insensitive_literal_and_bounded() { + let document = format!( + "begin{}{}end", + PRELOAD_MARKER.to_lowercase(), + "a".repeat(80) + ); + let (r, chunks) = rewrite(document.as_bytes(), "{\"x\":1}", "&'\"", "d").unwrap(); + assert_eq!(r.html, format!("begin{{\"x\":1}}{}end", "a".repeat(80))); + assert_eq!(chunks.concat(), r.html.as_bytes()); + assert_eq!(entity("&'\""), "<t>&'""); + assert!( + rewrite( + PRELOAD_MARKER.repeat(20).as_bytes(), + &"a".repeat(16384), + "", + "" + ) + .is_none() + ); + assert!(rewrite(b"short", "\"雪\"", "", "").is_none()); + } + #[tokio::test] + async fn fixed_body_and_head_are_bounded() { + for (method, wire, expected) in [ + ( + "GET", + b"HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nabc".to_vec(), + b"abc".to_vec(), + ), + ( + "HEAD", + b"HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\n".to_vec(), + vec![], + ), + ] { + let (c, t) = fixture(wire, Duration::ZERO).await; + assert_eq!(c.fetch(&req(method)).await.unwrap(), expected); + t.await.unwrap(); + } + } + #[tokio::test] + async fn uncertain_static_responses_fall_back() { + for wire in [ + "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n", + "HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\nabc", + "HTTP/1.1 200 OK\r\nContent-Length: 1000000\r\n\r\n", + "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n", + "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Length: 0\r\n\r\n", + "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Encoding: gzip\r\n\r\n", + ] { + let (c, t) = fixture(wire.as_bytes().to_vec(), Duration::ZERO).await; + assert!(c.fetch(&req("GET")).await.is_err(), "{wire}"); + t.await.unwrap(); + } + } + #[tokio::test] + async fn slow_and_saturated_static_transport_sheds_itself() { + let (c, t) = fixture( + b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n".to_vec(), + Duration::from_millis(150), + ) + .await; + let permit = c.slots.acquire_many(4).await.unwrap(); + assert!( + c.fetch(&req("GET")) + .await + .unwrap_err() + .to_string() + .contains("busy") + ); + drop(permit); + assert!( + c.fetch(&req("GET")) + .await + .unwrap_err() + .to_string() + .contains("deadline") + ); + assert_eq!(c.slots.available_permits(), 4); + t.await.unwrap(); + } + #[tokio::test] + async fn fragmented_static_body_is_not_a_single_write_contract() { + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let client = + Client::new("127.0.0.1".into(), listener.local_addr().unwrap().port()).unwrap(); + let task = tokio::spawn(async move { + let (mut s, _) = listener.accept().await.unwrap(); + let mut b = [0; 4096]; + let n = s.read(&mut b).await.unwrap(); + assert!(n > 0); + s.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 6\r\n\r\nabc") + .await + .unwrap(); + tokio::time::sleep(Duration::from_millis(15)).await; + s.write_all(b"def").await.unwrap(); + }); + assert!( + client + .fetch(&req("GET")) + .await + .unwrap_err() + .to_string() + .contains("segmented") + ); + task.await.unwrap(); + } + #[tokio::test] + async fn unresolved_static_host_is_a_local_handoff() { + let client = Client::new("unresolved.invalid".into(), 8080).unwrap(); + assert!( + client + .fetch(&req("GET")) + .await + .unwrap_err() + .to_string() + .contains("unresolved") + ); + assert_eq!(client.slots.available_permits(), 4); + } +} + +#[cfg(all(test, feature = "db-tests"))] +mod db_tests { + use super::*; + #[tokio::test] + async fn page_preserves_preload_and_bounds_and_sheds_locked_reads() { + let url = std::env::var("POLIS_API_TEST_DATABASE_URL").unwrap(); + let schema = format!("conversation_page_test_{}", std::process::id()); + let setup_url = url.clone(); + let setup_schema = schema.clone(); + tokio::task::spawn_blocking(move||{ + let mut c=postgres::Client::connect(&setup_url,postgres::NoTls).unwrap(); + c.batch_execute(&format!("CREATE SCHEMA {setup_schema}; CREATE TABLE {setup_schema}.conversations(zid integer,topic text,description text,created bigint,link_url text,parent_url text,vis_type integer,write_type integer,importance_enabled boolean,help_type integer,bgcolor text,help_color text,help_bgcolor text,style_btn text,auth_opt_allow_3rdparty boolean); CREATE TABLE {setup_schema}.zinvites(zid integer,zinvite text); INSERT INTO {setup_schema}.conversations VALUES(1,NULL,NULL,9223372036854775807,NULL,NULL,0,1,false,1,NULL,NULL,NULL,NULL,NULL),(2,'雪','public',NULL,'link','parent',2,0,true,0,'blue','red','white','round',false); INSERT INTO {setup_schema}.zinvites VALUES(1,'first'),(2,'second'),(1,'ambiguous'),(2,'ambiguous');")).unwrap(); + }).await.unwrap(); + let make_pool = || { + let mut c: postgres::Config = url.parse().unwrap(); + c.options(&format!("-c search_path={schema}")); + crate::db::Pool::new( + polis_queue_adapter::jobs::transport::Connector::Plain(Box::new(c)), + pool_limits(), + ) + }; + let pool = make_pool(); + let participation = make_pool(); + let first = pool.with(|c| prepare(c, "first")).await.unwrap().unwrap(); + assert!(first.json.contains("9223372036854775807")); + assert!(first.topic.is_empty() && first.description.is_empty()); + assert!(pool.with(|c| prepare(c, "second")).await.unwrap().is_none()); + for cid in ["missing", "ambiguous"] { + assert!(pool.with(move |c| prepare(c, cid)).await.unwrap().is_none()); + } + let (ready_tx, ready_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = std::sync::mpsc::channel(); + let lock_url = url.clone(); + let lock_schema = schema.clone(); + let locked = tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&lock_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!( + "BEGIN; LOCK TABLE {lock_schema}.conversations IN ACCESS EXCLUSIVE MODE" + )) + .unwrap(); + ready_tx.send(()).unwrap(); + release_rx + .recv_timeout(std::time::Duration::from_secs(5)) + .unwrap(); + c.batch_execute("ROLLBACK").unwrap(); + }); + ready_rx.await.unwrap(); + let stalled = pool.clone(); + let task = tokio::spawn(async move { stalled.with(|c| prepare(c, "first")).await }); + assert!(participation.ping().await); + assert!(task.await.unwrap().is_err()); + release_tx.send(()).unwrap(); + locked.await.unwrap(); + assert!(pool.with(|c| prepare(c, "first")).await.unwrap().is_some()); + let error = pool + .with(|c| Ok(c.batch_execute("DELETE FROM conversations")?)) + .await + .unwrap_err(); + assert!(format!("{error:#}").contains("read-only")); + tokio::task::spawn_blocking(move || { + drop(pool); + drop(participation); + let mut c = postgres::Client::connect(&url, postgres::NoTls).unwrap(); + c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) + .unwrap(); + }) + .await + .unwrap(); + } +} + +#[cfg(test)] +mod recorded_html_tests { + use super::*; + #[test] + fn unchanged_node_html_after_both_stream_replacements() { + #[derive(serde::Deserialize)] + struct Fixture { + id: String, + document: String, + preload: String, + topic: Option, + description: Option, + html: String, + } + let fixtures: Vec = serde_json::from_str(include_str!( + "../../polis-contracts/src/fixtures/conversation-pages.json" + )) + .unwrap(); + for f in fixtures { + let (response, chunks) = rewrite( + f.document.as_bytes(), + &f.preload, + f.topic.as_deref().unwrap_or_default(), + f.description.as_deref().unwrap_or_default(), + ) + .unwrap(); + assert_eq!(response.html, f.html, "{}", f.id); + assert_eq!(chunks.concat(), f.html.as_bytes(), "{}", f.id); + } + } +} diff --git a/queue-rs/polis-api/src/link_pages.rs b/queue-rs/polis-api/src/link_pages.rs new file mode 100644 index 000000000..daec7783c --- /dev/null +++ b/queue-rs/polis-api/src/link_pages.rs @@ -0,0 +1,115 @@ +//! Public conversation links, resolved per request on independently bounded +//! read-only pools. Missing, ambiguous or expensive reads hand back to Node. +use crate::{ + http::{Outgoing, Request}, + route::{self, App, Res}, +}; +#[path = "../../polis-contracts/src/link_pages.rs"] +mod contract; +use contract::{Page, Response}; +pub fn page(path: &str) -> Option { + if path.starts_with("/iip/") { + Some(Page::Participation) + } else if path.starts_with("/iim/") { + Some(Page::Moderation) + } else { + None + } +} +pub fn matches(path: &str) -> bool { + page(path).is_some() +} +pub fn parse(app: &App, req: &Request) -> Option { + let page = page(req.path())?; + let pool = match page { + Page::Participation => &app.iip_db, + Page::Moderation => &app.iim_db, + }; + if pool.is_none() + || !matches!(req.method.as_str(), "GET" | "HEAD") + || !req.body.is_empty() + || req.headers.get("transfer-encoding").is_some() + || req.headers.get("content-length").is_some_and(|s| s != "0") + || req.headers.get("cookie").is_some() + || req.headers.get("authorization").is_some() + || req.query().is_some_and(|q| !q.is_empty()) + { + return None; + } + let cid = req.path()[5..] + .strip_suffix('/') + .unwrap_or(&req.path()[5..]); + if cid.is_empty() || cid.len() > 100 || !cid.bytes().all(|b| b.is_ascii_alphanumeric()) { + return None; + } + Some(contract::Request { + page, + conversation_id: cid.into(), + }) +} +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 1, + acquire_timeout: std::time::Duration::from_millis(15), + statement_timeout: std::time::Duration::from_millis(50), + max_lifetime: std::time::Duration::from_secs(300), + } +} +pub fn read( + c: &mut postgres::Client, + query: &contract::Request, +) -> anyhow::Result> { + let Some(zid) = crate::db::zid_for_conversation_id(c, &query.conversation_id)? else { + return Ok(None); + }; + if zid <= 0 { + return Ok(None); + } + if query.page == Page::Participation { + return Ok(Some(Response::participation(&query.conversation_id))); + } + // Bound transfer before allocating the source strings. Node's bigint comes + // through pg as text, including values outside JavaScript's integer range. + let rows = c.query("SELECT topic,description,created FROM conversations WHERE zid=$1 AND coalesce(octet_length(topic),0)+coalesce(octet_length(description),0)<=16384 LIMIT 2", &[&zid])?; + if rows.len() != 1 { + return Ok(None); + } + let row = &rows[0]; + let topic: Option = row.try_get(0)?; + let description: Option = row.try_get(1)?; + let created: Option = row.try_get(2)?; + let title = topic.filter(|s| !s.is_empty()).unwrap_or_else(|| { + created + .map(|n| n.to_string()) + .unwrap_or_else(|| "null".into()) + }); + Ok(Some(Response::moderation( + &query.conversation_id, + &title, + description.as_deref(), + ))) +} +pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { + let Some(query) = parse(app, req) else { + return route::bad_gateway(); + }; + let pool = match query.page { + Page::Participation => &app.iip_db, + Page::Moderation => &app.iim_db, + }; + let Some(pool) = pool else { + return route::bad_gateway(); + }; + let result = tokio::time::timeout( + std::time::Duration::from_millis(75), + pool.with(move |c| read(c, &query)), + ) + .await; + match result { + Ok(Ok(Some(response))) => route::html(req, res, &response.html), + _ => route::bad_gateway(), + } +} +#[cfg(all(test, feature = "db-tests"))] +#[path = "link_pages_tests.rs"] +mod tests; diff --git a/queue-rs/polis-api/src/link_pages_tests.rs b/queue-rs/polis-api/src/link_pages_tests.rs new file mode 100644 index 000000000..35ee23b00 --- /dev/null +++ b/queue-rs/polis-api/src/link_pages_tests.rs @@ -0,0 +1,118 @@ +use super::*; +#[tokio::test] +async fn rows_bounds_and_isolated_lock_pressure() { + let url = std::env::var("POLIS_API_TEST_DATABASE_URL").unwrap(); + let schema = format!("link_pages_test_{}", std::process::id()); + let setup_url = url.clone(); + let setup_schema = schema.clone(); + tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&setup_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!("CREATE SCHEMA {setup_schema}; SET search_path={setup_schema}; CREATE TABLE zinvites(zid integer,zinvite text); CREATE UNIQUE INDEX ON zinvites(zinvite); CREATE TABLE conversations(zid integer,topic text,description text,created bigint); INSERT INTO zinvites VALUES(1,'4fixture'),(2,'4empty'),(3,'4large'),(4,'4orphan'); INSERT INTO conversations VALUES(1,'topic','🙂 & text',1700000000000),(2,'',NULL,9223372036854775807),(3,repeat('x',16385),NULL,0);")).unwrap(); + }).await.unwrap(); + let make_pool = || { + let mut c: postgres::Config = url.parse().unwrap(); + c.options(&format!("-c search_path={schema}")); + crate::db::Pool::new( + polis_queue_adapter::jobs::transport::Connector::Plain(Box::new(c)), + pool_limits(), + ) + }; + let pool = make_pool(); + let participation = make_pool(); + for (cid, title, desc) in [ + ("4fixture", "topic", Some("🙂 & text")), + ("4empty", "9223372036854775807", None), + ] { + assert_eq!( + pool.with(move |c| read( + c, + &contract::Request { + page: Page::Moderation, + conversation_id: cid.into() + } + )) + .await + .unwrap(), + Some(Response::moderation(cid, title, desc)) + ); + } + for cid in ["4fixture", "4empty", "4large", "4orphan"] { + assert_eq!( + pool.with(move |c| read( + c, + &contract::Request { + page: Page::Participation, + conversation_id: cid.into() + } + )) + .await + .unwrap(), + Some(Response::participation(cid)) + ); + } + for cid in ["4large", "4orphan", "4absent"] { + assert!( + pool.with(move |c| read( + c, + &contract::Request { + page: Page::Moderation, + conversation_id: cid.into() + } + )) + .await + .unwrap() + .is_none() + ); + } + let (ready_tx, ready_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = std::sync::mpsc::channel(); + let lock_url = url.clone(); + let lock_schema = schema.clone(); + let locked = tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&lock_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!( + "BEGIN; LOCK TABLE {lock_schema}.conversations IN ACCESS EXCLUSIVE MODE" + )) + .unwrap(); + ready_tx.send(()).unwrap(); + release_rx + .recv_timeout(std::time::Duration::from_secs(5)) + .unwrap(); + c.batch_execute("ROLLBACK").unwrap(); + }); + ready_rx.await.unwrap(); + let stalled = pool.clone(); + let task = tokio::spawn(async move { + stalled + .with(|c| { + read( + c, + &contract::Request { + page: Page::Moderation, + conversation_id: "4fixture".into(), + }, + ) + }) + .await + }); + assert!(participation.ping().await); + assert!(task.await.unwrap().is_err()); + release_tx.send(()).unwrap(); + locked.await.unwrap(); + assert!( + pool.with(|c| Ok(c.batch_execute("DELETE FROM conversations")?)) + .await + .unwrap_err() + .to_string() + .contains("read-only") + ); + tokio::task::spawn_blocking(move || { + drop(pool); + drop(participation); + let mut c = postgres::Client::connect(&url, postgres::NoTls).unwrap(); + c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) + .unwrap(); + }) + .await + .unwrap(); +} diff --git a/queue-rs/polis-api/src/main.rs b/queue-rs/polis-api/src/main.rs index a9347274c..82f682170 100644 --- a/queue-rs/polis-api/src/main.rs +++ b/queue-rs/polis-api/src/main.rs @@ -15,6 +15,7 @@ mod compress; mod config; mod connection; mod contexts; +mod conversation_pages; mod conversation_preload; mod conversation_stats; mod cors; @@ -49,15 +50,19 @@ mod integrate_page; mod js; mod legacy_conversations; mod legacy_pca; +mod link_pages; mod lru; mod metadata_answers; #[allow(dead_code)] #[rustfmt::skip] #[path = "../../polis-contracts/src/votes.rs"] mod votes; +mod math_bundle; +mod math_membership; mod metadata_choices; mod metadata_questions; mod metadata_read; +mod my_invites_csv; mod negotiate; mod next_comment; mod ops_catchall; @@ -66,8 +71,10 @@ mod ops_whoami; mod other_conversations_page; mod owner; mod params; +mod participants_read; mod participation_read; mod pca; +mod ptptois; mod recent_activity; mod recent_started; mod reports_read; @@ -106,6 +113,25 @@ use std::sync::{Arc, atomic::Ordering}; async fn health(app: &route::App) -> Outgoing { let reachable = app.db.ping().await; let mut body = js::Obj::new(); + for (i, name) in [ + "conversationPage", + "explorePage", + "sharePage", + "summaryPage", + "oneTimePage", + ] + .into_iter() + .enumerate() + { + body.set( + &format!("{name}Served"), + js::Js::Num(app.conversation_page_served[i].load(Ordering::Relaxed) as f64), + ); + body.set( + &format!("{name}Fallback"), + js::Js::Num(app.conversation_page_fallback[i].load(Ordering::Relaxed) as f64), + ); + } body.set( "status", js::Js::Str(if reachable { "ok" } else { "degraded" }.into()), @@ -270,6 +296,54 @@ async fn health(app: &route::App) -> Outgoing { "metadataAnswersFallback", js::Js::Num(app.metadata_answers_fallback.load(Ordering::Relaxed) as f64), ); + for (name, counter) in [ + ("iipServed", &app.iip_served), + ("iipFallback", &app.iip_fallback), + ("iimServed", &app.iim_served), + ("iimFallback", &app.iim_fallback), + ] { + body.set(name, js::Js::Num(counter.load(Ordering::Relaxed) as f64)); + } + body.set( + "participantsReadServed", + js::Js::Num(app.participants_read_served.load(Ordering::Relaxed) as f64), + ); + body.set( + "participantsReadFallback", + js::Js::Num(app.participants_read_fallback.load(Ordering::Relaxed) as f64), + ); + body.set( + "ptptoisServed", + js::Js::Num(app.ptptois_served.load(Ordering::Relaxed) as f64), + ); + body.set( + "ptptoisFallback", + js::Js::Num(app.ptptois_fallback.load(Ordering::Relaxed) as f64), + ); + body.set( + "myInvitesCsvServed", + js::Js::Num(app.my_invites_csv_served.load(Ordering::Relaxed) as f64), + ); + body.set( + "myInvitesCsvFallback", + js::Js::Num(app.my_invites_csv_fallback.load(Ordering::Relaxed) as f64), + ); + body.set( + "bidServed", + js::Js::Num(app.bid_served.load(Ordering::Relaxed) as f64), + ); + body.set( + "bidFallback", + js::Js::Num(app.bid_fallback.load(Ordering::Relaxed) as f64), + ); + body.set( + "locationsServed", + js::Js::Num(app.locations_served.load(Ordering::Relaxed) as f64), + ); + body.set( + "locationsFallback", + js::Js::Num(app.locations_fallback.load(Ordering::Relaxed) as f64), + ); body.set( "votesReadServed", js::Js::Num(app.votes_read_served.load(Ordering::Relaxed) as f64), @@ -592,6 +666,11 @@ async fn dispatch_at_clock( | domain_whitelist::PATH | metadata_questions::PATH | treevite_waves::PATH + | math_membership::BID_PATH + | math_membership::LOCATIONS_PATH + | participants_read::PATH + | ptptois::PATH + | my_invites_csv::PATH | participation_read::PATH | treevite_csv::PATH | treevite_invites::PATH @@ -613,6 +692,8 @@ async fn dispatch_at_clock( | votes_read::PATH | votes_read::ME_PATH | metadata_answers::PATH => route::handle(app, req).await, + path if conversation_pages::matches(path) => route::handle(app, req).await, + path if link_pages::matches(path) => route::handle(app, req).await, path if delphi_result_read::matches(path) => route::handle(app, req).await, path if ops_page::matches(path) => route::handle(app, req).await, path if ops_catchall::matches(path) => route::handle(app, req).await, @@ -637,6 +718,30 @@ async fn main() -> Result<()> { let connector = config::db_connector()?; let pool = db::Pool::new(connector, cfg.pool.clone()); let mut state = route::App::new(&cfg, pool); + for (i, switch) in [ + "POLIS_API_CONVERSATION_PAGE_READS", + "POLIS_API_EXPLORE_PAGE_READS", + "POLIS_API_SHARE_PAGE_READS", + "POLIS_API_SUMMARY_PAGE_READS", + "POLIS_API_ONE_TIME_PAGE_READS", + ] + .into_iter() + .enumerate() + { + if std::env::var(switch).ok().as_deref() == Some("1") { + let dsn = std::env::var("POLIS_API_CONVERSATION_PAGES_DATABASE_URL") + .context("POLIS_API_CONVERSATION_PAGES_DATABASE_URL required")?; + let read_dsn = std::env::var("READ_ONLY_DATABASE_URL") + .ok() + .filter(|s| !s.is_empty()) + .unwrap_or(dsn); + state.conversation_page_dbs[i] = Some(db::Pool::new( + config::connector_for_dsn(&read_dsn, "polis-api-conversation-page/1")?, + conversation_pages::pool_limits(), + )); + state.conversation_pages[i] = conversation_pages::Client::from_env_for(switch).await?; + } + } if std::env::var("POLIS_API_COMMENT_READS").ok().as_deref() == Some("1") { state.read_oidc = hybrid_read::Oidc::from_env()?; let admins = std::env::var("ADMIN_UIDS") @@ -1037,6 +1142,115 @@ async fn main() -> Result<()> { )); state.read_oidc = hybrid_read::Oidc::from_env()?; } + for (switch, slot, name) in [ + ("POLIS_API_IIP_READS", &mut state.iip_db, "polis-api-iip/1"), + ("POLIS_API_IIM_READS", &mut state.iim_db, "polis-api-iim/1"), + ] { + if std::env::var(switch).ok().as_deref() == Some("1") { + let dsn = std::env::var("POLIS_API_LINK_PAGES_DATABASE_URL") + .context("POLIS_API_LINK_PAGES_DATABASE_URL required")?; + *slot = Some(db::Pool::new( + config::connector_for_dsn(&dsn, name)?, + link_pages::pool_limits(), + )); + } + } + if std::env::var("POLIS_API_PARTICIPANTS_READS") + .ok() + .as_deref() + == Some("1") + { + let dsn = std::env::var("POLIS_API_PARTICIPANTS_DATABASE_URL") + .context("POLIS_API_PARTICIPANTS_DATABASE_URL required")?; + let read_dsn = std::env::var("READ_ONLY_DATABASE_URL") + .ok() + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| dsn.clone()); + state.participants_read_db = Some(db::Pool::new( + config::connector_for_dsn(&read_dsn, "polis-api-participants/1")?, + participants_read::pool_limits(), + )); + state.participants_read_auth_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-participants-auth/1")?, + participants_read::pool_limits(), + )); + state.read_oidc = hybrid_read::Oidc::from_env()?; + } + if std::env::var("POLIS_API_PTPTOIS_READS").ok().as_deref() == Some("1") { + let dsn = std::env::var("POLIS_API_PTPTOIS_DATABASE_URL") + .context("POLIS_API_PTPTOIS_DATABASE_URL required")?; + let read_dsn = std::env::var("READ_ONLY_DATABASE_URL") + .ok() + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| dsn.clone()); + state.ptptois_db = Some(db::Pool::new( + config::connector_for_dsn(&read_dsn, "polis-api-ptptois/1")?, + ptptois::pool_limits(), + )); + state.ptptois_auth_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-ptptois-auth/1")?, + ptptois::pool_limits(), + )); + state.read_oidc = hybrid_read::Oidc::from_env()?; + state.legacy_admin_uids = recent_started::admin_uids( + &std::env::var("ADMIN_UIDS").unwrap_or_else(|_| "[]".into()), + )?; + } + if std::env::var("POLIS_API_MY_INVITES_CSV_READS") + .ok() + .as_deref() + == Some("1") + { + let dsn = std::env::var("POLIS_API_MY_INVITES_CSV_DATABASE_URL") + .context("POLIS_API_MY_INVITES_CSV_DATABASE_URL required")?; + let read_dsn = std::env::var("READ_ONLY_DATABASE_URL") + .ok() + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| dsn.clone()); + state.my_invites_csv_db = Some(db::Pool::new( + config::connector_for_dsn(&read_dsn, "polis-api-my-invites-csv/1")?, + my_invites_csv::pool_limits(), + )); + state.my_invites_csv_auth_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-my-invites-csv-auth/1")?, + my_invites_csv::pool_limits(), + )); + state.read_oidc = hybrid_read::Oidc::from_env()?; + } + if std::env::var("POLIS_API_BID_READS").ok().as_deref() == Some("1") { + let dsn = std::env::var("POLIS_API_BID_DATABASE_URL") + .context("POLIS_API_BID_DATABASE_URL required")?; + let read_dsn = std::env::var("READ_ONLY_DATABASE_URL") + .ok() + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| dsn.clone()); + state.bid_db = Some(db::Pool::new( + config::connector_for_dsn(&read_dsn, "polis-api-bid/1")?, + math_membership::pool_limits(), + )); + state.bid_auth_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-bid-auth/1")?, + math_membership::pool_limits(), + )); + state.read_oidc = hybrid_read::Oidc::from_env()?; + } + if std::env::var("POLIS_API_LOCATIONS_READS").ok().as_deref() == Some("1") { + let dsn = std::env::var("POLIS_API_LOCATIONS_DATABASE_URL") + .context("POLIS_API_LOCATIONS_DATABASE_URL required")?; + let read_dsn = std::env::var("READ_ONLY_DATABASE_URL") + .ok() + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| dsn.clone()); + state.locations_db = Some(db::Pool::new( + config::connector_for_dsn(&read_dsn, "polis-api-locations/1")?, + math_membership::pool_limits(), + )); + state.locations_auth_db = Some(db::Pool::new( + config::connector_for_dsn(&dsn, "polis-api-locations-auth/1")?, + math_membership::pool_limits(), + )); + state.read_oidc = hybrid_read::Oidc::from_env()?; + } if std::env::var("POLIS_API_VOTES_READS").ok().as_deref() == Some("1") { let dsn = std::env::var("POLIS_API_VOTES_READ_DATABASE_URL") .context("POLIS_API_VOTES_READ_DATABASE_URL required")?; diff --git a/queue-rs/polis-api/src/math_bundle.rs b/queue-rs/polis-api/src/math_bundle.rs new file mode 100644 index 000000000..6b01d812b --- /dev/null +++ b/queue-rs/polis-api/src/math_bundle.rs @@ -0,0 +1,195 @@ +//! One coherent math generation, cached as a whole for three seconds. +use crate::{db::Pool, lru::Lru}; +use serde::Deserialize; +use std::sync::{Arc, Mutex}; +#[derive(Debug, Clone, Deserialize, Default)] +pub struct Base { + #[serde(default)] + pub id: Vec, +} +#[derive(Debug, Clone, Deserialize, Default)] +pub struct Group { + #[serde(default)] + pub members: Vec, +} +#[derive(Debug, Clone, Deserialize, Default)] +pub struct Main { + #[serde(rename = "base-clusters", default)] + pub base: Option, + #[serde(rename = "group-clusters", default)] + pub groups: Option>, +} +#[derive(Debug, Clone, Deserialize, Default)] +pub struct Mapping { + #[serde(rename = "bidToPid", default)] + pub rows: Option>>, +} +#[derive(Debug, Clone)] +pub struct Bundle { + pub tick: i64, + pub main: Main, + pub mapping: Mapping, +} +#[derive(Debug, Clone)] +pub enum Read { + Absent, + Incoherent(i64), + Complete(Bundle), +} +impl Read { + pub fn tick(&self) -> i64 { + match self { + Self::Absent => 0, + Self::Incoherent(t) => *t, + Self::Complete(b) => b.tick, + } + } +} +#[derive(Clone)] +struct Entry { + expiration: f64, + read: Arc, +} +pub struct Cache { + entries: Mutex>, +} +impl Cache { + pub fn new(enabled: bool) -> Self { + Self { + entries: Mutex::new(Lru::new(if enabled { 100 } else { 1 })), + } + } + pub async fn get(&self, pool: &Arc, zid: i32, env: &str) -> Option> { + let key = (env.to_owned(), zid); + if let Some(cached) = self + .entries + .lock() + .ok()? + .get(&key) + .filter(|e| e.expiration > crate::clock::now_ms()) + { + return Some(cached.read); + } + let namespace = env.to_owned(); + let read = Arc::new( + pool.with(move |c| read(c, zid, &namespace)) + .await + .ok() + .flatten()?, + ); + self.entries.lock().ok()?.set( + key, + Entry { + expiration: crate::clock::now_ms() + 3000.0, + read: read.clone(), + }, + ); + Some(read) + } +} +pub fn read(c: &mut postgres::Client, zid: i32, env: &str) -> anyhow::Result> { + let rows=c.query("SELECT m.math_tick,b.math_tick,p.math_tick,t.math_tick,CASE WHEN octet_length(m.data::text)<=65536 THEN m.data::text END,CASE WHEN octet_length(b.data::text)<=65536 THEN b.data::text END,p.data IS NOT NULL AND p.data<>'null'::jsonb FROM math_main m LEFT JOIN math_bidtopid b ON b.zid=m.zid AND b.math_env=m.math_env LEFT JOIN math_ptptstats p ON p.zid=m.zid AND p.math_env=m.math_env LEFT JOIN math_ticks t ON t.zid=m.zid AND t.math_env=m.math_env WHERE m.zid=$1 AND m.math_env=$2 LIMIT 2",&[&zid,&env])?; + if rows.len() > 1 { + return Ok(None); + } + let Some(r) = rows.first() else { + return Ok(Some(Read::Absent)); + }; + let tick = r.try_get::<_, Option>(0)?.unwrap_or(-1); + if tick.unsigned_abs() > 9007199254740991 { + return Ok(None); + } + let Some(main) = r.try_get::<_, Option>(4)? else { + return Ok(None); + }; + let mapping = r.try_get::<_, Option>(5)?; + let matching = (1..=3).all(|i| r.try_get::<_, Option>(i).ok() == Some(Some(tick))); + if !matching + || mapping.as_deref() == Some("null") + || !r.try_get::<_, Option>(6)?.unwrap_or(false) + { + return Ok(Some(Read::Incoherent(tick))); + } + let Some(mapping) = mapping else { + return Ok(None); + }; + let main: Main = match serde_json::from_str(&main) { + Ok(v) => v, + Err(_) => return Ok(None), + }; + let mapping: Mapping = match serde_json::from_str(&mapping) { + Ok(v) => v, + Err(_) => return Ok(None), + }; + Ok(Some(Read::Complete(Bundle { + tick, + main, + mapping, + }))) +} +impl Bundle { + pub fn bid(&self, pid: i32) -> Option { + let position = self + .mapping + .rows + .as_ref()? + .iter() + .position(|pids| pids.contains(&pid))?; + Some( + self.main + .base + .as_ref() + .and_then(|b| b.id.get(position)) + .copied() + .unwrap_or(-1), + ) + } + pub fn pids(&self, gid: i32) -> Option> { + let Some(group) = usize::try_from(gid) + .ok() + .and_then(|i| self.main.groups.as_ref()?.get(i)) + else { + return Some(vec![]); + }; + let mut pids = Vec::new(); + for bid in &group.members { + // JavaScript's assigned bid index keeps the final occurrence of an ID. + if let Some(i) = self + .main + .base + .as_ref() + .and_then(|b| b.id.iter().rposition(|x| x == bid)) + && let Some(more) = self.mapping.rows.as_ref().and_then(|r| r.get(i)) + { + if pids.len().checked_add(more.len())? > 16384 { + return None; + } + pids.extend_from_slice(more); + } + } + pids.sort_unstable(); + Some(pids) + } +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn repeated_group_members_cannot_multiply_the_pid_buffer_without_bound() { + let b = Bundle { + tick: 0, + main: Main { + base: Some(Base { id: vec![1] }), + groups: Some(vec![Group { + members: vec![1; 200], + }]), + }, + mapping: Mapping { + rows: Some(vec![vec![0; 200]]), + }, + }; + assert!(b.pids(0).is_none()); + assert_eq!(b.pids(-1), Some(vec![])); + } +} diff --git a/queue-rs/polis-api/src/math_membership.rs b/queue-rs/polis-api/src/math_membership.rs new file mode 100644 index 000000000..53930ccd7 --- /dev/null +++ b/queue-rs/polis-api/src/math_membership.rs @@ -0,0 +1,194 @@ +//! Bucket and location reads on independent, bounded, read-only pools. +use crate::{ + http::{Outgoing, Request}, + math_bundle::Read, + route::{self, App, Res}, +}; +#[path = "../../polis-contracts/src/math_membership.rs"] +mod contract; +use contract::Kind; +pub use contract::{BID_PATH, LOCATIONS_PATH}; +pub fn matches(path: &str) -> bool { + matches!(path, BID_PATH | LOCATIONS_PATH) +} +pub fn parse(app: &App, req: &Request) -> Option { + let kind = match req.path() { + BID_PATH => Kind::Bid, + LOCATIONS_PATH => Kind::Locations, + _ => return None, + }; + let enabled = match kind { + Kind::Bid => app.bid_db.is_some(), + Kind::Locations => app.locations_db.is_some(), + }; + if !enabled + || !matches!(req.method.as_str(), "GET" | "HEAD") + || !req.body.is_empty() + || req.headers.get("transfer-encoding").is_some() + || req.headers.get("content-length").is_some_and(|s| s != "0") + || req.headers.get("cookie").is_some() + { + return None; + } + if kind == Kind::Bid && req.headers.get("authorization").is_none() { + return None; + } + let raw = req.query()?; + if raw.len() > 4096 { + return None; + } + let (mut cid, mut tick, mut gid) = (None, None, None); + for (k, v) in url::form_urlencoded::parse(raw.as_bytes()) { + match k.as_ref() { + "conversation_id" if cid.is_none() => cid = Some(v.into_owned()), + "math_tick" if kind == Kind::Bid && tick.is_none() => { + let n = v.parse::().ok()?; + if n.to_string() != v { + return None; + } + tick = Some(n); + } + "gid" if kind == Kind::Locations && gid.is_none() => { + let n = v.parse::().ok()?; + if n.to_string() != v { + return None; + } + gid = Some(n); + } + _ => return None, + } + } + let cid = cid?; + if cid.is_empty() + || cid.len() > 100 + || !cid.bytes().all(|b| b.is_ascii_alphanumeric()) + || (kind == Kind::Locations && gid.is_none()) + { + return None; + } + Some(contract::Request { + kind, + conversation_id: cid, + math_tick: tick.unwrap_or(-1), + gid, + }) +} +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 1, + acquire_timeout: std::time::Duration::from_millis(15), + statement_timeout: std::time::Duration::from_millis(50), + max_lifetime: std::time::Duration::from_secs(300), + } +} +pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { + let Some(query) = parse(app, req) else { + return route::bad_gateway(); + }; + let (Some(pool), Some(auth_pool)) = (match query.kind { + Kind::Bid => (&app.bid_db, &app.bid_auth_db), + Kind::Locations => (&app.locations_db, &app.locations_auth_db), + }) else { + return route::bad_gateway(); + }; + let result = tokio::time::timeout(std::time::Duration::from_millis(75), async { + let identity = crate::hybrid_read::resolve_scoped( + req.headers.get("authorization"), + app.participant_verifier.as_deref(), + app.read_oidc.as_deref(), + auth_pool, + Some(&query.conversation_id), + ) + .await?; + let cid = query.conversation_id; + let zid = auth_pool + .with(move |c| crate::db::zid_for_conversation_id(c, &cid)) + .await + .ok() + .flatten()?; + if zid <= 0 { + return None; + } + let bundle = app.math_bundle.get(pool, zid, &app.math_env).await?; + let encoded = match query.kind { + Kind::Bid => { + let uid = identity.uid()?.0; + let pid = pool + .with(move |c| { + let rows = c.query( + "SELECT pid FROM participants WHERE zid=$1 AND uid=$2 LIMIT 2", + &[&zid, &uid], + )?; + Ok(if rows.len() == 1 { + Some(rows[0].try_get::<_, i32>(0)?) + } else { + None + }) + }) + .await + .ok() + .flatten()?; + if pid < 0 || bundle.tick() <= i64::from(query.math_tick) { + return None; + } + let bid = match bundle.as_ref() { + Read::Complete(b) => b.bid(pid), + _ => None, + }; + serde_json::to_string(&contract::Bid { bid }).ok()? + } + Kind::Locations => { + let pids = match bundle.as_ref() { + Read::Complete(b) if b.tick > -1 => b.pids(query.gid?)?, + _ => vec![], + }; + let response = pool + .with(move |c| locations(c, zid, &pids)) + .await + .ok() + .flatten()?; + serde_json::to_string(&response).ok()? + } + }; + crate::js::parse(&encoded).ok() + }) + .await; + match result { + Ok(Some(value)) => route::json(req, res, &value), + _ => route::bad_gateway(), + } +} +pub fn locations( + c: &mut postgres::Client, + zid: i32, + pids: &[i32], +) -> anyhow::Result>> { + if pids.len() > 16384 { + return Ok(None); + } + let rows = c.query( + "SELECT lat,lng FROM participant_locations WHERE zid=$1 AND pid=ANY($2) LIMIT 2", + &[&zid, &pids], + )?; + if rows.len() > 1 { + return Ok(None); + } + let mut out = Vec::new(); + for row in rows { + let lat: f64 = row.try_get(0)?; + let lng: f64 = row.try_get(1)?; + if !lat.is_finite() || !lng.is_finite() { + return Ok(None); + } + out.push(contract::Location { + lat: crate::wire::JsNumber::new(lat)?, + lng: crate::wire::JsNumber::new(lng)?, + n: 1, + }); + } + Ok(Some(out)) +} + +#[cfg(all(test, feature = "db-tests"))] +#[path = "math_membership_tests.rs"] +mod tests; diff --git a/queue-rs/polis-api/src/math_membership_tests.rs b/queue-rs/polis-api/src/math_membership_tests.rs new file mode 100644 index 000000000..3411b6718 --- /dev/null +++ b/queue-rs/polis-api/src/math_membership_tests.rs @@ -0,0 +1,129 @@ +use super::*; +use crate::math_bundle::{self, Cache, Read}; +#[tokio::test] +async fn whole_generations_cache_and_locations_are_isolated_and_bounded() { + let url = std::env::var("POLIS_API_TEST_DATABASE_URL").unwrap(); + let schema = format!("math_membership_test_{}", std::process::id()); + let setup_url = url.clone(); + let setup_schema = schema.clone(); + tokio::task::spawn_blocking(move||{ + let mut c=postgres::Client::connect(&setup_url,postgres::NoTls).unwrap(); + c.batch_execute(&format!("CREATE SCHEMA {setup_schema};SET search_path={setup_schema};CREATE TABLE math_main(zid integer,math_env text,data jsonb,math_tick bigint);CREATE TABLE math_bidtopid(zid integer,math_env text,data jsonb,math_tick bigint);CREATE TABLE math_ptptstats(zid integer,math_env text,data jsonb,math_tick bigint);CREATE TABLE math_ticks(zid integer,math_env text,math_tick bigint);CREATE TABLE participant_locations(zid integer,pid integer,lat double precision,lng double precision);INSERT INTO math_main VALUES(1,'a','{{\"base-clusters\":{{\"id\":[42,99]}},\"group-clusters\":[{{\"members\":[42]}}]}}',0);INSERT INTO math_bidtopid VALUES(1,'a','{{\"bidToPid\":[[0],[2]]}}',0);INSERT INTO math_ptptstats VALUES(1,'a','{{}}',0);INSERT INTO math_ticks VALUES(1,'a',0);INSERT INTO participant_locations VALUES(1,0,0,1e21),(1,2,10.125,-20.5);")).unwrap(); + }).await.unwrap(); + let make = || { + let mut c: postgres::Config = url.parse().unwrap(); + c.options(&format!("-c search_path={schema}")); + crate::db::Pool::new( + polis_queue_adapter::jobs::transport::Connector::Plain(Box::new(c)), + pool_limits(), + ) + }; + let pool = make(); + let participation = make(); + let cache = Cache::new(true); + let cold = cache.get(&pool, 1, "a").await.unwrap(); + let Read::Complete(b) = cold.as_ref() else { + panic!("coherent zero generation"); + }; + assert_eq!(b.tick, 0); + assert_eq!(b.bid(0), Some(42)); + assert_eq!(b.bid(2), Some(99)); + assert_eq!(b.bid(9), None); + assert_eq!(b.pids(0), Some(vec![0])); + assert!(b.pids(-1).unwrap().is_empty()); + assert!(matches!( + cache.get(&pool, 1, "other").await.unwrap().as_ref(), + Read::Absent + )); + let locations = pool.with(|c| locations(c, 1, &[0])).await.unwrap().unwrap(); + assert_eq!(locations.len(), 1); + assert_eq!(locations[0].lng.get(), 1e21); + assert!( + pool.with(|c| super::locations(c, 1, &[0, 2])) + .await + .unwrap() + .is_none() + ); + assert!( + pool.with(|c| super::locations(c, 1, &[])) + .await + .unwrap() + .unwrap() + .is_empty() + ); + let mutate_url = url.clone(); + let mutate_schema = schema.clone(); + tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&mutate_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!( + "SET search_path={mutate_schema};UPDATE math_main SET math_tick=1;" + )) + .unwrap(); + }) + .await + .unwrap(); + assert_eq!(cache.get(&pool, 1, "a").await.unwrap().tick(), 0); + assert!(matches!( + pool.with(|c| math_bundle::read(c, 1, "a")) + .await + .unwrap() + .unwrap(), + Read::Incoherent(1) + )); + // The source uses wall-clock expiry; exercise the actual three-second boundary. + tokio::time::sleep(std::time::Duration::from_millis(3001)).await; + assert!(matches!( + cache.get(&pool, 1, "a").await.unwrap().as_ref(), + Read::Incoherent(1) + )); + let (ready_tx, ready_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = std::sync::mpsc::channel(); + let lock_url = url.clone(); + let lock_schema = schema.clone(); + let lock = tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&lock_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!( + "BEGIN;LOCK TABLE {lock_schema}.math_main IN ACCESS EXCLUSIVE MODE" + )) + .unwrap(); + ready_tx.send(()).unwrap(); + release_rx + .recv_timeout(std::time::Duration::from_secs(5)) + .unwrap(); + c.batch_execute("ROLLBACK").unwrap(); + }); + ready_rx.await.unwrap(); + let stalled = pool.clone(); + let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); + let task = tokio::spawn(async move { + stalled + .with(move |c| { + entered_tx.send(()).unwrap(); + math_bundle::read(c, 1, "a") + }) + .await + }); + entered_rx.await.unwrap(); + assert!(participation.ping().await); + assert!(task.await.unwrap().is_err()); + release_tx.send(()).unwrap(); + lock.await.unwrap(); + assert!( + format!( + "{:#}", + pool.with(|c| Ok(c.batch_execute("DELETE FROM math_main")?)) + .await + .unwrap_err() + ) + .contains("read-only") + ); + tokio::task::spawn_blocking(move || { + drop(pool); + drop(participation); + let mut c = postgres::Client::connect(&url, postgres::NoTls).unwrap(); + c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) + .unwrap(); + }) + .await + .unwrap(); +} diff --git a/queue-rs/polis-api/src/my_invites_csv.rs b/queue-rs/polis-api/src/my_invites_csv.rs new file mode 100644 index 000000000..d50819c21 --- /dev/null +++ b/queue-rs/polis-api/src/my_invites_csv.rs @@ -0,0 +1,200 @@ +//! Participant-owned invitation CSV on independent, bounded read-only pools. +use crate::{ + http::{Outgoing, Request}, + route::{self, App, Res}, +}; +#[path = "../../polis-contracts/src/my_invites_csv.rs"] +mod contract; +pub use contract::PATH; +pub fn parse(app: &App, req: &Request) -> Option { + if app.my_invites_csv_db.is_none() + || req.path() != PATH + || req.headers.get("authorization").is_none() + || !matches!(req.method.as_str(), "GET" | "HEAD") + || !req.body.is_empty() + || req.headers.get("transfer-encoding").is_some() + || req.headers.get("content-length").is_some_and(|s| s != "0") + || req.headers.get("cookie").is_some() + { + return None; + } + let raw = req.query()?; + if raw.len() > 4096 { + return None; + } + let pairs = url::form_urlencoded::parse(raw.as_bytes()).collect::>(); + if pairs.len() != 1 || pairs[0].0 != "conversation_id" { + return None; + } + let cid = pairs[0].1.as_ref(); + if cid.is_empty() || cid.len() > 100 || !cid.bytes().all(|b| b.is_ascii_alphanumeric()) { + return None; + } + Some(contract::Request { + conversation_id: cid.into(), + }) +} +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 1, + acquire_timeout: std::time::Duration::from_millis(15), + statement_timeout: std::time::Duration::from_millis(50), + max_lifetime: std::time::Duration::from_secs(300), + } +} +pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { + let Some(query) = parse(app, req) else { + return route::bad_gateway(); + }; + let (Some(pool), Some(auth_pool)) = (&app.my_invites_csv_db, &app.my_invites_csv_auth_db) + else { + return route::bad_gateway(); + }; + let utc_dates = matches!(std::env::var("TZ").ok().as_deref(), Some("UTC" | "Etc/UTC")); + let result = tokio::time::timeout(std::time::Duration::from_millis(75), async { + let uid = crate::hybrid_read::resolve_scoped( + req.headers.get("authorization"), + app.participant_verifier.as_deref(), + app.read_oidc.as_deref(), + auth_pool, + Some(&query.conversation_id), + ) + .await? + .uid()?; + let cid = query.conversation_id; + let zid = auth_pool + .with(move |c| crate::db::zid_for_conversation_id(c, &cid)) + .await + .ok() + .flatten()?; + if zid <= 0 { + return None; + } + pool.with(move |c| read(c, zid, uid.0, utc_dates)) + .await + .ok() + .flatten() + }) + .await; + match result { + Ok(Some(response)) => { + let Some(stamp) = timestamp(crate::clock::now_ms() as u64) else { + return route::bad_gateway(); + }; + route::csv_attachment( + req, + res, + &format!( + "my_treevite_invites_{}_{}.csv", + response.conversation_id, stamp + ), + response.csv, + ) + } + _ => route::bad_gateway(), + } +} + +fn timestamp(ms: u64) -> Option { + if ms > 253402300799999 { + return None; + } + let date = crate::http::http_date(ms / 1000); + let parts = date.split_whitespace().collect::>(); + let month = [ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + ] + .iter() + .position(|m| *m == parts[2])? + + 1; + Some(format!( + "{}-{month:02}-{}T{}-{:03}Z", + parts[3], + parts[1], + parts[4].replace(':', "-"), + ms % 1000 + )) +} +fn date_string(seconds: i64) -> Option { + if !(0..=253402300799).contains(&seconds) { + return None; + } + let d = crate::http::http_date(seconds as u64); + let p = d.split_whitespace().collect::>(); + Some(format!( + "{} {} {} {}", + p[0].trim_end_matches(','), + p[2], + p[1], + p[3] + )) +} +pub fn read( + c: &mut postgres::Client, + zid: i32, + uid: i32, + utc_dates: bool, +) -> anyhow::Result> { + let codes = c.query("SELECT zinvite FROM zinvites WHERE zid=$1 LIMIT 2", &[&zid])?; + if codes.len() != 1 { + return Ok(None); + } + let cid: String = codes[0].try_get(0)?; + if cid.is_empty() || cid.len() > 100 || !cid.bytes().all(|b| b.is_ascii_alphanumeric()) { + return Ok(None); + } + let rows = c.query( + "SELECT pid FROM participants WHERE zid=$1 AND uid=$2 LIMIT 2", + &[&zid, &uid], + )?; + if rows.len() > 1 { + return Ok(None); + } + let pid = match rows.first() { + Some(r) => r.try_get::<_, i32>(0)?, + None => -1, + }; + let mut csv = String::from("invite_code,status,created_at"); + if pid == -1 { + csv.push('\n'); + return Ok(Some(contract::Response { + conversation_id: cid, + csv, + })); + } + if pid < 0 { + return Ok(None); + } + let rows=c.query("SELECT CASE WHEN octet_length(invite_code)<=8192 THEN invite_code END,floor(extract(epoch FROM created_at))::bigint FROM treevite_invites WHERE zid=$1 AND invite_owner_pid=$2 AND status=0 ORDER BY id ASC LIMIT 201",&[&zid,&pid])?; + if rows.len() > 200 || (!rows.is_empty() && !utc_dates) { + return Ok(None); + } + for row in rows { + let Some(code) = row.try_get::<_, Option>(0)? else { + return Ok(None); + }; + let date = match row.try_get::<_, Option>(1)? { + Some(s) => { + let Some(d) = date_string(s) else { + return Ok(None); + }; + d + } + None => String::new(), + }; + csv.push('\n'); + csv.push_str(&contract::escape(&code)); + csv.push_str(",unused,"); + csv.push_str(&date); + if csv.len() > 65536 { + return Ok(None); + } + } + Ok(Some(contract::Response { + conversation_id: cid, + csv, + })) +} +#[cfg(all(test, feature = "db-tests"))] +#[path = "my_invites_csv_tests.rs"] +mod tests; diff --git a/queue-rs/polis-api/src/my_invites_csv_tests.rs b/queue-rs/polis-api/src/my_invites_csv_tests.rs new file mode 100644 index 000000000..b5d49e496 --- /dev/null +++ b/queue-rs/polis-api/src/my_invites_csv_tests.rs @@ -0,0 +1,102 @@ +use super::*; +#[tokio::test] +async fn csv_ownership_null_dates_escaping_and_independent_pool() { + let url = std::env::var("POLIS_API_TEST_DATABASE_URL").unwrap(); + let schema = format!("my_csv_test_{}", std::process::id()); + let setup_url = url.clone(); + let setup_schema = schema.clone(); + tokio::task::spawn_blocking(move||{ + let mut c=postgres::Client::connect(&setup_url,postgres::NoTls).unwrap(); + c.batch_execute(&format!("CREATE SCHEMA {setup_schema};SET search_path={setup_schema};CREATE TABLE zinvites(zid integer,zinvite text);CREATE TABLE participants(zid integer,uid integer,pid integer);CREATE TABLE treevite_invites(id bigint,zid integer,invite_owner_pid integer,invite_code text,status smallint,created_at timestamptz);INSERT INTO zinvites VALUES(1,'4csvfixture');INSERT INTO participants VALUES(1,1,0),(1,2,1);INSERT INTO treevite_invites VALUES(1,1,0,'plain',0,'2020-02-29 23:59:59.999+00'),(3,1,0,'ignored',1,NULL);")).unwrap(); + c.execute("INSERT INTO treevite_invites VALUES(2,1,0,$1,0,NULL)",&[&"comma,quote\"line\nnext"]).unwrap(); + }).await.unwrap(); + let make = || { + let mut c: postgres::Config = url.parse().unwrap(); + c.options(&format!("-c search_path={schema}")); + crate::db::Pool::new( + polis_queue_adapter::jobs::transport::Connector::Plain(Box::new(c)), + pool_limits(), + ) + }; + let pool = make(); + let participation = make(); + let response = pool.with(|c| read(c, 1, 1, true)).await.unwrap().unwrap(); + assert_eq!( + response.csv, + "invite_code,status,created_at\nplain,unused,Sat Feb 29 2020\n\"comma,quote\"\"line\nnext\",unused," + ); + assert!(pool.with(|c| read(c, 1, 1, false)).await.unwrap().is_none()); + assert_eq!( + pool.with(|c| read(c, 1, 2, false)) + .await + .unwrap() + .unwrap() + .csv, + "invite_code,status,created_at" + ); + assert_eq!( + pool.with(|c| read(c, 1, 99, false)) + .await + .unwrap() + .unwrap() + .csv, + "invite_code,status,created_at\n" + ); + assert_eq!( + timestamp(1700000000123).as_deref(), + Some("2023-11-14T22-13-20-123Z") + ); + assert_eq!(date_string(0).as_deref(), Some("Thu Jan 01 1970")); + assert!(date_string(-1).is_none()); + assert_eq!(contract::escape("carriage\rreturn"), "carriage\rreturn"); + let (ready_tx, ready_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = std::sync::mpsc::channel(); + let lock_url = url.clone(); + let lock_schema = schema.clone(); + let lock = tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&lock_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!( + "BEGIN;LOCK TABLE {lock_schema}.treevite_invites IN ACCESS EXCLUSIVE MODE" + )) + .unwrap(); + ready_tx.send(()).unwrap(); + release_rx + .recv_timeout(std::time::Duration::from_secs(5)) + .unwrap(); + c.batch_execute("ROLLBACK").unwrap(); + }); + ready_rx.await.unwrap(); + let stalled = pool.clone(); + let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); + let task = tokio::spawn(async move { + stalled + .with(move |c| { + entered_tx.send(()).unwrap(); + read(c, 1, 1, true) + }) + .await + }); + entered_rx.await.unwrap(); + assert!(participation.ping().await); + assert!(task.await.unwrap().is_err()); + release_tx.send(()).unwrap(); + lock.await.unwrap(); + assert!( + format!( + "{:#}", + pool.with(|c| Ok(c.batch_execute("DELETE FROM treevite_invites")?)) + .await + .unwrap_err() + ) + .contains("read-only") + ); + tokio::task::spawn_blocking(move || { + drop(pool); + drop(participation); + let mut c = postgres::Client::connect(&url, postgres::NoTls).unwrap(); + c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) + .unwrap(); + }) + .await + .unwrap(); +} diff --git a/queue-rs/polis-api/src/participants_read.rs b/queue-rs/polis-api/src/participants_read.rs new file mode 100644 index 000000000..08154ec28 --- /dev/null +++ b/queue-rs/polis-api/src/participants_read.rs @@ -0,0 +1,128 @@ +//! Current participant rows on independent, bounded read-only pools. +use crate::{ + http::{Outgoing, Request}, + route::{self, App, Res}, +}; +#[path = "../../polis-contracts/src/participants_read.rs"] +mod contract; +pub use contract::PATH; +pub fn parse(app: &App, req: &Request) -> Option { + if app.participants_read_db.is_none() + || req.path() != PATH + || req.headers.get("authorization").is_none() + || !matches!(req.method.as_str(), "GET" | "HEAD") + || !req.body.is_empty() + || req.headers.get("transfer-encoding").is_some() + || req.headers.get("content-length").is_some_and(|s| s != "0") + || req.headers.get("cookie").is_some() + { + return None; + } + let raw = req.query()?; + if raw.len() > 4096 { + return None; + } + let pairs = url::form_urlencoded::parse(raw.as_bytes()).collect::>(); + if pairs.len() != 1 || pairs[0].0 != "conversation_id" { + return None; + } + let cid = pairs[0].1.as_ref(); + if cid.is_empty() || cid.len() > 100 || !cid.bytes().all(|b| b.is_ascii_alphanumeric()) { + return None; + } + Some(contract::Request { + conversation_id: cid.into(), + }) +} +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 1, + acquire_timeout: std::time::Duration::from_millis(15), + statement_timeout: std::time::Duration::from_millis(50), + max_lifetime: std::time::Duration::from_secs(300), + } +} +pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { + let Some(query) = parse(app, req) else { + return route::bad_gateway(); + }; + let (Some(pool), Some(auth_pool)) = (&app.participants_read_db, &app.participants_read_auth_db) + else { + return route::bad_gateway(); + }; + let result = tokio::time::timeout(std::time::Duration::from_millis(75), async { + let uid = crate::hybrid_read::resolve_scoped( + req.headers.get("authorization"), + app.participant_verifier.as_deref(), + app.read_oidc.as_deref(), + auth_pool, + Some(&query.conversation_id), + ) + .await? + .uid()?; + let cid = query.conversation_id; + let zid = auth_pool + .with(move |c| crate::db::zid_for_conversation_id(c, &cid)) + .await + .ok() + .flatten()?; + if zid <= 0 { + return None; + } + pool.with(move |c| read(c, zid, uid.0)).await.ok().flatten() + }) + .await; + match result { + Ok(Some(response)) => match serde_json::to_string(&response) { + Ok(body) => route::json_text(req, res, 200, body), + Err(_) => route::bad_gateway(), + }, + _ => route::bad_gateway(), + } +} +/// Duplicate projected vote_count replaces its original value without moving +/// that property's position. Multiple rows or schema extensions stay on Node. +pub fn read( + c: &mut postgres::Client, + zid: i32, + uid: i32, +) -> anyhow::Result> { + let rows=c.query("SELECT p.*, (SELECT CASE WHEN COUNT(*)=0 AND p.vote_count IS NULL THEN NULL ELSE COUNT(*)::integer END FROM votes v WHERE v.zid=p.zid AND v.pid=p.pid) AS vote_count FROM participants p WHERE uid=$1 AND zid=$2 LIMIT 2",&[&uid,&zid])?; + if rows.len() > 1 { + return Ok(None); + } + let Some(r) = rows.first() else { + return Ok(Some(None)); + }; + let expected = [ + "pid", + "uid", + "zid", + "vote_count", + "last_interaction", + "subscribed", + "last_notified", + "nsli", + "mod", + "created", + "vote_count", + ]; + if r.columns().iter().map(|c| c.name()).collect::>() != expected { + return Ok(None); + } + Ok(Some(Some(contract::Participant { + pid: r.try_get(0)?, + uid: r.try_get(1)?, + zid: r.try_get(2)?, + vote_count: r.try_get(10)?, + last_interaction: r.try_get::<_, Option>(4)?.map(|n| n.to_string()), + subscribed: r.try_get(5)?, + last_notified: r.try_get::<_, Option>(6)?.map(|n| n.to_string()), + nsli: r.try_get(7)?, + moderation: r.try_get(8)?, + created: r.try_get::<_, Option>(9)?.map(|n| n.to_string()), + }))) +} +#[cfg(all(test, feature = "db-tests"))] +#[path = "participants_read_tests.rs"] +mod tests; diff --git a/queue-rs/polis-api/src/participants_read_tests.rs b/queue-rs/polis-api/src/participants_read_tests.rs new file mode 100644 index 000000000..6e0fc1e08 --- /dev/null +++ b/queue-rs/polis-api/src/participants_read_tests.rs @@ -0,0 +1,96 @@ +use super::*; +#[tokio::test] +async fn participant_projection_counts_history_preserves_bigints_and_sheds_locks() { + let url = std::env::var("POLIS_API_TEST_DATABASE_URL").unwrap(); + let schema = format!("participants_read_test_{}", std::process::id()); + let setup_url = url.clone(); + let setup_schema = schema.clone(); + tokio::task::spawn_blocking(move||{ + let mut c=postgres::Client::connect(&setup_url,postgres::NoTls).unwrap(); + c.batch_execute(&format!("CREATE SCHEMA {setup_schema}; SET search_path={setup_schema}; CREATE TABLE participants(pid integer,uid integer,zid integer,vote_count integer,last_interaction bigint,subscribed integer,last_notified bigint,nsli smallint,mod integer,created bigint); CREATE TABLE votes(zid integer,pid integer,vote smallint); INSERT INTO participants VALUES(0,1,1,999,9223372036854775807,2,NULL,3,1,1700000000000),(1,2,1,NULL,0,0,NULL,0,0,NULL);")).unwrap(); + let vote=crate::votes::StorageConvention::CURRENT.encode(crate::votes::VoteChoice::Agree) as i16; + c.execute("INSERT INTO votes(zid,pid,vote) VALUES(1,0,$1),(1,0,$1)",&[&vote]).unwrap(); + }).await.unwrap(); + let make_pool = || { + let mut c: postgres::Config = url.parse().unwrap(); + c.options(&format!("-c search_path={schema}")); + crate::db::Pool::new( + polis_queue_adapter::jobs::transport::Connector::Plain(Box::new(c)), + pool_limits(), + ) + }; + let pool = make_pool(); + let participation = make_pool(); + assert_eq!(pool.with(|c| read(c, 1, 99)).await.unwrap(), Some(None)); + let first = pool + .with(|c| read(c, 1, 1)) + .await + .unwrap() + .unwrap() + .unwrap(); + assert_eq!(first.pid, Some(0)); + assert_eq!(first.vote_count, Some(2)); + assert_eq!( + first.last_interaction.as_deref(), + Some("9223372036854775807") + ); + assert!(first.last_notified.is_none()); + let second = pool + .with(|c| read(c, 1, 2)) + .await + .unwrap() + .unwrap() + .unwrap(); + assert!(second.vote_count.is_none()); + assert!(second.created.is_none()); + let (ready_tx, ready_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = std::sync::mpsc::channel(); + let lock_url = url.clone(); + let lock_schema = schema.clone(); + let locked = tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&lock_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!( + "BEGIN; LOCK TABLE {lock_schema}.votes IN ACCESS EXCLUSIVE MODE" + )) + .unwrap(); + ready_tx.send(()).unwrap(); + release_rx + .recv_timeout(std::time::Duration::from_secs(5)) + .unwrap(); + c.batch_execute("ROLLBACK").unwrap(); + }); + ready_rx.await.unwrap(); + let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); + let stalled = pool.clone(); + let task = tokio::spawn(async move { + stalled + .with(move |c| { + entered_tx.send(()).unwrap(); + read(c, 1, 1) + }) + .await + }); + entered_rx.await.unwrap(); + assert!(participation.ping().await); + assert!(task.await.unwrap().is_err()); + release_tx.send(()).unwrap(); + locked.await.unwrap(); + assert!( + format!( + "{:#}", + pool.with(|c| Ok(c.batch_execute("DELETE FROM participants")?)) + .await + .unwrap_err() + ) + .contains("read-only") + ); + tokio::task::spawn_blocking(move || { + drop(pool); + drop(participation); + let mut c = postgres::Client::connect(&url, postgres::NoTls).unwrap(); + c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) + .unwrap(); + }) + .await + .unwrap(); +} diff --git a/queue-rs/polis-api/src/ptptois.rs b/queue-rs/polis-api/src/ptptois.rs new file mode 100644 index 000000000..1de1f9113 --- /dev/null +++ b/queue-rs/polis-api/src/ptptois.rs @@ -0,0 +1,150 @@ +//! Social participant rows on independent, bounded read-only pools. +use crate::{ + http::{Outgoing, Request}, + route::{self, App, Res}, +}; +#[path = "../../polis-contracts/src/ptptois.rs"] +mod contract; +pub use contract::PATH; +pub fn parse(app: &App, req: &Request) -> Option { + if app.ptptois_db.is_none() + || req.path() != PATH + || !matches!(req.method.as_str(), "GET" | "HEAD") + || !req.body.is_empty() + || req.headers.get("transfer-encoding").is_some() + || req.headers.get("content-length").is_some_and(|s| s != "0") + || req.headers.get("cookie").is_some() + { + return None; + } + let raw = req.query()?; + if raw.len() > 4096 { + return None; + } + let mut cid = None; + let mut moderation = None; + for (k, v) in url::form_urlencoded::parse(raw.as_bytes()) { + match k.as_ref() { + "conversation_id" if cid.is_none() => cid = Some(v.into_owned()), + "mod" if moderation.is_none() => { + let n = v.parse::().ok()?; + if n.to_string() != v { + return None; + } + moderation = Some(n); + } + _ => return None, + } + } + let cid = cid?; + if cid.is_empty() || cid.len() > 100 || !cid.bytes().all(|b| b.is_ascii_alphanumeric()) { + return None; + } + Some(contract::Request { + conversation_id: cid, + moderation, + }) +} +pub fn pool_limits() -> crate::db::Limits { + crate::db::Limits { + size: 1, + acquire_timeout: std::time::Duration::from_millis(15), + statement_timeout: std::time::Duration::from_millis(50), + max_lifetime: std::time::Duration::from_secs(300), + } +} +pub async fn handle(app: &App, req: &Request, res: Res) -> Outgoing { + let Some(query) = parse(app, req) else { + return route::bad_gateway(); + }; + let (Some(pool), Some(auth_pool)) = (&app.ptptois_db, &app.ptptois_auth_db) else { + return route::bad_gateway(); + }; + let result = tokio::time::timeout(std::time::Duration::from_millis(75), async { + let identity = crate::hybrid_read::resolve_scoped( + req.headers.get("authorization"), + app.participant_verifier.as_deref(), + app.read_oidc.as_deref(), + auth_pool, + Some(&query.conversation_id), + ) + .await?; + let uid = identity.uid().map(|v| v.0); + let developer = uid.is_some_and(|v| app.legacy_admin_uids.contains(&v)); + let cid = query.conversation_id.clone(); + let zid = auth_pool + .with(move |c| crate::db::zid_for_conversation_id(c, &cid)) + .await + .ok() + .flatten()?; + if zid <= 0 { + return None; + } + pool.with(move |c| read(c, zid, uid, developer, &query)) + .await + .ok() + .flatten() + }) + .await; + match result { + Ok(Some(response)) => match serde_json::to_string(&response) { + Ok(body) => route::json_text(req, res, 200, body), + Err(_) => route::bad_gateway(), + }, + _ => route::bad_gateway(), + } +} +/// The source has no final ORDER BY: admit at most one row, with no invented sort. +pub fn read( + c: &mut postgres::Client, + zid: i32, + uid: Option, + developer: bool, + query: &contract::Request, +) -> anyhow::Result> { + let conv = c.query( + "SELECT owner,is_data_open FROM conversations WHERE zid=$1 LIMIT 2", + &[&zid], + )?; + if conv.len() != 1 { + return Ok(None); + } + let owner: Option = conv[0].try_get(0)?; + let open: Option = conv[0].try_get(1)?; + let count=c.query_one("SELECT count(*) FROM (SELECT 1 FROM participants WHERE zid=$1 AND ($2::integer IS NULL OR mod=$2) LIMIT 100000) bounded",&[&zid,&query.moderation])?.try_get::<_,i64>(0)?; + if count > 99999 { + return Ok(None); + } + let rows=c.query("WITH p AS (SELECT uid,pid,mod FROM participants WHERE zid=$1 AND ($3::integer IS NULL OR mod=$3)), final_set AS (SELECT * FROM p LIMIT 99999), x AS (SELECT * FROM xids WHERE owner=$2 AND x_profile_image_url IS NOT NULL), a AS (SELECT f.mod,x.x_profile_image_url,x.xid,x.x_name,f.pid FROM final_set f LEFT JOIN x ON f.uid=x.uid WHERE x.xid IS NOT NULL), bounded AS (SELECT *,coalesce(octet_length(x_profile_image_url),0)+coalesce(octet_length(xid),0)+coalesce(octet_length(x_name),0)<=8192 AS fits FROM a) SELECT mod,CASE WHEN fits THEN x_profile_image_url END,CASE WHEN fits THEN xid END,CASE WHEN fits THEN x_name END,pid,fits FROM bounded LIMIT 2",&[&zid,&owner,&query.moderation])?; + if uid.is_none_or(|u| Some(u) != owner) && !developer && open != Some(true) { + return Ok(Some(vec![])); + } + if rows.len() > 1 { + return Ok(None); + } + let Some(row) = rows.first() else { + return Ok(Some(vec![])); + }; + if !row.try_get::<_, bool>(5)? { + return Ok(None); + } + let profile: String = row.try_get(1)?; + let xid: String = row.try_get(2)?; + let name: Option = row.try_get(3)?; + let nested = !profile.is_empty() || !xid.is_empty(); + Ok(Some(vec![contract::Participant { + moderation: row.try_get(0)?, + x_profile_image_url: (!nested).then(|| profile.clone()), + xid: (!nested).then_some(xid), + x_name: if nested { None } else { name.clone() }, + pid: row.try_get(4)?, + x_info: nested.then_some(contract::XInfo { + x_profile_image_url: profile, + x_name: name, + }), + conversation_id: query.conversation_id.clone(), + }])) +} +#[cfg(all(test, feature = "db-tests"))] +#[path = "ptptois_tests.rs"] +mod tests; diff --git a/queue-rs/polis-api/src/ptptois_tests.rs b/queue-rs/polis-api/src/ptptois_tests.rs new file mode 100644 index 000000000..580d59f2a --- /dev/null +++ b/queue-rs/polis-api/src/ptptois_tests.rs @@ -0,0 +1,110 @@ +use super::*; +#[tokio::test] +async fn social_rows_preserve_visibility_nesting_and_shed_locked_reads() { + let url = std::env::var("POLIS_API_TEST_DATABASE_URL").unwrap(); + let schema = format!("ptptois_test_{}", std::process::id()); + let setup_url = url.clone(); + let setup_schema = schema.clone(); + tokio::task::spawn_blocking(move||{let mut c=postgres::Client::connect(&setup_url,postgres::NoTls).unwrap();c.batch_execute(&format!("CREATE SCHEMA {setup_schema};SET search_path={setup_schema};CREATE TABLE conversations(zid integer,owner integer,is_data_open boolean);CREATE TABLE participants(zid integer,uid integer,pid integer,mod integer);CREATE TABLE xids(owner integer,uid integer,x_profile_image_url text,xid text,x_name text);INSERT INTO conversations VALUES(1,10,false),(2,20,true);INSERT INTO participants VALUES(1,3,0,2),(2,3,0,NULL);INSERT INTO xids VALUES(10,3,'https://example.invalid/a','generated',NULL),(20,3,'','',NULL);")).unwrap();}).await.unwrap(); + let make = || { + let mut c: postgres::Config = url.parse().unwrap(); + c.options(&format!("-c search_path={schema}")); + crate::db::Pool::new( + polis_queue_adapter::jobs::transport::Connector::Plain(Box::new(c)), + pool_limits(), + ) + }; + let pool = make(); + let participation = make(); + let run = |zid, uid, developer, moderation| { + let pool = pool.clone(); + async move { + pool.with(move |c| { + read( + c, + zid, + uid, + developer, + &contract::Request { + conversation_id: "4fixture".into(), + moderation, + }, + ) + }) + .await + .unwrap() + .unwrap() + } + }; + assert!(run(1, None, false, None).await.is_empty()); + let row = run(1, Some(10), false, None).await; + assert_eq!( + serde_json::to_string(&row).unwrap(), + "[{\"mod\":2,\"pid\":0,\"xInfo\":{\"x_profile_image_url\":\"https://example.invalid/a\",\"x_name\":null},\"conversation_id\":\"4fixture\"}]" + ); + assert_eq!(row, run(1, Some(99), true, None).await); + assert!(run(1, Some(10), false, Some(0)).await.is_empty()); + assert_eq!( + serde_json::to_string(&run(2, None, false, None).await).unwrap(), + "[{\"x_profile_image_url\":\"\",\"xid\":\"\",\"pid\":0,\"conversation_id\":\"4fixture\"}]" + ); + let (ready_tx, ready_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = std::sync::mpsc::channel(); + let lock_url = url.clone(); + let lock_schema = schema.clone(); + let lock = tokio::task::spawn_blocking(move || { + let mut c = postgres::Client::connect(&lock_url, postgres::NoTls).unwrap(); + c.batch_execute(&format!( + "BEGIN;LOCK TABLE {lock_schema}.xids IN ACCESS EXCLUSIVE MODE" + )) + .unwrap(); + ready_tx.send(()).unwrap(); + release_rx + .recv_timeout(std::time::Duration::from_secs(5)) + .unwrap(); + c.batch_execute("ROLLBACK").unwrap(); + }); + ready_rx.await.unwrap(); + let stalled = pool.clone(); + let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); + let task = tokio::spawn(async move { + stalled + .with(move |c| { + entered_tx.send(()).unwrap(); + read( + c, + 1, + Some(10), + false, + &contract::Request { + conversation_id: "4fixture".into(), + moderation: None, + }, + ) + }) + .await + }); + entered_rx.await.unwrap(); + assert!(participation.ping().await); + assert!(task.await.unwrap().is_err()); + release_tx.send(()).unwrap(); + lock.await.unwrap(); + assert!( + format!( + "{:#}", + pool.with(|c| Ok(c.batch_execute("DELETE FROM participants")?)) + .await + .unwrap_err() + ) + .contains("read-only") + ); + tokio::task::spawn_blocking(move || { + drop(pool); + drop(participation); + let mut c = postgres::Client::connect(&url, postgres::NoTls).unwrap(); + c.batch_execute(&format!("DROP SCHEMA {schema} CASCADE")) + .unwrap(); + }) + .await + .unwrap(); +} diff --git a/queue-rs/polis-api/src/route.rs b/queue-rs/polis-api/src/route.rs index 9eb7b3bbb..d931a3cc6 100644 --- a/queue-rs/polis-api/src/route.rs +++ b/queue-rs/polis-api/src/route.rs @@ -48,6 +48,37 @@ pub struct App { pub metadata_questions_auth_db: Option>, pub metadata_questions_served: AtomicU64, pub metadata_questions_fallback: AtomicU64, + pub conversation_pages: [Option; 5], + pub conversation_page_dbs: [Option>; 5], + pub conversation_page_served: [AtomicU64; 5], + pub conversation_page_fallback: [AtomicU64; 5], + pub iip_db: Option>, + pub iim_db: Option>, + pub iip_served: AtomicU64, + pub iip_fallback: AtomicU64, + pub iim_served: AtomicU64, + pub iim_fallback: AtomicU64, + pub participants_read_db: Option>, + pub participants_read_auth_db: Option>, + pub participants_read_served: AtomicU64, + pub participants_read_fallback: AtomicU64, + pub ptptois_db: Option>, + pub ptptois_auth_db: Option>, + pub ptptois_served: AtomicU64, + pub ptptois_fallback: AtomicU64, + pub my_invites_csv_db: Option>, + pub my_invites_csv_auth_db: Option>, + pub my_invites_csv_served: AtomicU64, + pub my_invites_csv_fallback: AtomicU64, + pub bid_db: Option>, + pub bid_auth_db: Option>, + pub bid_served: AtomicU64, + pub bid_fallback: AtomicU64, + pub locations_db: Option>, + pub locations_auth_db: Option>, + pub locations_served: AtomicU64, + pub locations_fallback: AtomicU64, + pub math_bundle: crate::math_bundle::Cache, pub votes_read_db: Option>, pub votes_read_auth_db: Option>, pub votes_read_served: AtomicU64, @@ -258,6 +289,37 @@ impl App { metadata_questions_auth_db: None, metadata_questions_served: AtomicU64::new(0), metadata_questions_fallback: AtomicU64::new(0), + conversation_pages: std::array::from_fn(|_| None), + conversation_page_dbs: std::array::from_fn(|_| None), + conversation_page_served: std::array::from_fn(|_| AtomicU64::new(0)), + conversation_page_fallback: std::array::from_fn(|_| AtomicU64::new(0)), + iip_db: None, + iim_db: None, + iip_served: AtomicU64::new(0), + iip_fallback: AtomicU64::new(0), + iim_served: AtomicU64::new(0), + iim_fallback: AtomicU64::new(0), + participants_read_db: None, + participants_read_auth_db: None, + participants_read_served: AtomicU64::new(0), + participants_read_fallback: AtomicU64::new(0), + ptptois_db: None, + ptptois_auth_db: None, + ptptois_served: AtomicU64::new(0), + ptptois_fallback: AtomicU64::new(0), + my_invites_csv_db: None, + my_invites_csv_auth_db: None, + my_invites_csv_served: AtomicU64::new(0), + my_invites_csv_fallback: AtomicU64::new(0), + bid_db: None, + bid_auth_db: None, + bid_served: AtomicU64::new(0), + bid_fallback: AtomicU64::new(0), + locations_db: None, + locations_auth_db: None, + locations_served: AtomicU64::new(0), + locations_fallback: AtomicU64::new(0), + math_bundle: crate::math_bundle::Cache::new(cfg.cache_size > 1), votes_read_db: None, votes_read_auth_db: None, votes_read_served: AtomicU64::new(0), @@ -767,6 +829,37 @@ pub(crate) fn admin_html(req: &Request, mut res: Res, chunks: Vec>) -> O out } +/// Express CSV download, preserving the ordinary freshness/compression wrapper. +pub(crate) fn csv_attachment( + req: &Request, + mut res: Res, + filename: &str, + body: String, +) -> Outgoing { + res.set("Content-Type", "text/csv; charset=utf-8"); + res.set( + "Content-Disposition", + format!("attachment; filename=\"{filename}\""), + ); + send(req, res, Payload::Text(body)) +} + +/// Static conversation HTML after both stream transformations. +pub(crate) fn conversation_html( + req: &Request, + mut res: Res, + chunks: Vec>, + no_cache: bool, +) -> Outgoing { + res.set("Content-Type", "text/html"); + if no_cache { + res.set("Cache-Control", "no-cache"); + } + let mut out = finish(req, res, Ending::WriteHeadThenEnd, true); + out.body = Body::Chunked(chunks); + out +} + /// Express status(...).json(...) retaining the normal response envelope. pub(crate) fn json_status(req: &Request, mut res: Res, status: u16, value: &Js) -> Outgoing { res.status = status; @@ -802,6 +895,12 @@ pub(crate) fn text(req: &Request, res: Res, value: &str) -> Outgoing { send(req, res, Payload::Text(value.into())) } +/// Express HTML send with the normal ETag, freshness and compression envelope. +pub(crate) fn html(req: &Request, mut res: Res, value: &str) -> Outgoing { + res.set("Content-Type", "text/html"); + send(req, res, Payload::Text(value.into())) +} + /// Express CSV send with its normal ETag, freshness and compression envelope. pub(crate) fn csv(req: &Request, mut res: Res, value: &str) -> Outgoing { res.set("Content-Type", "text/csv"); @@ -1041,6 +1140,61 @@ pub async fn handle(app: Arc, req: Request) -> Outgoing { app.metadata_answers_served.fetch_add(1, Ordering::Relaxed); } } + if let Some((page, _)) = crate::conversation_pages::page(req.path()) { + if out.status == 502 { + app.conversation_page_fallback[page.index()].fetch_add(1, Ordering::Relaxed); + } else { + app.conversation_page_served[page.index()].fetch_add(1, Ordering::Relaxed); + } + } + if crate::link_pages::matches(req.path()) { + let (served, fallback) = if req.path().starts_with("/iip/") { + (&app.iip_served, &app.iip_fallback) + } else { + (&app.iim_served, &app.iim_fallback) + }; + if out.status == 502 { + fallback.fetch_add(1, Ordering::Relaxed); + } else { + served.fetch_add(1, Ordering::Relaxed); + } + } + if req.path() == crate::participants_read::PATH { + if out.status == 502 { + app.participants_read_fallback + .fetch_add(1, Ordering::Relaxed); + } else { + app.participants_read_served.fetch_add(1, Ordering::Relaxed); + } + } + if req.path() == crate::ptptois::PATH { + if out.status == 502 { + app.ptptois_fallback.fetch_add(1, Ordering::Relaxed); + } else { + app.ptptois_served.fetch_add(1, Ordering::Relaxed); + } + } + if req.path() == crate::my_invites_csv::PATH { + if out.status == 502 { + app.my_invites_csv_fallback.fetch_add(1, Ordering::Relaxed); + } else { + app.my_invites_csv_served.fetch_add(1, Ordering::Relaxed); + } + } + if req.path() == crate::math_membership::BID_PATH { + if out.status == 502 { + app.bid_fallback.fetch_add(1, Ordering::Relaxed); + } else { + app.bid_served.fetch_add(1, Ordering::Relaxed); + } + } + if req.path() == crate::math_membership::LOCATIONS_PATH { + if out.status == 502 { + app.locations_fallback.fetch_add(1, Ordering::Relaxed); + } else { + app.locations_served.fetch_add(1, Ordering::Relaxed); + } + } if crate::votes_read::matches(req.path()) { if out.status == 502 { app.votes_read_fallback.fetch_add(1, Ordering::Relaxed); @@ -1583,6 +1737,31 @@ async fn serve(app: &App, req: &Request) -> Outgoing { { return bad_gateway(); } + if crate::conversation_pages::matches(req.path()) + && crate::conversation_pages::parse(app, req).is_none() + { + return bad_gateway(); + } + if crate::link_pages::matches(req.path()) && crate::link_pages::parse(app, req).is_none() { + return bad_gateway(); + } + if req.path() == crate::participants_read::PATH + && crate::participants_read::parse(app, req).is_none() + { + return bad_gateway(); + } + if req.path() == crate::ptptois::PATH && crate::ptptois::parse(app, req).is_none() { + return bad_gateway(); + } + if req.path() == crate::my_invites_csv::PATH && crate::my_invites_csv::parse(app, req).is_none() + { + return bad_gateway(); + } + if crate::math_membership::matches(req.path()) + && crate::math_membership::parse(app, req).is_none() + { + return bad_gateway(); + } if crate::votes_read::matches(req.path()) && crate::votes_read::parse(app, req).is_none() { return bad_gateway(); } @@ -1705,6 +1884,8 @@ async fn serve(app: &App, req: &Request) -> Outgoing { }; // writeDefaultHead, compress, addCorsHeader. let origin = match if matches!(req.path(), crate::robots::PATH | crate::about::PATH) + || crate::conversation_pages::matches(req.path()) + || crate::link_pages::matches(req.path()) || crate::create_page::matches(req.path()) || crate::settings_page::matches(req.path()) || crate::other_conversations_page::matches(req.path()) @@ -1878,9 +2059,27 @@ async fn serve(app: &App, req: &Request) -> Outgoing { if req.path() == crate::metadata_answers::PATH { return crate::metadata_answers::handle(app, req, res).await; } + if crate::math_membership::matches(req.path()) { + return crate::math_membership::handle(app, req, res).await; + } if crate::votes_read::matches(req.path()) { return crate::votes_read::handle(app, req, res).await; } + if crate::conversation_pages::matches(req.path()) { + return crate::conversation_pages::handle(app, req, res).await; + } + if crate::link_pages::matches(req.path()) { + return crate::link_pages::handle(app, req, res).await; + } + if req.path() == crate::participants_read::PATH { + return crate::participants_read::handle(app, req, res).await; + } + if req.path() == crate::ptptois::PATH { + return crate::ptptois::handle(app, req, res).await; + } + if req.path() == crate::my_invites_csv::PATH { + return crate::my_invites_csv::handle(app, req, res).await; + } if req.path() == crate::metadata_questions::PATH { return crate::metadata_questions::handle(app, req, res).await; } @@ -3947,6 +4146,259 @@ mod tests { assert_eq!(redirect.status, 302); // Ordinary HTTPS middleware, unlike testConnection. } + #[tokio::test] + async fn ptptois_switch_and_boundaries() { + let mut state = app(true); + let make = || { + let mut req = request( + "GET", + &[("host", "localhost"), ("authorization", "Bearer generated")], + ); + req.target = "/api/v3/ptptois?conversation_id=4fixture".into(); + req + }; + assert_eq!(handle(state.clone(), make()).await.status, 502); + let pool = state.db.clone(); + Arc::get_mut(&mut state).unwrap().ptptois_db = Some(pool.clone()); + Arc::get_mut(&mut state).unwrap().ptptois_auth_db = Some(pool); + assert!(crate::ptptois::parse(&state, &make()).is_some()); + assert_eq!(handle(state.clone(), make()).await.status, 502); + for (method, tail, extra) in [ + ("POST", "", vec![]), + ("OPTIONS", "", vec![]), + ("GET", "&pid=0", vec![]), + ("GET", "&conversation_id=again", vec![]), + ("GET", "", vec![("cookie", "x=y")]), + ("GET", "", vec![("content-length", "2")]), + ("GET", "", vec![("transfer-encoding", "chunked")]), + ] { + let mut headers = vec![("host", "localhost"), ("authorization", "Bearer generated")]; + headers.extend(extra); + let mut req = request(method, &headers); + req.target = format!("/api/v3/ptptois?conversation_id=4fixture{tail}"); + assert!(crate::ptptois::parse(&state, &req).is_none()); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + let mut no_auth = request("GET", &[("host", "localhost")]); + no_auth.target = make().target; + assert!(crate::ptptois::parse(&state, &no_auth).is_some()); + assert_eq!(state.ptptois_served.load(Ordering::Relaxed), 0); + assert_eq!(state.ptptois_fallback.load(Ordering::Relaxed), 9); + } + + #[tokio::test] + async fn my_invites_csv_switch_and_boundaries() { + let mut state = app(true); + let make = || { + let mut req = request( + "GET", + &[("host", "localhost"), ("authorization", "Bearer generated")], + ); + req.target = "/api/v3/treevite/myInvites/csv?conversation_id=4fixture".into(); + req + }; + assert_eq!(handle(state.clone(), make()).await.status, 502); + let pool = state.db.clone(); + Arc::get_mut(&mut state).unwrap().my_invites_csv_db = Some(pool.clone()); + Arc::get_mut(&mut state).unwrap().my_invites_csv_auth_db = Some(pool); + assert!(crate::my_invites_csv::parse(&state, &make()).is_some()); + assert_eq!(handle(state.clone(), make()).await.status, 502); + for (method, tail, extra) in [ + ("POST", "", vec![]), + ("OPTIONS", "", vec![]), + ("GET", "&pid=0", vec![]), + ("GET", "&conversation_id=again", vec![]), + ("GET", "", vec![("cookie", "x=y")]), + ("GET", "", vec![("content-length", "2")]), + ("GET", "", vec![("transfer-encoding", "chunked")]), + ] { + let mut headers = vec![("host", "localhost"), ("authorization", "Bearer generated")]; + headers.extend(extra); + let mut req = request(method, &headers); + req.target = format!("/api/v3/treevite/myInvites/csv?conversation_id=4fixture{tail}"); + assert!(crate::my_invites_csv::parse(&state, &req).is_none()); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + let mut no_auth = request("GET", &[("host", "localhost")]); + no_auth.target = make().target; + assert!(crate::my_invites_csv::parse(&state, &no_auth).is_none()); + assert_eq!(state.my_invites_csv_served.load(Ordering::Relaxed), 0); + assert_eq!(state.my_invites_csv_fallback.load(Ordering::Relaxed), 9); + } + + #[tokio::test] + async fn math_membership_switches_and_parser_boundaries_are_independent() { + let mut state = app(true); + for route in ["bid", "locations"] { + let mut req = request( + "GET", + &[("host", "localhost"), ("authorization", "Bearer generated")], + ); + req.target = format!( + "/api/v3/{route}?conversation_id=4fixture{}", + if route == "locations" { "&gid=0" } else { "" } + ); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + let pool = state.db.clone(); + Arc::get_mut(&mut state).unwrap().bid_db = Some(pool.clone()); + Arc::get_mut(&mut state).unwrap().bid_auth_db = Some(pool.clone()); + let mut req = request( + "GET", + &[("host", "localhost"), ("authorization", "Bearer generated")], + ); + req.target = "/api/v3/locations?conversation_id=4fixture&gid=0".into(); + assert!(crate::math_membership::parse(&state, &req).is_none()); + req.target = "/api/v3/bid?conversation_id=4fixture".into(); + assert!(crate::math_membership::parse(&state, &req).is_some()); + assert_eq!(handle(state.clone(), req).await.status, 502); + Arc::get_mut(&mut state).unwrap().locations_db = Some(pool.clone()); + Arc::get_mut(&mut state).unwrap().locations_auth_db = Some(pool); + for route in ["bid", "locations"] { + for (method, tail, headers) in [ + ("POST", "", vec![]), + ("OPTIONS", "", vec![]), + ("GET", "&pid=0", vec![]), + ("GET", "&conversation_id=other", vec![]), + ("GET", "", vec![("cookie", "x=y")]), + ("GET", "", vec![("content-length", "2")]), + ] { + let mut h = vec![("host", "localhost"), ("authorization", "Bearer generated")]; + h.extend(headers); + let mut req = request(method, &h); + req.target = format!( + "/api/v3/{route}?conversation_id=4fixture{}{tail}", + if route == "locations" { "&gid=0" } else { "" } + ); + assert!(crate::math_membership::parse(&state, &req).is_none()); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + } + let mut req = request("GET", &[("host", "localhost")]); + req.target = "/api/v3/locations?conversation_id=4fixture&gid=0".into(); + assert!(crate::math_membership::parse(&state, &req).is_some()); + req.target = "/api/v3/bid?conversation_id=4fixture".into(); + assert!(crate::math_membership::parse(&state, &req).is_none()); + } + + #[tokio::test] + async fn five_conversation_page_switches_and_boundaries_are_independent() { + let prefixes = ["/", "/explore/", "/share/", "/summary/", "/ot/"]; + for (index, prefix) in prefixes.iter().enumerate() { + let mut state = app(true); + let pool = state.db.clone(); + Arc::get_mut(&mut state).unwrap().conversation_page_dbs[index] = Some(pool); + Arc::get_mut(&mut state).unwrap().conversation_pages[index] = + Some(crate::conversation_pages::Client::new("127.0.0.1".into(), 1).unwrap()); + for (other, p) in prefixes.iter().enumerate() { + let mut req = request("GET", &[("host", "localhost")]); + req.target = format!("{p}4fixture"); + assert_eq!( + crate::conversation_pages::parse(&state, &req).is_some(), + other == index + ); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + for (method, suffix, headers) in [ + ("POST", "", vec![]), + ("OPTIONS", "", vec![]), + ("GET", "?extra=1", vec![]), + ("GET", "", vec![("cookie", "x=y")]), + ("GET", "", vec![("authorization", "Bearer generated")]), + ("GET", "", vec![("content-length", "2")]), + ("GET", "", vec![("user-agent", "MSIE 7.0")]), + ("GET", "", vec![("accept-encoding", "gzip")]), + ] { + let mut req = request(method, &headers); + req.target = format!("{prefix}4fixture{suffix}"); + assert!(crate::conversation_pages::parse(&state, &req).is_none()); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + assert_eq!( + state.conversation_page_served[index].load(Ordering::Relaxed), + 0 + ); + } + } + + #[tokio::test] + async fn participants_read_switch_and_boundaries() { + let mut state = app(true); + let make = || { + let mut req = request( + "GET", + &[("host", "localhost"), ("authorization", "Bearer generated")], + ); + req.target = "/api/v3/participants?conversation_id=4fixture".into(); + req + }; + assert_eq!(handle(state.clone(), make()).await.status, 502); + let pool = state.db.clone(); + Arc::get_mut(&mut state).unwrap().participants_read_db = Some(pool.clone()); + Arc::get_mut(&mut state).unwrap().participants_read_auth_db = Some(pool); + assert!(crate::participants_read::parse(&state, &make()).is_some()); + assert_eq!(handle(state.clone(), make()).await.status, 502); + for (method, tail, extra) in [ + ("POST", "", vec![]), + ("OPTIONS", "", vec![]), + ("GET", "&pid=0", vec![]), + ("GET", "&conversation_id=again", vec![]), + ("GET", "", vec![("cookie", "x=y")]), + ("GET", "", vec![("content-length", "2")]), + ("GET", "", vec![("transfer-encoding", "chunked")]), + ] { + let mut headers = vec![("host", "localhost"), ("authorization", "Bearer generated")]; + headers.extend(extra); + let mut req = request(method, &headers); + req.target = format!("/api/v3/participants?conversation_id=4fixture{tail}"); + assert!(crate::participants_read::parse(&state, &req).is_none()); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + let mut no_auth = request("GET", &[("host", "localhost")]); + no_auth.target = make().target; + assert!(crate::participants_read::parse(&state, &no_auth).is_none()); + assert_eq!(state.participants_read_served.load(Ordering::Relaxed), 0); + assert_eq!(state.participants_read_fallback.load(Ordering::Relaxed), 9); + } + + #[tokio::test] + async fn link_pages_switches_admission_and_unreachable_database() { + let mut state = app(true); + for prefix in ["iip", "iim"] { + let mut req = request("GET", &[("host", "localhost")]); + req.target = format!("/{prefix}/4fixture"); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + let pool = state.db.clone(); + Arc::get_mut(&mut state).unwrap().iip_db = Some(pool.clone()); + let mut req = request("GET", &[("host", "localhost")]); + req.target = "/iim/4fixture".into(); + assert!(crate::link_pages::parse(&state, &req).is_none()); + req.target = "/iip/4fixture".into(); + assert!(crate::link_pages::parse(&state, &req).is_some()); + assert_eq!(handle(state.clone(), req).await.status, 502); + Arc::get_mut(&mut state).unwrap().iim_db = Some(pool); + for prefix in ["iip", "iim"] { + for (method, suffix, headers) in [ + ("POST", "", vec![]), + ("OPTIONS", "", vec![]), + ("GET", "?other=1", vec![]), + ("GET", "/extra", vec![]), + ("GET", "%20", vec![]), + ("GET", "", vec![("cookie", "x=y")]), + ("GET", "", vec![("authorization", "Bearer bad")]), + ("GET", "", vec![("content-length", "2")]), + ] { + let mut req = request(method, &headers); + req.target = format!("/{prefix}/4fixture{suffix}"); + assert!(crate::link_pages::parse(&state, &req).is_none()); + assert_eq!(handle(state.clone(), req).await.status, 502); + } + } + assert_eq!(state.iip_served.load(Ordering::Relaxed), 0); + assert_eq!(state.iim_served.load(Ordering::Relaxed), 0); + } + #[tokio::test] async fn votes_read_is_off_and_unreachable_database_is_a_handoff() { let mut state = app(true); diff --git a/queue-rs/polis-contracts/src/conversation_pages.rs b/queue-rs/polis-contracts/src/conversation_pages.rs new file mode 100644 index 000000000..257fb25ef --- /dev/null +++ b/queue-rs/polis-contracts/src/conversation_pages.rs @@ -0,0 +1,34 @@ +//! Per-conversation static pages with typed preload and stream output. +use serde::{Deserialize, Serialize}; +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub enum Page { + Conversation, + Explore, + Share, + Summary, + OneTime, +} +impl Page { + pub fn index(self) -> usize { + match self { + Self::Conversation => 0, + Self::Explore => 1, + Self::Share => 2, + Self::Summary => 3, + Self::OneTime => 4, + } + } +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Request { + pub page: Page, + pub conversation_id: String, + pub path: String, + pub head_only: bool, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Response { + pub html: String, +} diff --git a/queue-rs/polis-contracts/src/fixtures/conversation-pages.json b/queue-rs/polis-contracts/src/fixtures/conversation-pages.json new file mode 100644 index 000000000..1ae71ca90 --- /dev/null +++ b/queue-rs/polis-contracts/src/fixtures/conversation-pages.json @@ -0,0 +1,34 @@ +[ + { + "id": "plain///GET", + "document": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "preload": "{\"conversation\":{\"topic\":\"Generated topic\",\"description\":\"Generated description\",\"created\":\"9223372036854775807\",\"link_url\":null,\"parent_url\":null,\"vis_type\":0,\"write_type\":1,\"importance_enabled\":false,\"help_type\":1,\"bgcolor\":null,\"help_color\":null,\"help_bgcolor\":null,\"style_btn\":null,\"auth_needed_to_vote\":false,\"auth_needed_to_write\":false,\"auth_opt_allow_3rdparty\":null,\"conversation_id\":\"2p027r61033\"}}", + "topic": "Generated topic", + "description": "Generated description", + "html": "\n \n \naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "id": "markup///GET", + "document": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "preload": "{\"conversation\":{\"topic\":\"Quote \\\" & apostrophe'\",\"description\":\"First line\\nSecond & line\",\"created\":\"9223372036854775807\",\"link_url\":null,\"parent_url\":null,\"vis_type\":0,\"write_type\":1,\"importance_enabled\":false,\"help_type\":1,\"bgcolor\":null,\"help_color\":null,\"help_bgcolor\":null,\"style_btn\":null,\"auth_needed_to_vote\":false,\"auth_needed_to_write\":false,\"auth_opt_allow_3rdparty\":null,\"conversation_id\":\"2p027r61033\"}}", + "topic": "Quote \" & apostrophe'", + "description": "First line\nSecond & line", + "html": "\n \n \naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "id": "null///GET", + "document": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "preload": "{\"conversation\":{\"topic\":null,\"description\":null,\"created\":\"9223372036854775807\",\"link_url\":null,\"parent_url\":null,\"vis_type\":0,\"write_type\":1,\"importance_enabled\":false,\"help_type\":1,\"bgcolor\":null,\"help_color\":null,\"help_bgcolor\":null,\"style_btn\":null,\"auth_needed_to_vote\":false,\"auth_needed_to_write\":false,\"auth_opt_allow_3rdparty\":null,\"conversation_id\":\"2p027r61033\"}}", + "topic": null, + "description": null, + "html": "\n \n \naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "id": "static/multiple///GET", + "document": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "preload": "{\"conversation\":{\"topic\":\"Generated topic\",\"description\":\"Generated description\",\"created\":\"9223372036854775807\",\"link_url\":null,\"parent_url\":null,\"vis_type\":0,\"write_type\":1,\"importance_enabled\":false,\"help_type\":1,\"bgcolor\":null,\"help_color\":null,\"help_bgcolor\":null,\"style_btn\":null,\"auth_needed_to_vote\":false,\"auth_needed_to_write\":false,\"auth_opt_allow_3rdparty\":null,\"conversation_id\":\"2p027r61033\"}}", + "topic": "Generated topic", + "description": "Generated description", + "html": "\n \n \naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n \n \naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + } +] diff --git a/queue-rs/polis-contracts/src/fixtures/link-pages.json b/queue-rs/polis-contracts/src/fixtures/link-pages.json new file mode 100644 index 000000000..f8e28e6f0 --- /dev/null +++ b/queue-rs/polis-contracts/src/fixtures/link-pages.json @@ -0,0 +1,57 @@ +[ + { + "page": "Participation", + "conversation_id": "4linkplain", + "html": "4linkplain" + }, + { + "page": "Participation", + "conversation_id": "4linkempty", + "html": "4linkempty" + }, + { + "page": "Participation", + "conversation_id": "4linkmarkup", + "html": "4linkmarkup" + }, + { + "page": "Participation", + "conversation_id": "4linklarge", + "html": "4linklarge" + }, + { + "page": "Participation", + "conversation_id": "4linknull", + "html": "4linknull" + }, + { + "page": "Participation", + "conversation_id": "4linkbigint", + "html": "4linkbigint" + }, + { + "page": "Moderation", + "conversation_id": "4linkplain", + "html": "Generated topic

moderate

Generated description

" + }, + { + "page": "Moderation", + "conversation_id": "4linkempty", + "html": "1700000000000

moderate

" + }, + { + "page": "Moderation", + "conversation_id": "4linkmarkup", + "html": "Topic & 🙂

moderate

raw markup

" + }, + { + "page": "Moderation", + "conversation_id": "4linknull", + "html": "null

moderate

" + }, + { + "page": "Moderation", + "conversation_id": "4linkbigint", + "html": "9223372036854775807

moderate

" + } +] diff --git a/queue-rs/polis-contracts/src/fixtures/math-membership.json b/queue-rs/polis-contracts/src/fixtures/math-membership.json new file mode 100644 index 000000000..866aef760 --- /dev/null +++ b/queue-rs/polis-contracts/src/fixtures/math-membership.json @@ -0,0 +1,37 @@ +[ + { + "id": "absent/bid/anonymous", + "kind": "bid", + "body": "{}" + }, + { + "id": "absent/locations/anonymous", + "kind": "locations", + "body": "[]" + }, + { + "id": "zero/bid/anonymous", + "kind": "bid", + "body": "{\"bid\":42}" + }, + { + "id": "zero/bid/admin", + "kind": "bid", + "body": "{\"bid\":99}" + }, + { + "id": "zero/locations/anonymous", + "kind": "locations", + "body": "[{\"lat\":0,\"lng\":1e+21,\"n\":1}]" + }, + { + "id": "gap/bid/anonymous", + "kind": "bid", + "body": "{\"bid\":-1}" + }, + { + "id": "cache/expired/bid", + "kind": "bid", + "body": "{\"bid\":55}" + } +] diff --git a/queue-rs/polis-contracts/src/fixtures/my-invites-csv.json b/queue-rs/polis-contracts/src/fixtures/my-invites-csv.json new file mode 100644 index 000000000..5ff1e7cc6 --- /dev/null +++ b/queue-rs/polis-contracts/src/fixtures/my-invites-csv.json @@ -0,0 +1,14 @@ +[ + { + "id": "empty/participant", + "csv": "invite_code,status,created_at" + }, + { + "id": "empty/owner", + "csv": "invite_code,status,created_at\n" + }, + { + "id": "populated/participant", + "csv": "invite_code,status,created_at\ngenerated invite,unused,Sat Feb 29 2020\n\"comma,quote\"\"line\nnext\",unused,Sat Feb 29 2020\ncarriage\rreturn,unused,\nunicode 🙂,unused,Sat Feb 29 2020" + } +] diff --git a/queue-rs/polis-contracts/src/fixtures/participants-read.json b/queue-rs/polis-contracts/src/fixtures/participants-read.json new file mode 100644 index 000000000..8aa96696f --- /dev/null +++ b/queue-rs/polis-contracts/src/fixtures/participants-read.json @@ -0,0 +1,29 @@ +[ + "{\"pid\":0,\"uid\":3,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "null", + "{\"pid\":2,\"uid\":2,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":1,\"uid\":200001,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":3,\"uid\":200004,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":1,\"uid\":3,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":2,\"uid\":2,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":0,\"uid\":200001,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":3,\"uid\":200004,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":0,\"uid\":3,\"zid\":1033,\"vote_count\":1,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":1,\"uid\":3,\"zid\":1003,\"vote_count\":1,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":\"0\",\"nsli\":0,\"mod\":0,\"created\":\"1700000000000\"}", + "{\"pid\":0,\"uid\":3,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":null,\"nsli\":0,\"mod\":0,\"created\":null}", + "{\"pid\":2,\"uid\":2,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":null,\"nsli\":0,\"mod\":0,\"created\":null}", + "{\"pid\":1,\"uid\":200001,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":null,\"nsli\":0,\"mod\":0,\"created\":null}", + "{\"pid\":3,\"uid\":200004,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":null,\"nsli\":0,\"mod\":0,\"created\":null}", + "{\"pid\":1,\"uid\":3,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":null,\"nsli\":0,\"mod\":0,\"created\":null}", + "{\"pid\":2,\"uid\":2,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":null,\"nsli\":0,\"mod\":0,\"created\":null}", + "{\"pid\":0,\"uid\":200001,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":null,\"nsli\":0,\"mod\":0,\"created\":null}", + "{\"pid\":3,\"uid\":200004,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"0\",\"subscribed\":0,\"last_notified\":null,\"nsli\":0,\"mod\":0,\"created\":null}", + "{\"pid\":0,\"uid\":3,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"9223372036854775807\",\"subscribed\":0,\"last_notified\":\"-9223372036854775808\",\"nsli\":0,\"mod\":0,\"created\":\"9007199254740993\"}", + "{\"pid\":2,\"uid\":2,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"9223372036854775807\",\"subscribed\":0,\"last_notified\":\"-9223372036854775808\",\"nsli\":0,\"mod\":0,\"created\":\"9007199254740993\"}", + "{\"pid\":1,\"uid\":200001,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"9223372036854775807\",\"subscribed\":0,\"last_notified\":\"-9223372036854775808\",\"nsli\":0,\"mod\":0,\"created\":\"9007199254740993\"}", + "{\"pid\":3,\"uid\":200004,\"zid\":1033,\"vote_count\":0,\"last_interaction\":\"9223372036854775807\",\"subscribed\":0,\"last_notified\":\"-9223372036854775808\",\"nsli\":0,\"mod\":0,\"created\":\"9007199254740993\"}", + "{\"pid\":1,\"uid\":3,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"9223372036854775807\",\"subscribed\":0,\"last_notified\":\"-9223372036854775808\",\"nsli\":0,\"mod\":0,\"created\":\"9007199254740993\"}", + "{\"pid\":2,\"uid\":2,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"9223372036854775807\",\"subscribed\":0,\"last_notified\":\"-9223372036854775808\",\"nsli\":0,\"mod\":0,\"created\":\"9007199254740993\"}", + "{\"pid\":0,\"uid\":200001,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"9223372036854775807\",\"subscribed\":0,\"last_notified\":\"-9223372036854775808\",\"nsli\":0,\"mod\":0,\"created\":\"9007199254740993\"}", + "{\"pid\":3,\"uid\":200004,\"zid\":1003,\"vote_count\":0,\"last_interaction\":\"9223372036854775807\",\"subscribed\":0,\"last_notified\":\"-9223372036854775808\",\"nsli\":0,\"mod\":0,\"created\":\"9007199254740993\"}" +] diff --git a/queue-rs/polis-contracts/src/fixtures/ptptois.json b/queue-rs/polis-contracts/src/fixtures/ptptois.json new file mode 100644 index 000000000..4f750f18c --- /dev/null +++ b/queue-rs/polis-contracts/src/fixtures/ptptois.json @@ -0,0 +1,6 @@ +[ + "[]", + "[{\"mod\":2,\"pid\":0,\"xInfo\":{\"x_profile_image_url\":\"https://example.invalid/avatar\",\"x_name\":\"Name & 🙂\"},\"conversation_id\":\"2p027r61033\"}]", + "[{\"mod\":2,\"pid\":0,\"xInfo\":{\"x_profile_image_url\":\"https://example.invalid/avatar\",\"x_name\":null},\"conversation_id\":\"2p027r61033\"}]", + "[{\"mod\":2,\"x_profile_image_url\":\"\",\"xid\":\"\",\"pid\":0,\"conversation_id\":\"2p027r61033\"}]" +] diff --git a/queue-rs/polis-contracts/src/lib.rs b/queue-rs/polis-contracts/src/lib.rs index 1e600e116..a8fb93415 100644 --- a/queue-rs/polis-contracts/src/lib.rs +++ b/queue-rs/polis-contracts/src/lib.rs @@ -6,6 +6,7 @@ pub mod bid_to_pid; pub mod collective_statement; pub mod connection; pub mod contexts; +pub mod conversation_pages; pub mod conversation_preload; pub mod conversation_stats; pub mod create_page; @@ -25,17 +26,22 @@ pub mod einvites_read; pub mod integrate_page; pub mod legacy_conversations; pub mod legacy_pca; +pub mod link_pages; +pub mod math_membership; pub mod metadata_answers; pub mod metadata_choices; pub mod metadata_questions; pub mod metadata_read; +pub mod my_invites_csv; pub mod ops_catchall; pub mod ops_page; pub mod ops_whoami; pub mod other_conversations_page; +pub mod participants_read; pub mod participation_read; pub mod post_comments; pub mod post_votes; +pub mod ptptois; pub mod recent_activity; pub mod recent_started; pub mod reports_read; diff --git a/queue-rs/polis-contracts/src/link_pages.rs b/queue-rs/polis-contracts/src/link_pages.rs new file mode 100644 index 000000000..9a2da6a91 --- /dev/null +++ b/queue-rs/polis-contracts/src/link_pages.rs @@ -0,0 +1,85 @@ +//! Conversation link HTML as emitted by the existing public page handlers. +use serde::{Deserialize, Serialize}; +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub enum Page { + Participation, + Moderation, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Request { + pub page: Page, + pub conversation_id: String, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Response { + pub html: String, +} +impl Response { + pub fn participation(cid: &str) -> Self { + Self { + html: format!("{cid}"), + } + } + // The source sends these strings verbatim, including markup. Escaping them + // would change the public response and belongs to a separate change. + pub fn moderation(cid: &str, title: &str, description: Option<&str>) -> Self { + let mut html = format!( + "{title}

moderate

" + ); + if let Some(description) = description.filter(|s| !s.is_empty()) { + html.push_str(&format!("

{description}

")); + } + Self { html } + } +} +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn markup_and_empty_description_are_preserved() { + assert_eq!( + Response::participation("4fixture").html, + "4fixture" + ); + assert_eq!( + Response::moderation("4fixture", "topic", Some("")), + Response::moderation("4fixture", "topic", None) + ); + assert!( + Response::moderation("4fixture", "1700000000000", Some("🙂 & text")) + .html + .ends_with("

🙂 & text

") + ); + } + #[test] + fn unchanged_node_recordings_match_html_contract() { + #[derive(Deserialize)] + struct Recorded { + page: Page, + conversation_id: String, + html: String, + } + let rows: Vec = + serde_json::from_str(include_str!("fixtures/link-pages.json")).unwrap(); + assert_eq!(rows.len(), 11); + for row in rows { + let response = match row.page { + Page::Participation => Response::participation(&row.conversation_id), + Page::Moderation => { + let (title, description) = match row.conversation_id.as_str() { + "4linkplain" => ("Generated topic", Some("Generated description")), + "4linkempty" => ("1700000000000", None), + "4linkmarkup" => ("Topic & 🙂", Some("raw markup")), + "4linknull" => ("null", Some("")), + "4linkbigint" => ("9223372036854775807", None), + _ => panic!("unexpected fixture"), + }; + Response::moderation(&row.conversation_id, title, description) + } + }; + assert_eq!(response.html, row.html, "{}", row.conversation_id); + } + } +} diff --git a/queue-rs/polis-contracts/src/math_membership.rs b/queue-rs/polis-contracts/src/math_membership.rs new file mode 100644 index 000000000..e3d9e6fac --- /dev/null +++ b/queue-rs/polis-contracts/src/math_membership.rs @@ -0,0 +1,55 @@ +//! Current bucket membership and the locations in one group. +use serde::{Deserialize, Serialize}; +pub const BID_PATH: &str = "/api/v3/bid"; +pub const LOCATIONS_PATH: &str = "/api/v3/locations"; +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub enum Kind { + Bid, + Locations, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Request { + pub kind: Kind, + pub conversation_id: String, + pub math_tick: i32, + pub gid: Option, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Bid { + #[serde(skip_serializing_if = "Option::is_none")] + pub bid: Option, +} +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Location { + pub lat: crate::wire::JsNumber, + pub lng: crate::wire::JsNumber, + pub n: i32, +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn unchanged_node_bucket_and_location_bytes() { + #[derive(Deserialize)] + struct Fixture { + id: String, + kind: String, + body: String, + } + let fixtures: Vec = + serde_json::from_str(include_str!("fixtures/math-membership.json")).unwrap(); + for f in fixtures { + let encoded = if f.kind == "bid" { + serde_json::to_string(&serde_json::from_str::(&f.body).unwrap()).unwrap() + } else { + serde_json::to_string(&serde_json::from_str::>(&f.body).unwrap()) + .unwrap() + }; + assert_eq!(encoded, f.body, "{}", f.id); + } + } +} diff --git a/queue-rs/polis-contracts/src/my_invites_csv.rs b/queue-rs/polis-contracts/src/my_invites_csv.rs new file mode 100644 index 000000000..369d7890f --- /dev/null +++ b/queue-rs/polis-contracts/src/my_invites_csv.rs @@ -0,0 +1,50 @@ +//! Participant-owned CSV, including the distinct header-only newline shapes. +use serde::{Deserialize, Serialize}; +pub const PATH: &str = "/api/v3/treevite/myInvites/csv"; +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Request { + pub conversation_id: String, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Response { + pub conversation_id: String, + pub csv: String, +} +pub fn escape(s: &str) -> String { + let escaped = s.replace('"', "\"\""); + if s.contains([',', '"', '\n']) { + format!("\"{escaped}\"") + } else { + escaped + } +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn unchanged_node_csv_shapes_and_escape_bytes() { + #[derive(Deserialize)] + struct Fixture { + id: String, + csv: String, + } + let fixtures: Vec = + serde_json::from_str(include_str!("fixtures/my-invites-csv.json")).unwrap(); + for fixture in fixtures { + let expected = if fixture.id.starts_with("populated/") { + format!( + "invite_code,status,created_at\ngenerated invite,unused,Sat Feb 29 2020\n{},unused,Sat Feb 29 2020\ncarriage\rreturn,unused,\nunicode 🙂,unused,Sat Feb 29 2020", + escape("comma,quote\"line\nnext") + ) + } else if fixture.id.contains("/owner") { + "invite_code,status,created_at\n".into() + } else { + "invite_code,status,created_at".into() + }; + assert_eq!(fixture.csv, expected, "{}", fixture.id); + } + } +} diff --git a/queue-rs/polis-contracts/src/participants_read.rs b/queue-rs/polis-contracts/src/participants_read.rs new file mode 100644 index 000000000..978dd8d54 --- /dev/null +++ b/queue-rs/polis-contracts/src/participants_read.rs @@ -0,0 +1,41 @@ +//! The existing participant-row projection, including its internal integer ID. +use serde::{Deserialize, Serialize}; +pub const PATH: &str = "/api/v3/participants"; +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Request { + pub conversation_id: String, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Participant { + pub pid: Option, + pub uid: Option, + pub zid: Option, + pub vote_count: Option, + pub last_interaction: Option, + pub subscribed: Option, + pub last_notified: Option, + pub nsli: Option, + #[serde(rename = "mod")] + pub moderation: Option, + pub created: Option, +} +pub type Response = Option; + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn unchanged_node_rows_preserve_order_types_and_null_membership() { + let bodies: Vec = + serde_json::from_str(include_str!("fixtures/participants-read.json")).unwrap(); + assert!(!bodies.is_empty()); + assert!(bodies.iter().any(|s| s == "null")); + assert!(bodies.iter().any(|s| s.contains("9223372036854775807"))); + for body in bodies { + let row: Response = serde_json::from_str(&body).unwrap(); + assert_eq!(serde_json::to_string(&row).unwrap(), body); + } + } +} diff --git a/queue-rs/polis-contracts/src/ptptois.rs b/queue-rs/polis-contracts/src/ptptois.rs new file mode 100644 index 000000000..dc6fb6650 --- /dev/null +++ b/queue-rs/polis-contracts/src/ptptois.rs @@ -0,0 +1,50 @@ +//! Social participants, preserving top-level omission and nested null values. +use serde::{Deserialize, Serialize}; +pub const PATH: &str = "/api/v3/ptptois"; +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Request { + pub conversation_id: String, + pub moderation: Option, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct XInfo { + pub x_profile_image_url: String, + pub x_name: Option, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Participant { + #[serde(rename = "mod", skip_serializing_if = "Option::is_none")] + pub moderation: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub x_profile_image_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub xid: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub x_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub pid: Option, + #[serde(rename = "xInfo", skip_serializing_if = "Option::is_none")] + pub x_info: Option, + pub conversation_id: String, +} +pub type Response = Vec; + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn unchanged_node_social_rows_keep_field_order_and_nested_nulls() { + let bodies: Vec = + serde_json::from_str(include_str!("fixtures/ptptois.json")).unwrap(); + assert!(bodies.iter().any(|s| s.contains("xInfo"))); + assert!(bodies.iter().any(|s| s.contains("xid"))); + assert!(bodies.iter().any(|s| s.contains("null"))); + for body in bodies { + let response: Response = serde_json::from_str(&body).unwrap(); + assert_eq!(serde_json::to_string(&response).unwrap(), body); + } + } +} From 0b26f95e265d932303d5c0617787553ecccad8bc Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Sat, 24 Oct 2026 10:05:56 -0700 Subject: [PATCH 29/30] comments: a seed CSV without its header row is refused with a clear message (#3262) * comments: a seed CSV without its header row is refused with a clear message A seed CSV's first row must be the header comment_text, optionally with original_id. A file without it answered 200 after treating its first comment as column names and skipping the rest, and some wrong headers stored comments anyway. The upload is now checked before any participant or comment is created and refused with 400 polis_err_csv_header, "CSV header must be comment_text, optionally with original_id.", which the admin upload form shows. Well-formed one- and two-column uploads are unchanged. Co-Authored-By: Claude Opus 5.5 * comments: a seed CSV saved with a byte-order mark is read normally Excel's 'CSV UTF-8' export starts with a byte-order mark, which made the first header read as '\ufeffcomment_text' and the upload be refused. The parser now drops the mark, so those files upload as before. Four cases cover both header shapes and quoting with a leading mark. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../ModerateCommentSeed.upload.test.js | 86 +++++----- .../integration/comments-bulk-header.test.ts | 150 ++++++++++++++++++ server/src/routes/comments.ts | 36 ++++- 3 files changed, 230 insertions(+), 42 deletions(-) create mode 100644 server/__tests__/integration/comments-bulk-header.test.ts diff --git a/client-admin/src/components/conversation-admin/ModerateCommentSeed.upload.test.js b/client-admin/src/components/conversation-admin/ModerateCommentSeed.upload.test.js index 1ce636cc3..d9d111de3 100644 --- a/client-admin/src/components/conversation-admin/ModerateCommentSeed.upload.test.js +++ b/client-admin/src/components/conversation-admin/ModerateCommentSeed.upload.test.js @@ -45,48 +45,60 @@ describe('seed CSV upload with real actions and reducer', () => { jest.resetAllMocks() }) - it('shows the server error, re-enables submission, and allows a successful retry', async () => { - let rejectUpload - PolisNet.polisPost.mockReturnValueOnce( - new Promise((resolve, reject) => { - rejectUpload = reject + it.each([ + [500, 'The seed CSV could not be imported.'], + [ + 400, + JSON.stringify({ + error: 'polis_err_csv_header', + message: 'CSV header must be comment_text, optionally with original_id.', + status: 400 }) - ) - const onComplete = jest.fn() - const { button, store } = await prepareUpload(onComplete) + ] + ])( + 'shows a %s error, re-enables submission, and allows a successful retry', + async (status, responseText) => { + let rejectUpload + PolisNet.polisPost.mockReturnValueOnce( + new Promise((resolve, reject) => { + rejectUpload = reject + }) + ) + const onComplete = jest.fn() + const { button, store } = await prepareUpload(onComplete) - fireEvent.click(button) - expect(button).toBeDisabled() - expect(button).toHaveTextContent('Saving...') - expect(PolisNet.polisPost).toHaveBeenCalledWith('/api/v3/comments-bulk', { - csv, - conversation_id: 'test-conversation', - is_seed: true - }) + fireEvent.click(button) + expect(button).toBeDisabled() + expect(button).toHaveTextContent('Saving...') + expect(PolisNet.polisPost).toHaveBeenCalledWith('/api/v3/comments-bulk', { + csv, + conversation_id: 'test-conversation', + is_seed: true + }) - const responseText = 'The seed CSV could not be imported.' - await act(async () => { - rejectUpload({ status: 500, responseText }) - }) + await act(async () => { + rejectUpload({ status, responseText }) + }) - expect(screen.getByText(responseText)).toBeInTheDocument() - expect(button).toBeEnabled() - expect(button).toHaveTextContent('Submit') - expect(store.getState().seed_comments).toMatchObject({ - loading: false, - error: responseText, - success: false - }) - expect(onComplete).not.toHaveBeenCalled() + expect(screen.getByText(responseText)).toBeInTheDocument() + expect(button).toBeEnabled() + expect(button).toHaveTextContent('Submit') + expect(store.getState().seed_comments).toMatchObject({ + loading: false, + error: responseText, + success: false + }) + expect(onComplete).not.toHaveBeenCalled() - PolisNet.polisPost.mockResolvedValueOnce({}) - fireEvent.click(button) - expect(screen.queryByText(responseText)).not.toBeInTheDocument() - await waitFor(() => expect(button).toHaveTextContent('Success!')) - expect(button).toBeEnabled() - expect(PolisNet.polisPost).toHaveBeenCalledTimes(2) - expect(onComplete).toHaveBeenCalledTimes(1) - }) + PolisNet.polisPost.mockResolvedValueOnce({}) + fireEvent.click(button) + expect(screen.queryByText(responseText)).not.toBeInTheDocument() + await waitFor(() => expect(button).toHaveTextContent('Success!')) + expect(button).toBeEnabled() + expect(PolisNet.polisPost).toHaveBeenCalledTimes(2) + expect(onComplete).toHaveBeenCalledTimes(1) + } + ) it.each([true, false])( 'completes a successful upload (callback provided: %s)', diff --git a/server/__tests__/integration/comments-bulk-header.test.ts b/server/__tests__/integration/comments-bulk-header.test.ts new file mode 100644 index 000000000..e85855450 --- /dev/null +++ b/server/__tests__/integration/comments-bulk-header.test.ts @@ -0,0 +1,150 @@ +import { randomUUID } from "crypto"; +import { beforeAll, describe, expect, test } from "@jest/globals"; +import type { Agent } from "supertest"; +import { + createConversation, + getJwtAuthenticatedAgent, +} from "../setup/api-test-helpers"; +import { getPooledTestUser } from "../setup/test-user-helpers"; +import { pool } from "../setup/db-test-helpers"; + +describe("bulk seed CSV header", () => { + let owner: Agent; + + beforeAll(async () => { + const user = getPooledTestUser(1); + ({ agent: owner } = await getJwtAuthenticatedAgent({ + email: user.email, + hname: user.name, + password: user.password, + })); + }); + + async function conversation() { + const id = await createConversation(owner, { + topic: `CSV header ${randomUUID()}`, + }); + const { rows } = await pool.query( + "select zid from zinvites where zinvite = $1", + [id] + ); + return { id, zid: rows[0].zid as number }; + } + + async function stored(zid: number) { + const tables = [ + "conversations", + "participants", + "comments", + "votes", + "votes_latest_unique", + ]; + return Promise.all( + tables.map(async (table) => { + const { rows } = await pool.query( + `select * from ${table} where zid = $1`, + [zid] + ); + return { table, rows }; + }) + ); + } + + test.each([ + ["one headerless comment", "First seed"], + ["multiple headerless comments", "First seed\nSecond seed"], + [ + "headerless comments with IDs", + `First seed,${randomUUID()}\nSecond seed,${randomUUID()}`, + ], + ["wrong name", "text\nFirst seed\nSecond seed"], + ["wrong case", "Comment_text\nFirst seed"], + ["header whitespace", " comment_text\nFirst seed"], + ["ID without text", `original_id\n${randomUUID()}`], + ["unknown column", "comment_text,source\nFirst seed,example"], + ["duplicate column", "comment_text,comment_text\nFirst seed,Second seed"], + ["wrong header with no data", "text"], + ["no nonempty row", "\n\n"], + ])("refuses %s before storing anything", async (_label, csv) => { + const { id, zid } = await conversation(); + const before = await stored(zid); + const response = await owner.post("/api/v3/comments-bulk").send({ + conversation_id: id, + is_seed: true, + csv, + }); + + expect({ + status: response.status, + body: response.body, + stored: await stored(zid), + }).toEqual({ + status: 400, + body: { + error: "polis_err_csv_header", + message: + "CSV header must be comment_text, optionally with original_id.", + status: 400, + }, + stored: before, + }); + }); + + test.each( + ["text only", "text then ID", "ID then text", "quoted header"].flatMap( + (format) => [ + [format, ""], + [format, "\uFEFF"], + ] + ) + )( + "keeps a well-formed upload unchanged: %s (BOM: %j)", + async (format, bom) => { + const { id, zid } = await conversation(); + const ids = [randomUUID(), randomUUID()]; + const texts = ["First seed", "Second seed"]; + const csv = + format === "text only" + ? ["comment_text", ...texts].join("\n") + : format === "ID then text" + ? [ + "original_id,comment_text", + ...texts.map((txt, i) => `${ids[i]},${txt}`), + ].join("\n") + : [ + format === "quoted header" + ? '"comment_text","original_id"' + : "comment_text,original_id", + ...texts.map((txt, i) => `${txt},${ids[i]}`), + ].join("\r\n"); + const response = await owner.post("/api/v3/comments-bulk").send({ + conversation_id: id, + is_seed: true, + csv: bom + csv, + }); + expect(response.status).toBe(200); + expect(response.body).toEqual({ + currentPid: 0, + results: texts.map((txt, i) => ({ + txt, + tid: i, + status: "success", + ...(format === "text only" ? {} : { original_id: ids[i] }), + })), + }); + const { rows } = await pool.query( + "select txt, original_id, is_seed, mod, active from comments where zid = $1 order by tid", + [zid] + ); + expect(rows).toEqual( + texts.map((txt, i) => ({ + txt, + original_id: format === "text only" ? null : ids[i], + is_seed: true, + mod: 1, + active: true, + })) + ); + } + ); +}); diff --git a/server/src/routes/comments.ts b/server/src/routes/comments.ts index 4d8035ed7..f8967a41d 100644 --- a/server/src/routes/comments.ts +++ b/server/src/routes/comments.ts @@ -831,6 +831,7 @@ async function handle_POST_comments_bulk( // @ts-expect-error body parsing const csv = req.body.csv; let pid = initialPid; + const invalidHeader = new Error("Invalid CSV header"); if (!csv) { failJson(res, 400, "polis_err_param_missing_csv"); return; @@ -865,17 +866,35 @@ async function handle_POST_comments_bulk( return; } + // Validate before creating a participant or storing any comments. Otherwise + // a headerless upload consumes its first comment as column names. + let hasHeader = false; + const records = parse(String(csv), { + bom: true, + columns: (header: string[]) => { + if ( + !( + (header.length === 1 && header[0] === "comment_text") || + (header.length === 2 && + header.includes("comment_text") && + header.includes("original_id")) + ) + ) { + throw invalidHeader; + } + hasHeader = true; + return header; + }, + skip_empty_lines: true, + }); + if (!hasHeader) throw invalidHeader; + const finalPid = await doGetPid(); if (finalPid < 0) { failJson(res, 500, "polis_err_post_comment_bad_pid"); return; } - const records = parse(String(csv), { - columns: true, - skip_empty_lines: true, - }); - const results = []; let lastInteractionTime = new Date(0); @@ -980,6 +999,13 @@ async function handle_POST_comments_bulk( currentPid: pid, }); } catch (err: any) { + if (err === invalidHeader) { + failJson(res, 400, "polis_err_csv_header", undefined, { + message: + "CSV header must be comment_text, optionally with original_id.", + }); + return; + } failJson(res, 500, "polis_err_post_comments_bulk", err); } } From 1c6e874fcb8eeab8b7de7408534721ed9a581431 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Sat, 24 Oct 2026 10:27:07 -0700 Subject: [PATCH 30/30] participants: the participant-number lock is held to commit, so participants joining at once each get a number on the first try (migration 000044) (#3266) The pid_auto trigger numbers a conversation's participants MAX(pid) + 1 under a per-conversation advisory lock, but took it as a session lock that pid_auto_unlock released when the INSERT ended, before COMMIT. A second join could read the same MAX(pid) and fail with 23505 on (zid, pid); one retry hid most of these, and two collisions in a row reached the caller as HTTP 500, for example a Treevite invite accept that left the invitation unused. Migration 000044 takes pg_advisory_xact_lock on the same key and drops pid_auto_unlock and its trigger, the participant twin of 000042. Numbering, participant_count and the down migration are as before. Co-authored-by: Claude Opus 5.5 --- coordinator-rs/src/schema/catalog.json | 4 + coordinator-rs/src/schema/mod.rs | 2 +- docs/migration-legacy-contract.md | 7 +- docs/migrations.md | 5 +- queue-rs/polis-migrate/tests/forward.py | 3 +- .../participation-under-load.test.ts | 80 +++- .../participation-pg/join-lock.pgtest.ts | 29 +- .../participant-numbers-migration.pgtest.ts | 411 ++++++++++++++++++ .../participant-numbers.pgtest.ts | 355 +++++++++++++++ .../statement-numbers-migration.pgtest.ts | 36 +- server/bin/build-migration-report.py | 3 +- server/characterization/README.md | 6 +- .../recordings/index.json | 3 +- .../000044_pid_auto_transaction_lock.sql | 75 ++++ server/postgres/migrations/compat.txt | 3 +- .../000044_restore_pid_auto_session_lock.sql | 66 +++ server/postgres/migrations/release.txt | 1 + .../migrations/report/first-deploy.sql | 5 +- server/src/participant.ts | 29 +- server/src/workers/import-processor.ts | 12 +- 20 files changed, 1075 insertions(+), 60 deletions(-) create mode 100644 server/__tests__/participation-pg/participant-numbers-migration.pgtest.ts create mode 100644 server/__tests__/participation-pg/participant-numbers.pgtest.ts create mode 100644 server/postgres/migrations/000044_pid_auto_transaction_lock.sql create mode 100644 server/postgres/migrations/down/000044_restore_pid_auto_session_lock.sql diff --git a/coordinator-rs/src/schema/catalog.json b/coordinator-rs/src/schema/catalog.json index 08661fdf4..0906491d7 100644 --- a/coordinator-rs/src/schema/catalog.json +++ b/coordinator-rs/src/schema/catalog.json @@ -12814,6 +12814,10 @@ { "path": "server/postgres/migrations/000043_add_conversation_activity_indexes.sql", "sha256": "1c85ef8a67bb0add2bcf6dd7e38fabb977c26fe004994cf78e06fed8eda9b906" + }, + { + "path": "server/postgres/migrations/000044_pid_auto_transaction_lock.sql", + "sha256": "8eaffb393aca2b89ffe41264a1a9676f83a74685866a095befd3bb648784903f" } ] } diff --git a/coordinator-rs/src/schema/mod.rs b/coordinator-rs/src/schema/mod.rs index 7bf6dcd56..01a5fdb33 100644 --- a/coordinator-rs/src/schema/mod.rs +++ b/coordinator-rs/src/schema/mod.rs @@ -1,7 +1,7 @@ //! Descriptive storage types only. No runtime caller adopts these rows. //! //! Source inventory: server/postgres/migrations/000000_initial.sql through -//! 000042_tid_auto_transaction_lock.sql. The adjacent catalog was measured on +//! 000044_pid_auto_transaction_lock.sql. The adjacent catalog was measured on //! PostgreSQL 17.11; tests bind it to every migration's bytes. A changed or new //! migration requires a fresh isolated census and review, even for a change //! that does not alter columns. This intentionally avoids parsing PL/pgSQL DDL. diff --git a/docs/migration-legacy-contract.md b/docs/migration-legacy-contract.md index 789659447..825074455 100644 --- a/docs/migration-legacy-contract.md +++ b/docs/migration-legacy-contract.md @@ -46,8 +46,9 @@ advance a live sequence to match bootstrap. Reviewed implementations of `random_string(integer)` and `random_polis_site_id()` are executable equivalents of the public historical sources; formatting fingerprints differ. Adoption never replaces those routines. After adoption, migration 000042 replaces -`tid_auto()` (the same body, with the advisory lock held to the end of the -transaction) and drops `tid_auto_unlock()` with its trigger; the others are +`tid_auto()` and migration 000044 replaces `pid_auto()` (each the same body, +with the advisory lock held to the end of the transaction), and they drop +`tid_auto_unlock()` and `pid_auto_unlock()` with their triggers; the others are never replaced. Their exact historical source bindings are in the deployment's private reconciliation record. @@ -117,7 +118,7 @@ unique constraint addition, contributor rename or data cleanup is selected. | users_uid_seq | SYNC BEFORE STABLE | Record exact bigint sequence with integer owning column; preserve current state and consumers, no setval/ALTER. Existing adoption does not check its bounds. | | random_polis_site_id(integer) | SET ASIDE | Retain unused integer overload as ancillary legacy state; no current direct caller established. | | get_times_for_most_recent_visible_comments() | SYNC BEFORE STABLE | Record reviewed production routine body/fingerprint for live trigger/caller contract. Executable equivalence established; no CREATE OR REPLACE and no existing body-hash adoption refusal. | -| pid_auto() | SYNC BEFORE STABLE | Record reviewed production routine body/fingerprint for live trigger/caller contract. Executable equivalence established; no CREATE OR REPLACE and no existing body-hash adoption refusal. | +| pid_auto() | SYNC BEFORE STABLE | Record reviewed production routine body/fingerprint for live trigger/caller contract. Executable equivalence established; no CREATE OR REPLACE and no existing body-hash adoption refusal. Migration 000044, after adoption, replaces it with the transaction-scoped lock and drops `pid_auto_unlock()`. | | tid_auto() | SYNC BEFORE STABLE | Record reviewed production routine body/fingerprint for live trigger/caller contract. Executable equivalence established; no CREATE OR REPLACE and no existing body-hash adoption refusal. Migration 000042, after adoption, replaces it with the transaction-scoped lock and drops `tid_auto_unlock()`. | | random_string(integer) | SYNC BEFORE STABLE | Record reviewed production routine body/fingerprint for live trigger/caller contract. Executable equivalence established; no CREATE OR REPLACE and no existing body-hash adoption refusal. | | random_polis_site_id() | SYNC BEFORE STABLE | Record reviewed production routine body/fingerprint for live trigger/caller contract. Executable equivalence established; no CREATE OR REPLACE and no existing body-hash adoption refusal. | diff --git a/docs/migrations.md b/docs/migrations.md index dc683744a..86d5ba834 100644 --- a/docs/migrations.md +++ b/docs/migrations.md @@ -233,7 +233,7 @@ before. `apply` never runs this release's pending SQL after a tolerated newer migration; that order is refused before any change. The rule only helps releases that contain it: a release built before it refuses every newer row. -Declarations for 000019–000043 (the older code is the release just before each +Declarations for 000019–000044 (the older code is the release just before each migration, as recorded in `release.txt` history): | Migration | Declared | Evidence | @@ -254,9 +254,10 @@ migration, as recorded in `release.txt` history): | 000041 Delphi run record | additive | One new read function, `pd_run_record(env, job)`: STABLE, SECURITY DEFINER with a pinned `search_path`, owned by `polis_queue_owner`, EXECUTE granted to `polis_queue_executor` only. No table, row, column or existing function changes and no table grant; nothing in the earlier release calls it, and its one reader (the polis-api run-record route) is off by default and hands back to Node when the function is missing. It takes no table lock. Number 000040 is reserved for another draft. Reversal: `down/000041_drop_delphi_run_record.sql` drops the function (it stores nothing). The runner's `forward.py` tolerates it as additive. | | 000042 statement-number lock to commit | additive | `tid_auto` (BEFORE INSERT on `comments`) takes `pg_advisory_xact_lock` instead of the session lock `pg_advisory_lock`, on the same key, so a conversation's statement-number lock is held until the inserting transaction ends rather than released before it commits; `tid_auto_unlock` and its AFTER INSERT trigger are dropped. Numbering is unchanged (MAX(tid) + 1 per conversation, from 0, no gaps); no table, column, index, constraint or row changes. No code in the earlier release calls `tid_auto_unlock` or takes the lock; every writer lets the trigger assign `tid` and reads it back, so an earlier release inserts and numbers statements as before. Locks: `DROP TRIGGER` takes ACCESS EXCLUSIVE on `comments` until the file commits, waiting at most the 5 s `lock_timeout` for transactions already using `comments`; comment reads and writes queue behind it for that wait, once; on timeout nothing changes and the deploy can be retried. Reversal: `down/000042_restore_tid_auto_session_lock.sql` restores both functions and the trigger exactly as `000000_initial.sql` defines them (SHARE ROW EXCLUSIVE on `comments`, bounded at 5 s), and brings back the race this migration removes. The runner's `forward.py` tolerates it as additive. | | 000043 activity indexes | additive | Three ordinary btree indexes only; no table, function, row or application SQL changes. Concurrent builds preserve ordinary participation writes. | +| 000044 participant-number lock to commit | additive | `pid_auto` (BEFORE INSERT on `participants`) takes `pg_advisory_xact_lock` instead of the session lock `pg_advisory_lock`, on the same key, so a conversation's participant-number lock is held until the inserting transaction ends rather than released before it commits; `pid_auto_unlock` and its AFTER INSERT trigger are dropped. Numbering is unchanged (MAX(pid) + 1 per conversation, from 0, no gaps), as is the `conversations.participant_count` update, whose row lock was already held to commit, so no join waits longer; no table, column, index, constraint or row changes. No code in the earlier release calls `pid_auto_unlock` or takes the lock; every writer lets the trigger assign `pid` and reads it back, so an earlier release joins and numbers participants as before. Locks: `DROP TRIGGER` takes ACCESS EXCLUSIVE on `participants` until the file commits, waiting at most the 5 s `lock_timeout` for transactions already using `participants`; participant reads and writes (votes, comments, nextComment, participationInit) queue behind it for that wait, once; on timeout nothing changes and the deploy can be retried. Reversal: `down/000044_restore_pid_auto_session_lock.sql` restores both functions and the trigger exactly as `000000_initial.sql` defines them (SHARE ROW EXCLUSIVE on `participants`, bounded at 5 s), and brings back the race and the held lock this migration removes. The runner's `forward.py` tolerates it as additive. | So a rollback to a release with this rule that lists 000027 starts beside -000028–000031, 000038, 000039, 000041–000043; a rollback past 000027 (or 000024) refuses, as it must: the +000028–000031, 000038, 000039, 000041–000044; a rollback past 000027 (or 000024) refuses, as it must: the earlier queue daemon would exit on the newer contract. ## CI and local test stacks diff --git a/queue-rs/polis-migrate/tests/forward.py b/queue-rs/polis-migrate/tests/forward.py index a160ebb78..8f30ada7e 100644 --- a/queue-rs/polis-migrate/tests/forward.py +++ b/queue-rs/polis-migrate/tests/forward.py @@ -42,7 +42,8 @@ def test_01_ledger_declares_every_migration(self): '000030_create_delphi_writers.sql', '000031_scope_delphi_result_reads.sql', '000038_create_delphi_comment_embeddings.sql', '000039_clear_zinvites_uuid.sql', '000041_create_delphi_run_record.sql', '000042_tid_auto_transaction_lock.sql', - '000043_add_conversation_activity_indexes.sql'}) + '000043_add_conversation_activity_indexes.sql', + '000044_pid_auto_transaction_lock.sql'}) def test_02_deploy_records_declarations(self): db = self.new('records'); p.runner(db, 'deploy') diff --git a/server/__tests__/integration/participation-under-load.test.ts b/server/__tests__/integration/participation-under-load.test.ts index 019e8c684..06a89876e 100644 --- a/server/__tests__/integration/participation-under-load.test.ts +++ b/server/__tests__/integration/participation-under-load.test.ts @@ -7,8 +7,9 @@ * them), then has PARTICIPANTS participants of one conversation each send a * vote, a comment and a nextComment call at the same moment, the way the * participation client sends them. Every one of those requests must answer 200 - * within BUDGET_MS, and every vote and comment sent must end up stored. A last - * case sends bursts of comments with no slow work at all. The slow work: + * within BUDGET_MS, and every vote and comment sent must end up stored. Two last + * cases send bursts of comments, and bursts of first votes from new + * participants, with no slow work at all. The slow work: * * - exports: the conversation's vote exports (votes.csv, * participant-votes.csv, participant-importance.csv, comments.csv), each @@ -976,3 +977,78 @@ describe("comments sent at the same moment in one conversation", () => { expect(stored).toBe(texts.length); }); }); + +// --------------------------------------------------------------------------- +// Participants joining at the same moment, with no slow work at all. + +/** Participants casting their first vote at once (the vote is what makes each + * one a participant of the conversation), and how many new groups do it. */ +const JOIN_PARTICIPANTS = 24; +const JOIN_ROUNDS = 3; + +describe("participants joining at the same moment in one conversation", () => { + const outcomes: Outcome[] = []; + let joined = 0; + let pids: number[] = []; + let participantCount = 0; + beforeAll(async () => { + const before = ( + await admin.query( + "SELECT count(*)::int AS n FROM participants WHERE zid = $1", + [zid] + ) + ).rows[0].n; + for (let round = 0; round < JOIN_ROUNDS; round++) { + const joiners = await Promise.all( + Array.from({ length: JOIN_PARTICIPANTS }, () => + initializeParticipant(conversationId) + ) + ); + // Each joiner's own agent, which carries what participationInit gave it. + const burst = joiners.map(({ agent }, i) => + timed( + round * JOIN_PARTICIPANTS + i, + agent.post("/api/v3/votes").send({ + conversation_id: conversationId, + tid: tids[0], + vote: semanticToWire("pass"), + }) + ) + ); + outcomes.push(...(await Promise.all(burst))); + } + pids = ( + await admin.query( + "SELECT pid FROM participants WHERE zid = $1 ORDER BY pid", + [zid] + ) + ).rows.map((r) => r.pid); + joined = pids.length - before; + participantCount = ( + await admin.query( + "SELECT participant_count FROM conversations WHERE zid = $1", + [zid] + ) + ).rows[0].participant_count; + process.stdout.write( + `${JSON.stringify({ + scenario: "participants joining at the same moment", + sent: outcomes.length, + joined, + rejected: outcomes.filter((o) => o.answered && o.status !== 200).length, + worst_ms: Math.max(...outcomes.map((o) => o.ms)), + })}\n` + ); + }, 120000); + + // The pid_auto trigger numbers a conversation's participants MAX(pid) + 1 + // under a per-conversation advisory lock held until the inserting + // transaction ends (server/postgres/migrations), so participants joining at + // the same moment are numbered one after another. + test("every first vote is answered 200, and each joiner is a participant with its own number", () => { + expectPrompt(outcomes, JOIN_PARTICIPANTS * JOIN_ROUNDS); + expect(joined).toBe(JOIN_PARTICIPANTS * JOIN_ROUNDS); + expect(pids).toEqual(Array.from({ length: pids.length }, (_, i) => i)); + expect(participantCount).toBe(pids.length); + }); +}); diff --git a/server/__tests__/participation-pg/join-lock.pgtest.ts b/server/__tests__/participation-pg/join-lock.pgtest.ts index f1b25729a..fa6cafbce 100644 --- a/server/__tests__/participation-pg/join-lock.pgtest.ts +++ b/server/__tests__/participation-pg/join-lock.pgtest.ts @@ -1,15 +1,17 @@ /** Joining a conversation must never leave its participant lock on a pooled * connection, and must never wait on that lock indefinitely. * - * The pid_auto trigger (server/postgres/migrations/000000_initial.sql) takes a - * SESSION advisory lock per conversation and pid_auto_unlock gives it back only - * after a successful INSERT. Two joiners racing in one conversation can be - * handed the same pid: the second takes the lock as soon as the first's INSERT - * ends, before the first has committed. The second INSERT then fails on - * (zid, pid), and its session keeps the lock through ROLLBACK. If that - * connection goes back to the pool, every later joiner of the conversation on - * any other connection, on this server or another, waits for a lock nobody - * will release, and holds a read-write connection while it waits. + * Before migration 000044, the pid_auto trigger (server/postgres/migrations) + * took a SESSION advisory lock per conversation and pid_auto_unlock gave it + * back only after a successful INSERT. Two joiners racing in one conversation + * could be handed the same pid: the second took the lock as soon as the first's + * INSERT ended, before the first had committed. The second INSERT then failed + * on (zid, pid), and its session kept the lock through ROLLBACK. If that + * connection went back to the pool, every later joiner of the conversation on + * any other connection, on this server or another, waited for a lock nobody + * would release, and held a read-write connection while it waited. Since 000044 + * the lock is held to COMMIT or ROLLBACK (participant-numbers.pgtest.ts); these + * cases still hold. * * Generated data only. Needs DATABASE_URL (superuser, migrated); see * scripts/test-delphi-result-reads.sh. */ @@ -90,16 +92,17 @@ afterAll(async () => { await pg?.end(); }); test("a joiner that loses the pid race leaves no lock behind, still gets a participant, and later joiners do not wait", async () => { const [uidA, uidB, uidC] = await newUsers(3); - // Joiner A has run its INSERT (pid_auto took and gave back the lock); its - // COMMIT, one round trip later in production, has not arrived yet. + // Joiner A has run its INSERT (pid_auto took the lock); its COMMIT, one round + // trip later in production, has not arrived yet. const a = new Client({ connectionString: process.env.DATABASE_URL }); await a.connect(); await a.query("BEGIN"); await a.query("INSERT INTO participants_extended (zid, uid) VALUES ($1, $2) ON CONFLICT (zid, uid) DO NOTHING", [RACE_ZID, uidA]); const pidA = (await a.query("INSERT INTO participants (pid, zid, uid, created) VALUES (NULL, $1, $2, default) RETURNING pid", [RACE_ZID, uidA])).rows[0].pid; - // Joiner B joins through the server. pid_auto gives it A's pid, because A's - // row is not committed, and B then waits on A's conversations row. + // Joiner B joins through the server and waits: since 000044 on the + // participant lock A holds to commit, then gets the next pid; before it, + // pid_auto gave B A's pid and B waited on A's conversations row. const lost = timed(addParticipant(RACE_ZID, uidB)); const deadline = Date.now() + 5000; while ((await waitingInserts()) === 0) { diff --git a/server/__tests__/participation-pg/participant-numbers-migration.pgtest.ts b/server/__tests__/participation-pg/participant-numbers-migration.pgtest.ts new file mode 100644 index 000000000..78228f98c --- /dev/null +++ b/server/__tests__/participation-pg/participant-numbers-migration.pgtest.ts @@ -0,0 +1,411 @@ +/** Migration 000044 (the participant-number lock held to the end of the + * transaction), through the real migration runner: + * - over a database that already has participants, `polis-migrate deploy` + * (what a deployment runs) applies only 000044, every stored participant + * and participant_count is unchanged, and numbering continues from + * MAX(pid) + 1; + * - the release before it still passes `check` beside it (declared additive); + * - its down restores the two triggers exactly as they were, and applying + * 000044 again gives the same catalog; + * - on a fresh database the whole release gives that same catalog; + * - at deploy, a transaction still using participants makes the migration + * wait at most its 5 s lock_timeout and then fail with nothing changed, and + * a join sent while it waits is delayed by that wait, not refused. + * + * Each case makes its own database on the server DATABASE_URL names, and drops + * it. The runner is the one scripts/test-delphi-result-reads.sh builds + * (POLIS_MIGRATE_BIN overrides). Generated data only. */ +import { Client } from "pg"; +import { execFile, execFileSync } from "child_process"; +import fs from "fs"; +import os from "os"; +import path from "path"; + +const ROOT = path.resolve(__dirname, "../../.."); +const MIGRATIONS = path.join(ROOT, "server/postgres/migrations"); +const RUNNER = + process.env.POLIS_MIGRATE_BIN || + path.join(ROOT, "queue-rs/target/debug/polis-migrate"); +const NAME = "000044_pid_auto_transaction_lock.sql"; +const DOWN = path.join( + MIGRATIONS, + "down/000044_restore_pid_auto_session_lock.sql" +); +const DATABASES = ["m000044_upgrade", "m000044_fresh", "m000044_lock"]; +const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); + +let admin: Client; +// The release just before 000044, and this release up to and including it. +let before000044: string; +let through000044: string; + +function url(db: string): string { + const u = new URL(process.env.DATABASE_URL as string); + u.pathname = `/${db}`; + return u.toString(); +} + +/** The runner's stdout; a refusal throws with its stderr. The DSN goes in the + * environment, never in argv. */ +function runner(db: string, command: string, dir = MIGRATIONS): string { + return execFileSync(RUNNER, [command, "--dir", dir], { + env: { ...process.env, DATABASE_URL: url(db) }, + encoding: "utf8", + stdio: ["ignore", "pipe", "pipe"], + }); +} + +/** The runner, without waiting for it: its exit code and output. */ +function runnerAsync( + db: string, + command: string, + dir = MIGRATIONS +): Promise<{ code: number; stdout: string; stderr: string }> { + return new Promise((resolve) => { + execFile( + RUNNER, + [command, "--dir", dir], + { env: { ...process.env, DATABASE_URL: url(db) }, encoding: "utf8" }, + (error, stdout, stderr) => + resolve({ + code: error ? (typeof error.code === "number" ? error.code : 1) : 0, + stdout, + stderr, + }) + ); + }); +} + +/** This release with only the numbered migrations `keep` accepts: their + * files and their release.txt and compat.txt lines. */ +function releaseWith(keep: (name: string) => boolean): string { + const dir = path.join( + fs.mkdtempSync(path.join(os.tmpdir(), "release-")), + "migrations" + ); + fs.cpSync(MIGRATIONS, dir, { recursive: true }); + const numbered = (name: string) => /^\d{6}_.*\.sql$/.test(name); + for (const name of fs.readdirSync(dir)) + if (numbered(name) && !keep(name)) fs.rmSync(path.join(dir, name)); + for (const manifest of ["release.txt", "compat.txt"]) { + const file = path.join(dir, manifest); + const kept = fs + .readFileSync(file, "utf8") + .split("\n") + .filter((line) => { + const name = line.split(" ")[0]; + return !numbered(name) || keep(name); + }); + fs.writeFileSync(file, kept.join("\n")); + } + return dir; +} + +async function connect(db: string): Promise { + const client = new Client({ connectionString: url(db) }); + await client.connect(); + return client; +} + +async function withDatabase( + db: string, + work: (client: Client) => Promise +): Promise { + const client = await connect(db); + try { + return await work(client); + } finally { + await client.end(); + } +} + +/** The participants triggers and the two functions, as the catalog has them. */ +async function numberingCatalog(client: Client) { + const triggers = ( + await client.query(`SELECT tgname, pg_get_triggerdef(oid) AS def FROM pg_trigger + WHERE tgrelid = 'public.participants'::regclass AND NOT tgisinternal ORDER BY tgname`) + ).rows; + const functions = ( + await client.query(`SELECT proname, prosrc, proisstrict, provolatile, prorettype::regtype::text AS returns, + pg_get_userbyid(proowner) AS owner, proacl::text AS acl + FROM pg_proc WHERE pronamespace = 'public'::regnamespace AND proname IN ('pid_auto', 'pid_auto_unlock') + ORDER BY proname`) + ).rows; + return { triggers, functions }; +} + +/** Every participant, and the count pid_auto copies to each conversation. */ +async function storedParticipants(client: Client) { + return { + participants: ( + await client.query("SELECT * FROM participants ORDER BY zid, pid") + ).rows, + counts: ( + await client.query( + "SELECT zid, participant_count FROM conversations ORDER BY zid" + ) + ).rows, + }; +} + +/** Users for conversation 1 are 1001.., for conversation 2 are 2001..; the + * caller's next join uses 1900 or 2900. */ +async function seedParticipants(client: Client): Promise { + const owner = ( + await client.query( + "INSERT INTO users (uid, created) VALUES (1000, default) RETURNING uid" + ) + ).rows[0].uid; + for (const zid of [1, 2]) { + await client.query( + "INSERT INTO conversations (zid, owner, topic) VALUES ($1, $2, 'generated')", + [zid, owner] + ); + for (let i = 0; i < 3 + zid; i++) { + const uid = ( + await client.query( + "INSERT INTO users (uid, created) VALUES ($1, default) RETURNING uid", + [zid * 1000 + 1 + i] + ) + ).rows[0].uid; + await client.query( + "INSERT INTO participants (pid, zid, uid, created) VALUES (NULL, $1, $2, default)", + [zid, uid] + ); + } + } + await client.query( + "INSERT INTO users (uid, created) VALUES (1900, default), (2900, default)" + ); +} + +beforeAll(async () => { + admin = new Client({ connectionString: process.env.DATABASE_URL }); + await admin.connect(); + for (const db of DATABASES) + await admin.query(`DROP DATABASE IF EXISTS ${db} WITH (FORCE)`); + before000044 = releaseWith((name) => name < NAME); + through000044 = releaseWith((name) => name <= NAME); +}); +afterAll(async () => { + for (const db of DATABASES) + await admin?.query(`DROP DATABASE IF EXISTS ${db} WITH (FORCE)`); + await admin?.end(); + for (const release of [before000044, through000044]) + if (release) + fs.rmSync(path.dirname(release), { recursive: true, force: true }); +}); + +describe("migration 000044 through the runner", () => { + let beforeCatalog: Awaited>; + let afterCatalog: Awaited>; + + test("over a database that already has participants: deploy applies only 000044, every participant is unchanged, numbering continues", async () => { + await admin.query("CREATE DATABASE m000044_upgrade"); + runner("m000044_upgrade", "deploy", before000044); + await withDatabase("m000044_upgrade", async (client) => { + await seedParticipants(client); + beforeCatalog = await numberingCatalog(client); + const stored = await storedParticipants(client); + + const out = runner("m000044_upgrade", "deploy", through000044); + expect( + out.split("\n").filter((line) => line.startsWith("APPLIED ")) + ).toEqual([`APPLIED ${NAME}`]); + expect(out).toContain("applied 1 migration(s)"); + expect(runner("m000044_upgrade", "check", through000044)).toMatch( + /^migration check: \d+ ready$/m + ); + expect( + ( + await client.query( + "SELECT status, compat FROM migrations WHERE name = $1", + [NAME] + ) + ).rows + ).toEqual([{ status: "APPLIED", compat: "additive" }]); + + afterCatalog = await numberingCatalog(client); + process.stdout.write( + `${JSON.stringify({ + scenario: "000044 over existing participants", + participants: stored.participants.length, + triggers_before: beforeCatalog.triggers.map((t) => t.tgname), + triggers_after: afterCatalog.triggers.map((t) => t.tgname), + })}\n` + ); + + // Before: the session lock and its AFTER INSERT partner. + expect(beforeCatalog.triggers.map((t) => t.tgname)).toEqual([ + "pid_auto", + "pid_auto_unlock", + ]); + expect(beforeCatalog.functions[0].prosrc).toContain( + "pg_advisory_lock(_magic_id, _conversation_id)" + ); + // After: one BEFORE INSERT trigger, unchanged, and the transaction lock. + expect(afterCatalog.triggers).toEqual([beforeCatalog.triggers[0]]); + expect(afterCatalog.functions.map((f) => f.proname)).toEqual([ + "pid_auto", + ]); + const [was, now] = [ + beforeCatalog.functions[0], + afterCatalog.functions[0], + ]; + expect(now.prosrc).toContain( + "pg_advisory_xact_lock(_magic_id, _conversation_id)" + ); + expect(now.prosrc).not.toContain("pg_advisory_lock("); + expect(now.prosrc).toContain("SELECT COALESCE(MAX(pid) + 1, 0)"); + expect(now.prosrc).toContain("SET participant_count = NEW.pid + 1"); + expect({ ...now, prosrc: undefined }).toEqual({ + ...was, + prosrc: undefined, + }); + + expect(await storedParticipants(client)).toEqual(stored); + const next = ( + await client.query( + "INSERT INTO participants (pid, zid, uid, created) VALUES (NULL, 2, 2900, default) RETURNING pid" + ) + ).rows[0].pid; + const inZid2 = stored.participants.filter((p) => p.zid === 2).length; + expect(next).toBe(inZid2); + expect( + ( + await client.query( + "SELECT participant_count FROM conversations WHERE zid = 2" + ) + ).rows[0].participant_count + ).toBe(inZid2 + 1); + }); + }, 120000); + + test("the release before 000044 still runs beside it: check tolerates it as additive", () => { + const out = runner("m000044_upgrade", "check", before000044); + expect(out).toContain(`migration check: tolerating ${NAME}`); + expect(out).toMatch( + new RegExp( + `^migration check: \\d+ ready; 1 newer additive migration\\(s\\) tolerated: ${NAME}$`, + "m" + ) + ); + }); + + test("the down restores both triggers exactly as they were, and applying 000044 again gives the same catalog", async () => { + await withDatabase("m000044_upgrade", async (client) => { + const stored = await storedParticipants(client); + await client.query(fs.readFileSync(DOWN, "utf8")); + expect(await numberingCatalog(client)).toEqual(beforeCatalog); + expect(await storedParticipants(client)).toEqual(stored); + + // The operator removes the history row in the same sitting; the release + // then applies 000044 again. + await client.query("DELETE FROM migrations WHERE name = $1", [NAME]); + const out = runner("m000044_upgrade", "apply", through000044); + expect( + out.split("\n").filter((line) => line.startsWith("APPLIED ")) + ).toEqual([`APPLIED ${NAME}`]); + expect(await numberingCatalog(client)).toEqual(afterCatalog); + expect(await storedParticipants(client)).toEqual(stored); + }); + }, 120000); + + test("at deploy, a transaction still using participants makes 000044 wait at most 5 s and fail with nothing changed; a join sent meanwhile is delayed, then stored", async () => { + await admin.query("CREATE DATABASE m000044_lock"); + runner("m000044_lock", "deploy", before000044); + const holder = await connect("m000044_lock"); + const joiner = await connect("m000044_lock"); + try { + await seedParticipants(holder); + const before = await numberingCatalog(holder); + // A long transaction that has read participants (ACCESS SHARE until it + // ends). + await holder.query("BEGIN"); + await holder.query("SELECT count(*) FROM participants"); + + // Relation oids are per database: read this one's from inside it. + const participants = ( + await holder.query("SELECT 'public.participants'::regclass::oid AS oid") + ).rows[0].oid; + const started = Date.now(); + const deploying = runnerAsync("m000044_lock", "deploy", through000044); + for (;;) { + const waiting = ( + await admin.query( + `SELECT l.mode FROM pg_locks l JOIN pg_stat_activity a ON a.pid = l.pid + WHERE a.datname = 'm000044_lock' AND a.application_name = 'polis-migrate' AND NOT l.granted + AND l.database = (SELECT oid FROM pg_database WHERE datname = 'm000044_lock') AND l.relation = $1`, + [participants] + ) + ).rows; + if (waiting.length) { + expect(waiting[0].mode).toBe("AccessExclusiveLock"); + break; + } + if (Date.now() - started > 4000) + throw new Error("the migration never waited on participants"); + await sleep(20); + } + // A join sent while the migration waits queues behind its lock request. + const sentAt = Date.now(); + const sent = joiner + .query( + "INSERT INTO participants (pid, zid, uid, created) VALUES (NULL, 1, 1900, default) RETURNING pid" + ) + .then((r) => ({ ms: Date.now() - sentAt, pid: r.rows[0].pid })); + + const deployed = await deploying; + const migrationMs = Date.now() - started; + const stored = await sent; + await holder.query("COMMIT"); + const history = ( + await joiner.query( + "SELECT count(*)::int AS n FROM migrations WHERE name = $1", + [NAME] + ) + ).rows[0].n; + process.stdout.write( + `${JSON.stringify({ + scenario: "000044 at deploy behind a transaction using participants", + migration_exit: deployed.code, + migration_wait_ms: migrationMs, + migration_error: deployed.stderr.trim().split("\n").pop(), + join_sent_meanwhile_ms: stored.ms, + join_pid: stored.pid, + })}\n` + ); + + expect(deployed.code).not.toBe(0); + // lock_not_available: the lock_timeout expired. + expect(deployed.stderr).toContain("SQLSTATE 55P03"); + expect(migrationMs).toBeLessThan(5000 + 3000); + expect(history).toBe(0); + expect(await numberingCatalog(joiner)).toEqual(before); + // Delayed by the migration's wait (never more than its lock_timeout plus + // margin), then stored under the old trigger with the next number. + expect(stored.ms).toBeLessThan(5000 + 3000); + expect(stored.pid).toBe(4); + + // With the transaction gone, the next deploy applies it. + expect(runner("m000044_lock", "deploy", through000044)).toContain( + `APPLIED ${NAME}` + ); + } finally { + await holder.end().catch(() => undefined); + await joiner.end().catch(() => undefined); + } + }, 120000); + + test("on a fresh database the whole release gives the same catalog", async () => { + await admin.query("CREATE DATABASE m000044_fresh"); + const out = runner("m000044_fresh", "deploy"); + expect(out).toContain(`APPLIED ${NAME}`); + expect(runner("m000044_fresh", "check")).toMatch( + /^migration check: \d+ ready$/m + ); + await withDatabase("m000044_fresh", async (client) => { + expect(await numberingCatalog(client)).toEqual(afterCatalog); + }); + }, 120000); +}); diff --git a/server/__tests__/participation-pg/participant-numbers.pgtest.ts b/server/__tests__/participation-pg/participant-numbers.pgtest.ts new file mode 100644 index 000000000..3daf75290 --- /dev/null +++ b/server/__tests__/participation-pg/participant-numbers.pgtest.ts @@ -0,0 +1,355 @@ +/** Participants joining one conversation at the same moment must each get a + * participant on the first attempt, with their own participant number, and an + * insert that fails or is skipped must leave nothing behind that makes the + * next joiner wait. + * + * The pid_auto trigger numbers a conversation's participants MAX(pid) + 1, + * from 0, under an advisory lock per conversation (server/postgres/migrations). + * For as long as that lock ends before the inserting transaction commits, a + * second join in the conversation can read the same MAX(pid), wait on the + * conversations row the first holds, and fail with 23505 on (zid, pid) once + * the first commits; the server then retries the join. An insert that fails + * after the trigger, or a row ON CONFLICT DO NOTHING skips, keeps the lock on + * its connection. With the lock held until the transaction ends, the second + * join reads MAX(pid) only after the first has committed, and the lock ends + * with every transaction. + * + * Each join is the server's insertParticipant transaction (src/participant.ts) + * without its retry. Every connection here is its own session, as the + * participation pools of several servers are. A connection whose join failed + * is closed and replaced, as insertParticipant closes it. + * + * Generated data only. Needs DATABASE_URL (superuser, migrated); see + * scripts/test-delphi-result-reads.sh. */ +import { Client } from "pg"; + +// pid_auto's advisory lock class; the conversation id is the second key. +const PID_LOCK = 873791983; +const BURST_ZID = { 40: 9621, 72: 9622 } as const; +const COMMIT_ORDER_ZID = 9623, + FAILED_INSERT_ZID = 9624, + SKIPPED_ROW_ZID = 9625; +const ROUNDS = 5; +// A join that the lock lets through must finish well within this. +const NEXT_JOIN_BUDGET_MS = 1000; +// Upper bound on any lock wait in this file, so a lock nobody releases fails a +// test instead of hanging it. +const LOCK_TIMEOUT = "20s"; + +type Outcome = { + ms: number; + pid?: number; + error?: { code?: string; constraint?: string }; +}; +const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); +let pg: Client; + +async function session(): Promise { + const client = new Client({ connectionString: process.env.DATABASE_URL }); + await client.connect(); + await client.query(`SET lock_timeout = '${LOCK_TIMEOUT}'`); + return client; +} + +/** Users with explicit uids: other suites in this database insert users with + * explicit small uids without advancing the sequence, so a uid from the + * sequence can collide with one of theirs. These are zid * 1000 + i. */ +async function users(first: number, n: number): Promise { + const uids = Array.from({ length: n }, (_, i) => first + i); + await pg.query("INSERT INTO users (uid) SELECT unnest($1::int[])", [uids]); + return uids; +} + +async function conversation(zid: number): Promise { + const [owner] = await users(zid * 1000, 1); + await pg.query( + "INSERT INTO conversations (zid, owner, topic) VALUES ($1, $2, 'generated')", + [zid, owner] + ); +} + +/** The insert insertParticipant runs, alone; the caller owns the transaction. */ +function insertParticipant( + client: Client, + zid: number, + uid: number +): Promise { + const started = Date.now(); + return client + .query( + "INSERT INTO participants (pid, zid, uid, created) VALUES (NULL, $1, $2, default) RETURNING *;", + [zid, uid] + ) + .then( + (r) => ({ ms: Date.now() - started, pid: r.rows[0].pid }), + (error) => ({ + ms: Date.now() - started, + error: { code: error.code, constraint: error.constraint }, + }) + ); +} + +/** insertParticipant's transaction, without the retry. */ +async function join( + client: Client, + zid: number, + uid: number +): Promise { + const started = Date.now(); + await client.query("BEGIN"); + await client.query( + "INSERT INTO participants_extended (zid, uid) VALUES ($1, $2) ON CONFLICT (zid, uid) DO NOTHING;", + [zid, uid] + ); + const outcome = await insertParticipant(client, zid, uid); + await client.query(outcome.error ? "ROLLBACK" : "COMMIT"); + return { ...outcome, ms: Date.now() - started }; +} + +/** Sessions holding the conversation's participant lock. */ +async function lockHolders(zid: number): Promise { + return ( + await pg.query( + `SELECT count(*)::int AS n FROM pg_locks WHERE locktype = 'advisory' AND granted + AND classid::bigint = $1 AND objid::bigint = $2 AND objsubid = 2`, + [PID_LOCK, zid] + ) + ).rows[0].n; +} + +async function untilWaiting(pid: number): Promise { + const deadline = Date.now() + 5000; + for (;;) { + const row = ( + await pg.query( + "SELECT wait_event FROM pg_stat_activity WHERE pid = $1 AND wait_event_type = 'Lock'", + [pid] + ) + ).rows[0]; + if (row) return row.wait_event; + if (Date.now() > deadline) + throw new Error(`session ${pid} never waited on a lock`); + await sleep(10); + } +} + +async function storedPids(zid: number): Promise { + return ( + await pg.query("SELECT pid FROM participants WHERE zid = $1 ORDER BY pid", [ + zid, + ]) + ).rows.map((r) => r.pid); +} + +async function participantCount(zid: number): Promise { + return ( + await pg.query( + "SELECT participant_count FROM conversations WHERE zid = $1", + [zid] + ) + ).rows[0].participant_count; +} + +beforeAll(async () => { + pg = new Client({ connectionString: process.env.DATABASE_URL }); + await pg.connect(); +}); +afterAll(async () => { + await pg?.end(); +}); + +test.each([40, 72] as const)( + "%i participants joining one conversation at once, round after round: every one joins on the first attempt, with distinct contiguous numbers", + async (n) => { + const zid = BURST_ZID[n]; + await conversation(zid); + const sessions = await Promise.all( + Array.from({ length: n }, () => session()) + ); + const perRound: Array<{ + round: number; + sent: number; + joined: number; + refused: number; + refusals: string[]; + }> = []; + let refusedTotal = 0; + try { + for (let round = 0; round < ROUNDS; round++) { + const uids = await users(zid * 1000 + 1 + round * n, n); + const outcomes = await Promise.all( + uids.map(async (uid, i) => { + const outcome = await join(sessions[i], zid, uid); + if (outcome.error) { + // insertParticipant closes a connection whose join failed. + await sessions[i].end().catch(() => undefined); + sessions[i] = await session(); + } + return outcome; + }) + ); + const refusals = outcomes + .filter((o) => o.error) + .map((o) => `${o.error!.code} ${o.error!.constraint ?? ""}`.trim()); + refusedTotal += refusals.length; + perRound.push({ + round, + sent: n, + joined: n - refusals.length, + refused: refusals.length, + refusals: [...new Set(refusals)], + }); + } + } finally { + await Promise.all(sessions.map((s) => s.end().catch(() => undefined))); + } + const pids = await storedPids(zid); + const count = await participantCount(zid); + process.stdout.write( + `${JSON.stringify({ + scenario: `${n} joins at once, ${ROUNDS} rounds`, + per_round: perRound, + sent: n * ROUNDS, + joined: pids.length, + refused: refusedTotal, + numbers_contiguous_from_0: pids.every((pid, i) => pid === i), + participant_count: count, + })}\n` + ); + + expect(refusedTotal).toBe(0); + expect(pids).toEqual(Array.from({ length: n * ROUNDS }, (_, i) => i)); + expect(count).toBe(n * ROUNDS); + expect(await lockHolders(zid)).toBe(0); + }, + 120000 +); + +test("a join sent while another in its conversation is not yet committed gets the next number once that one commits", async () => { + await conversation(COMMIT_ORDER_ZID); + const [uidA, uidB] = await users(COMMIT_ORDER_ZID * 1000 + 1, 2); + const a = await session(); + const b = await session(); + const bPid = (await b.query("SELECT pg_backend_pid() AS pid")).rows[0].pid; + try { + // A has inserted (the trigger numbered it) and not committed: in + // production its COMMIT is one round trip later. + await a.query("BEGIN"); + const first = await insertParticipant(a, COMMIT_ORDER_ZID, uidA); + expect(first.error).toBeUndefined(); + + const second = join(b, COMMIT_ORDER_ZID, uidB); + const waitedOn = await untilWaiting(bPid); + await a.query("COMMIT"); + const outcome = await second; + const holders = await lockHolders(COMMIT_ORDER_ZID); + process.stdout.write( + `${JSON.stringify({ + scenario: "second join sent before the first commits", + second_waited_on: waitedOn, + first_pid: first.pid, + second: outcome.error + ? `error ${outcome.error.code} ${outcome.error.constraint}` + : `pid ${outcome.pid}`, + sessions_holding_lock_after: holders, + })}\n` + ); + + // It waits for the participant number, not for a row it will fail behind. + expect(waitedOn).toBe("advisory"); + expect(outcome.error).toBeUndefined(); + expect(outcome.pid).toBe(first.pid! + 1); + expect(holders).toBe(0); + expect(await storedPids(COMMIT_ORDER_ZID)).toEqual([0, 1]); + expect(await participantCount(COMMIT_ORDER_ZID)).toBe(2); + } finally { + await a.end().catch(() => undefined); + await b.end().catch(() => undefined); + } +}, 60000); + +test("a join whose insert fails leaves no participant lock on its connection, and the next join does not wait", async () => { + await conversation(FAILED_INSERT_ZID); + const [uid, other] = await users(FAILED_INSERT_ZID * 1000 + 1, 2); + const failing = await session(); + const next = await session(); + try { + expect((await join(pg, FAILED_INSERT_ZID, uid)).pid).toBe(0); + // The same user again fails on (zid, uid) after the trigger took the lock; + // the connection is then rolled back but kept open, as a pooled one is + // (pg.withTransaction, for example, pools a client after an error). + const refused = await join(failing, FAILED_INSERT_ZID, uid); + const holders = await lockHolders(FAILED_INSERT_ZID); + + await next.query("SET lock_timeout = '3s'"); + const outcome = await join(next, FAILED_INSERT_ZID, other); + process.stdout.write( + `${JSON.stringify({ + scenario: "a join that fails, its connection kept", + refused: refused.error + ? `${refused.error.code} ${refused.error.constraint}` + : "joined", + sessions_holding_lock_after_rollback: holders, + next_join: outcome.error + ? `error ${outcome.error.code}` + : `pid ${outcome.pid}`, + next_join_ms: outcome.ms, + })}\n` + ); + + expect(refused.error).toEqual({ + code: "23505", + constraint: "participants_zid_uid_key", + }); + expect(holders).toBe(0); + expect(outcome.error).toBeUndefined(); + expect(outcome.ms).toBeLessThan(NEXT_JOIN_BUDGET_MS); + expect(outcome.pid).toBe(1); + } finally { + await failing.end().catch(() => undefined); + await next.end().catch(() => undefined); + } +}, 60000); + +test("a participant row skipped by ON CONFLICT DO NOTHING (the CSV import) leaves no participant lock on its connection, and the next join does not wait", async () => { + await conversation(SKIPPED_ROW_ZID); + const [uid, other] = await users(SKIPPED_ROW_ZID * 1000 + 1, 2); + const importer = await session(); + const next = await session(); + try { + expect((await join(pg, SKIPPED_ROW_ZID, uid)).pid).toBe(0); + // The import worker's participants insert (src/workers/import-processor.ts) + // for a user who already joined: the BEFORE trigger runs, the row is + // skipped, and the transaction commits. + await importer.query("BEGIN"); + const skipped = await importer.query( + "INSERT INTO participants (uid, zid, created) VALUES ($1, $2, default) ON CONFLICT (zid, uid) DO NOTHING", + [uid, SKIPPED_ROW_ZID] + ); + await importer.query("COMMIT"); + const holders = await lockHolders(SKIPPED_ROW_ZID); + + await next.query("SET lock_timeout = '3s'"); + const outcome = await join(next, SKIPPED_ROW_ZID, other); + process.stdout.write( + `${JSON.stringify({ + scenario: "a participant row skipped by ON CONFLICT DO NOTHING", + rows_inserted: skipped.rowCount, + sessions_holding_lock_after_commit: holders, + next_join: outcome.error + ? `error ${outcome.error.code}` + : `pid ${outcome.pid}`, + next_join_ms: outcome.ms, + })}\n` + ); + + expect(skipped.rowCount).toBe(0); + expect(holders).toBe(0); + expect(outcome.error).toBeUndefined(); + expect(outcome.ms).toBeLessThan(NEXT_JOIN_BUDGET_MS); + expect(outcome.pid).toBe(1); + } finally { + await importer.end().catch(() => undefined); + await next.end().catch(() => undefined); + } +}, 60000); diff --git a/server/__tests__/participation-pg/statement-numbers-migration.pgtest.ts b/server/__tests__/participation-pg/statement-numbers-migration.pgtest.ts index 95cb28625..8ecb54554 100644 --- a/server/__tests__/participation-pg/statement-numbers-migration.pgtest.ts +++ b/server/__tests__/participation-pg/statement-numbers-migration.pgtest.ts @@ -34,7 +34,9 @@ const DATABASES = ["m000042_upgrade", "m000042_fresh", "m000042_lock"]; const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); let admin: Client; +// The release just before 000042, and this release up to and including it. let before000042: string; +let through000042: string; function url(db: string): string { const u = new URL(process.env.DATABASE_URL as string); @@ -73,20 +75,26 @@ function runnerAsync( }); } -/** This release without 000042: the release just before it. */ -function releaseBefore000042(): string { +/** This release with only the numbered migrations `keep` accepts: their + * files and their release.txt and compat.txt lines. */ +function releaseWith(keep: (name: string) => boolean): string { const dir = path.join( fs.mkdtempSync(path.join(os.tmpdir(), "release-")), "migrations" ); fs.cpSync(MIGRATIONS, dir, { recursive: true }); - fs.rmSync(path.join(dir, NAME)); + const numbered = (name: string) => /^\d{6}_.*\.sql$/.test(name); + for (const name of fs.readdirSync(dir)) + if (numbered(name) && !keep(name)) fs.rmSync(path.join(dir, name)); for (const manifest of ["release.txt", "compat.txt"]) { const file = path.join(dir, manifest); const kept = fs .readFileSync(file, "utf8") .split("\n") - .filter((line) => line.split(" ")[0] !== NAME); + .filter((line) => { + const name = line.split(" ")[0]; + return !numbered(name) || keep(name); + }); fs.writeFileSync(file, kept.join("\n")); } return dir; @@ -166,14 +174,16 @@ beforeAll(async () => { await admin.connect(); for (const db of DATABASES) await admin.query(`DROP DATABASE IF EXISTS ${db} WITH (FORCE)`); - before000042 = releaseBefore000042(); + before000042 = releaseWith((name) => name < NAME); + through000042 = releaseWith((name) => name <= NAME); }); afterAll(async () => { for (const db of DATABASES) await admin?.query(`DROP DATABASE IF EXISTS ${db} WITH (FORCE)`); await admin?.end(); - if (before000042) - fs.rmSync(path.dirname(before000042), { recursive: true, force: true }); + for (const release of [before000042, through000042]) + if (release) + fs.rmSync(path.dirname(release), { recursive: true, force: true }); }); describe("migration 000042 through the runner", () => { @@ -188,12 +198,12 @@ describe("migration 000042 through the runner", () => { beforeCatalog = await numberingCatalog(client); const statements = await storedStatements(client); - const out = runner("m000042_upgrade", "deploy"); + const out = runner("m000042_upgrade", "deploy", through000042); expect( out.split("\n").filter((line) => line.startsWith("APPLIED ")) ).toEqual([`APPLIED ${NAME}`]); expect(out).toContain("applied 1 migration(s)"); - expect(runner("m000042_upgrade", "check")).toMatch( + expect(runner("m000042_upgrade", "check", through000042)).toMatch( /^migration check: \d+ ready$/m ); expect( @@ -275,7 +285,7 @@ describe("migration 000042 through the runner", () => { // The operator removes the history row in the same sitting; the release // then applies 000042 again. await client.query("DELETE FROM migrations WHERE name = $1", [NAME]); - const out = runner("m000042_upgrade", "apply"); + const out = runner("m000042_upgrade", "apply", through000042); expect( out.split("\n").filter((line) => line.startsWith("APPLIED ")) ).toEqual([`APPLIED ${NAME}`]); @@ -301,7 +311,7 @@ describe("migration 000042 through the runner", () => { await holder.query("SELECT 'public.comments'::regclass::oid AS oid") ).rows[0].oid; const started = Date.now(); - const deploying = runnerAsync("m000042_lock", "deploy"); + const deploying = runnerAsync("m000042_lock", "deploy", through000042); for (;;) { const waiting = ( await admin.query( @@ -360,7 +370,9 @@ describe("migration 000042 through the runner", () => { expect(stored.tid).toBe(4); // With the transaction gone, the next deploy applies it. - expect(runner("m000042_lock", "deploy")).toContain(`APPLIED ${NAME}`); + expect(runner("m000042_lock", "deploy", through000042)).toContain( + `APPLIED ${NAME}` + ); } finally { await holder.end().catch(() => undefined); await writer.end().catch(() => undefined); diff --git a/server/bin/build-migration-report.py b/server/bin/build-migration-report.py index 16fe66d69..2da85e3d8 100644 --- a/server/bin/build-migration-report.py +++ b/server/bin/build-migration-report.py @@ -85,7 +85,8 @@ def manifest(path): '000029_extend_delphi_graph_stages.sql', '000030_create_delphi_writers.sql', '000031_scope_delphi_result_reads.sql', '000038_create_delphi_comment_embeddings.sql', '000039_clear_zinvites_uuid.sql', '000041_create_delphi_run_record.sql', - '000042_tid_auto_transaction_lock.sql', '000043_add_conversation_activity_indexes.sql'} + '000042_tid_auto_transaction_lock.sql', '000043_add_conversation_activity_indexes.sql', + '000044_pid_auto_transaction_lock.sql'} assert selected == {p.name for p in files} | pending, 'report scope differs from release selection' assert held == {'000021_create_polis_coordinator.sql'}, 'review changed hold policy' numbered = sorted(MIG.glob('*.sql')) diff --git a/server/characterization/README.md b/server/characterization/README.md index a1bab08e7..5bf3fecf1 100644 --- a/server/characterization/README.md +++ b/server/characterization/README.md @@ -446,9 +446,9 @@ an explicit catalog review before recording. ### Release-selected schema catalog The catalog follows a fresh database built from the release-selected migrations -through `000042`. `000041` adds a function and `000042` replaces one and drops -a trigger and its function; neither adds or changes a column, so the catalog is -the same as through `000039`. It has 694 columns: 200 additions and 106 removals +through `000044`. `000041` adds a function, and `000042` and `000044` each +replace one and drop a trigger and its function; none adds or changes a column, +so the catalog is the same as through `000039`. It has 694 columns: 200 additions and 106 removals from the previous 600-column catalog, with every retained descriptor and type unchanged. The 106 removals are the coordinator tables' columns: `000021` is held, so a fresh release database never creates them; nothing is dropped. The diff --git a/server/characterization/collective-statement/recordings/index.json b/server/characterization/collective-statement/recordings/index.json index 694a395de..a75f0cb89 100644 --- a/server/characterization/collective-statement/recordings/index.json +++ b/server/characterization/collective-statement/recordings/index.json @@ -181,8 +181,7 @@ ], "rules": [], "triggers": [ - "pid_auto: CREATE TRIGGER pid_auto BEFORE INSERT ON public.participants FOR EACH ROW EXECUTE FUNCTION pid_auto()", - "pid_auto_unlock: CREATE TRIGGER pid_auto_unlock AFTER INSERT ON public.participants FOR EACH ROW EXECUTE FUNCTION pid_auto_unlock()" + "pid_auto: CREATE TRIGGER pid_auto BEFORE INSERT ON public.participants FOR EACH ROW EXECUTE FUNCTION pid_auto()" ] }, "reports": { diff --git a/server/postgres/migrations/000044_pid_auto_transaction_lock.sql b/server/postgres/migrations/000044_pid_auto_transaction_lock.sql new file mode 100644 index 000000000..fb466901c --- /dev/null +++ b/server/postgres/migrations/000044_pid_auto_transaction_lock.sql @@ -0,0 +1,75 @@ +-- 000044_pid_auto_transaction_lock.sql +-- +-- Hold the participant-number lock until the inserting transaction ends. +-- +-- pid_auto (BEFORE INSERT on participants, 000000_initial.sql) numbers a +-- conversation's participants MAX(pid) + 1, from 0, under the advisory lock +-- (873791983, zid), and copies the count to conversations.participant_count. +-- It took that lock with pg_advisory_lock, a SESSION lock, and pid_auto_unlock +-- (AFTER INSERT) released it as soon as the INSERT statement ended, before its +-- transaction committed. A second INSERT into the same conversation could take +-- the lock in that window and read the same MAX(pid): it then waited on the +-- conversations row the first held and failed with 23505 on (zid, pid) once +-- the first committed, so the join was refused unless the server retried it. +-- An INSERT that failed after the BEFORE trigger, or a row skipped by ON +-- CONFLICT DO NOTHING (the CSV import), never reached the AFTER trigger, so +-- its session kept the lock, through ROLLBACK, until the connection closed. +-- +-- pid_auto now takes pg_advisory_xact_lock, which Postgres releases at COMMIT +-- or ROLLBACK and never earlier. The next INSERT in the conversation waits for +-- it, then reads MAX(pid) with a fresh snapshot (READ COMMITTED: each statement +-- in a volatile PL/pgSQL function takes its own), which includes the committed +-- row. pid_auto_unlock and its trigger are dropped: there is nothing left for +-- them to release, and pg_advisory_unlock on a transaction lock would only +-- warn. Everything else is unchanged: the same lock key, numbering from 0 with +-- no gaps (a failed INSERT uses no number), the participant_count update, the +-- same function name, owner, STRICT and volatility, and the same BEFORE INSERT +-- trigger. No table, column, index, constraint or stored row changes. The +-- participant_count UPDATE already held the conversations row until commit, so +-- no join waits longer than it did before. +-- +-- Compatibility: additive. No code calls pid_auto_unlock or takes this lock +-- itself; every writer inserts with pid NULL (or lets the trigger overwrite +-- it) and reads the assigned pid back. A release that does not list this +-- migration therefore inserts and numbers participants exactly as it does here. +-- +-- Locks at deploy. CREATE OR REPLACE FUNCTION and DROP FUNCTION write the +-- catalog only. DROP TRIGGER takes ACCESS EXCLUSIVE on participants, held +-- until this migration's transaction commits a few statements later: it first +-- waits for transactions already using participants to finish, and +-- participant reads and writes that arrive meanwhile (votes, comments, +-- nextComment, participationInit, joins) wait behind it. The wait is bounded by +-- lock_timeout (5 s, set below and by the runner); on timeout the migration +-- fails with no history row, nothing is changed, and the deploy can be retried. +-- So: at most one stall of about 5 s on the participants table, once, and no +-- request refused. +BEGIN; +SET LOCAL lock_timeout='5s'; +CREATE OR REPLACE FUNCTION public.pid_auto() + RETURNS trigger AS $$ +DECLARE + _magic_id constant int := 873791983; -- This is a magic key used for locking conversation row-sets within the participants table. TODO keep track of these + _conversation_id int; +BEGIN + _conversation_id = NEW.zid; + + -- Obtain an advisory lock on the participants table, limited to this + -- conversation, held until this transaction commits or rolls back. + PERFORM pg_advisory_xact_lock(_magic_id, _conversation_id); + + SELECT COALESCE(MAX(pid) + 1, 0) -- Start with comment id of 0 + INTO NEW.pid + FROM participants + WHERE zid = NEW.zid; + + -- Duplicate participant_count to the conversations table to speed up conversationsView queries. + UPDATE conversations + SET participant_count = NEW.pid + 1 + WHERE zid = NEW.zid; + + RETURN NEW; +END; +$$ LANGUAGE plpgsql STRICT; +DROP TRIGGER pid_auto_unlock ON public.participants; +DROP FUNCTION public.pid_auto_unlock(); +COMMIT; diff --git a/server/postgres/migrations/compat.txt b/server/postgres/migrations/compat.txt index 409735de3..7957d5e5e 100644 --- a/server/postgres/migrations/compat.txt +++ b/server/postgres/migrations/compat.txt @@ -7,7 +7,7 @@ # this file. An undeclared migration counts as breaking. Recorded declarations # only ever tighten (additive -> breaking). Every release carries every line # forward; a new migration adds its own line in number order, with its evidence -# in the PR. Evidence for 000019-000042: docs/migrations.md "Forward compatibility". +# in the PR. Evidence for 000019-000044: docs/migrations.md "Forward compatibility". # 000000-000018 predate the runner and were not evaluated: fail closed. 000000_initial.sql breaking 000001_update_pwreset_table.sql breaking @@ -43,3 +43,4 @@ 000041_create_delphi_run_record.sql additive 000042_tid_auto_transaction_lock.sql additive 000043_add_conversation_activity_indexes.sql additive +000044_pid_auto_transaction_lock.sql additive diff --git a/server/postgres/migrations/down/000044_restore_pid_auto_session_lock.sql b/server/postgres/migrations/down/000044_restore_pid_auto_session_lock.sql new file mode 100644 index 000000000..79a00758d --- /dev/null +++ b/server/postgres/migrations/down/000044_restore_pid_auto_session_lock.sql @@ -0,0 +1,66 @@ +-- down/000044_restore_pid_auto_session_lock.sql (reversal of 000044_pid_auto_transaction_lock.sql) +-- +-- Restores the participant-number triggers exactly as 000000_initial.sql +-- defines them: pid_auto takes the SESSION advisory lock (873791983, zid), and +-- the AFTER INSERT trigger pid_auto_unlock releases it when the INSERT +-- statement ends. No stored row changes in either direction; participant +-- numbers already assigned and participant_count stay as they are. +-- +-- Restoring it brings back the defects 000044 removes: two participants joining +-- one conversation at the same moment can be given the same number, and one of +-- them is refused unless the server retries; and an insert that fails or is +-- skipped keeps the lock on its connection. +-- +-- psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -f server/postgres/migrations/down/000044_restore_pid_auto_session_lock.sql +-- +-- CREATE TRIGGER takes SHARE ROW EXCLUSIVE on participants (writes wait, reads +-- do not), bounded by the 5 s lock_timeout below. Runner history is not edited +-- here; the operator removes the 000044 history row in the same sitting, after +-- this succeeds. The runner never runs a down migration automatically. +BEGIN; +SET LOCAL lock_timeout='5s'; +CREATE OR REPLACE FUNCTION public.pid_auto() + RETURNS trigger AS $$ +DECLARE + _magic_id constant int := 873791983; -- This is a magic key used for locking conversation row-sets within the participants table. TODO keep track of these + _conversation_id int; +BEGIN + _conversation_id = NEW.zid; + + -- Obtain an advisory lock on the participants table, limited to this conversation + PERFORM pg_advisory_lock(_magic_id, _conversation_id); + + SELECT COALESCE(MAX(pid) + 1, 0) -- Start with comment id of 0 + INTO NEW.pid + FROM participants + WHERE zid = NEW.zid; + + -- Duplicate participant_count to the conversations table to speed up conversationsView queries. + UPDATE conversations + SET participant_count = NEW.pid + 1 + WHERE zid = NEW.zid; + + RETURN NEW; +END; +$$ LANGUAGE plpgsql STRICT; + +CREATE OR REPLACE FUNCTION public.pid_auto_unlock() + RETURNS trigger AS $$ +DECLARE + _magic_id constant int := 873791983; + _conversation_id int; +BEGIN + _conversation_id = NEW.zid; + + -- Release the lock. + PERFORM pg_advisory_unlock(_magic_id, _conversation_id); + + RETURN NEW; +END; +$$ LANGUAGE plpgsql STRICT; + +CREATE TRIGGER pid_auto_unlock + AFTER INSERT ON public.participants + FOR EACH ROW + EXECUTE PROCEDURE public.pid_auto_unlock(); +COMMIT; diff --git a/server/postgres/migrations/release.txt b/server/postgres/migrations/release.txt index 67a75fc79..dc8149cc1 100644 --- a/server/postgres/migrations/release.txt +++ b/server/postgres/migrations/release.txt @@ -33,3 +33,4 @@ 000041_create_delphi_run_record.sql 000042_tid_auto_transaction_lock.sql 000043_add_conversation_activity_indexes.sql +000044_pid_auto_transaction_lock.sql diff --git a/server/postgres/migrations/report/first-deploy.sql b/server/postgres/migrations/report/first-deploy.sql index b5891b2cd..49390ab75 100644 --- a/server/postgres/migrations/report/first-deploy.sql +++ b/server/postgres/migrations/report/first-deploy.sql @@ -2,7 +2,7 @@ -- First deployment only: no existing ledger or queue. Other states refuse. -- This is a catalog forecast, not DDL success or deployment-health proof. -- sha256 8fa1066d9fc29c1df528b300199c619a2f9edecf1432926ad6a8146ebc650593 adoption/helpers.sql --- sha256 80e69155198a1c4290c8803efe6607f360886f8afee11af8d2536242aa237f69 release.txt +-- sha256 4959eb616a51a172d7f7e5d3d06e92782fa24a67b099022fff366af7d5455c97 release.txt -- sha256 8a8b24fa47a25c613a8329aa79f413ac7461a93b12134045ae1cf2457e2ee3b7 held.txt -- sha256 c6b5c71247d129964dd89ba560a4522caef1abbb9379ad1b3445d6ed96be805b adoption/000000_initial.sql -- sha256 28ef33976beb9c7c9248ac800f29aab048f4410c2170ad12e3ade71d72e5ecb5 adoption/000001_update_pwreset_table.sql @@ -58,6 +58,7 @@ -- sha256 e6d86397e5b53ed3d75d73278a293353512698bd95be2da288c92e94a935dee2 000041_create_delphi_run_record.sql -- sha256 ae12bd2dcce3a8e055adb54b241c090f36861ad4185771e173a87abd278b53f6 000042_tid_auto_transaction_lock.sql -- sha256 1c85ef8a67bb0add2bcf6dd7e38fabb977c26fe004994cf78e06fed8eda9b906 000043_add_conversation_activity_indexes.sql +-- sha256 8eaffb393aca2b89ffe41264a1a9676f83a74685866a095befd3bb648784903f 000044_pid_auto_transaction_lock.sql BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY; SET LOCAL search_path=pg_catalog,public; SET LOCAL statement_timeout='30s'; @@ -1399,7 +1400,7 @@ SELECT (SELECT EXISTS(SELECT 1 FROM pg_index WHERE indexrelid=to_regclass('publi CASE WHEN NOT can_reconcile THEN 'BLOCKED_RECONCILIATION' WHEN NOT reconcile_authority OR NOT can_provision THEN 'REVIEW_MIGRATION_SESSION_AUTHORITY' ELSE 'WOULD_APPLY' END - FROM (VALUES ('000019_create_polis_queue.sql'),('000023_create_delphi_foundation.sql'),('000024_create_polis_queue_large_class.sql'),('000027_create_sealed_job_graphs.sql'),('000028_create_delphi_results.sql'),('000029_extend_delphi_graph_stages.sql'),('000030_create_delphi_writers.sql'),('000031_scope_delphi_result_reads.sql'),('000038_create_delphi_comment_embeddings.sql'),('000039_clear_zinvites_uuid.sql'),('000041_create_delphi_run_record.sql'),('000042_tid_auto_transaction_lock.sql'),('000043_add_conversation_activity_indexes.sql')) p(migration) CROSS JOIN readiness + FROM (VALUES ('000019_create_polis_queue.sql'),('000023_create_delphi_foundation.sql'),('000024_create_polis_queue_large_class.sql'),('000027_create_sealed_job_graphs.sql'),('000028_create_delphi_results.sql'),('000029_extend_delphi_graph_stages.sql'),('000030_create_delphi_writers.sql'),('000031_scope_delphi_result_reads.sql'),('000038_create_delphi_comment_embeddings.sql'),('000039_clear_zinvites_uuid.sql'),('000041_create_delphi_run_record.sql'),('000042_tid_auto_transaction_lock.sql'),('000043_add_conversation_activity_indexes.sql'),('000044_pid_auto_transaction_lock.sql')) p(migration) CROSS JOIN readiness UNION ALL SELECT migration, NULL::boolean, 'OUTSIDE_RELEASE' FROM (VALUES ('000020'),('000021'),('000025'),('000026')) p(migration) diff --git a/server/src/participant.ts b/server/src/participant.ts index d2289a935..f8ccb71ee 100644 --- a/server/src/participant.ts +++ b/server/src/participant.ts @@ -151,14 +151,16 @@ function tryToJoinConversation( }); } -// The pid_auto trigger takes the conversation's participant lock as a SESSION -// advisory lock, and pid_auto_unlock gives it back only after an INSERT that -// succeeds (server/postgres/migrations/000000_initial.sql). A participants -// INSERT that fails after taking it (a lost pid race, an existing (zid, uid), -// a lock timeout) leaves the lock on its connection, and ROLLBACK does not -// release it. So a connection that saw any error here is closed instead of +// Before migration 000044, the pid_auto trigger took the conversation's +// participant lock as a SESSION advisory lock, and pid_auto_unlock gave it back +// only after an INSERT that succeeded (server/postgres/migrations). A +// participants INSERT that failed after taking it (a lost pid race, an existing +// (zid, uid), a lock timeout) left the lock on its connection, and ROLLBACK did +// not release it. So a connection that saw any error here is closed instead of // being returned to the pool: the lock ends with its session, rather than -// making every later joiner of the conversation wait on it. +// making every later joiner of the conversation wait on it. Since 000044 the +// lock is held to COMMIT or ROLLBACK and never outlives the transaction; +// closing the connection is kept for a database without 000044. // // Every lock wait in the transaction is bounded, so a lock held elsewhere (a // server still running code that leaks it, for example) answers the joiner @@ -204,8 +206,9 @@ async function insertParticipant( } // Second insert into participants table. - // The pid_auto trigger acquires an advisory lock and assigns pid = MAX(pid)+1. - // The pid_auto_unlock trigger releases the lock after insert. + // The pid_auto trigger acquires the conversation's participant lock and + // assigns pid = MAX(pid)+1; since migration 000044 the lock is held until + // this transaction commits or rolls back. try { const partResult = await client.query( "INSERT INTO participants (pid, zid, uid, created) VALUES (NULL, $1, $2, default) RETURNING *;", @@ -280,9 +283,11 @@ async function addParticipant( if (err?.code !== "23505") { throw err; } - // Another joiner was given the same pid: pid_auto computes MAX(pid) + 1 - // before that joiner's row is committed. It is committed by the time this - // INSERT fails, so one more attempt, on a new connection, gets the next pid. + // Another joiner was given the same pid: before migration 000044, pid_auto + // could compute MAX(pid) + 1 before that joiner's row was committed. It is + // committed by the time this INSERT fails, so one more attempt, on a new + // connection, gets the next pid. With 000044 the lock is held to commit and + // this does not happen; the retry is kept for a database without it. logger.info("participant pid collision; retrying once", { zid, uid, diff --git a/server/src/workers/import-processor.ts b/server/src/workers/import-processor.ts index d5ba7a5b7..30dfa2cee 100644 --- a/server/src/workers/import-processor.ts +++ b/server/src/workers/import-processor.ts @@ -367,11 +367,13 @@ async function flushBatchToDb(rows: any[][]) { await client.query("ROLLBACK"); throw e; } finally { - // The participants INSERT fires pid_auto, whose session advisory lock is - // given back only for rows actually inserted: a row skipped by ON CONFLICT - // DO NOTHING, or a failed batch, leaves it held on this connection through - // COMMIT or ROLLBACK. Close the connection instead of pooling it, so the - // lock ends with the session and joiners of this conversation never wait. + // The participants INSERT fires pid_auto. Before migration 000044 its + // session advisory lock was given back only for rows actually inserted: a + // row skipped by ON CONFLICT DO NOTHING, or a failed batch, left it held on + // this connection through COMMIT or ROLLBACK. Close the connection instead + // of pooling it, so the lock ends with the session and joiners of this + // conversation never wait. Since 000044 the lock ends with the transaction; + // closing the connection is kept for a database without 000044. client.release(true); } }