Skip to content

Commit 4d54810

Browse files
aborrusoclaude
andcommitted
fix(review): riferimento corretto alla soglia e test fedele al client
- il commento sulla query compatta rimandava a SENATO_MAX_OR_TERMS, che riguarda il chunking: il vincolo qui è SENATO_MAX_REQUEST_URI - l'asserzione sulla dimensione usava encodeURIComponent su un frammento; ora sta accanto agli helper, misura con senatoRequestUriLength (stesso encoding del client) su una query intera con i suoi prefissi Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c2bb551 commit 4d54810

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/core/chunk.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ describe("chunk", () => {
1919
expect(chunk([], 25)).toEqual([]);
2020
});
2121

22-
it("tiene la query sotto la soglia di ~2 KB del Senato", () => {
23-
// 53 fiducie in leg. 19: la OR-chain intera supera i 2 KB di query string
24-
// e l'endpoint risponde 403. A blocchi di 25 ogni query resta ben sotto.
25-
const nums = Array.from({ length: 53 }, (_, i) => String(1000 + i));
26-
const orChain = (batch: string[]) =>
27-
batch.map((n) => `STR(?f) = "S.${n}"`).join(" || ");
28-
expect(encodeURIComponent(orChain(nums)).length).toBeGreaterThan(2000);
29-
for (const batch of chunk(nums, 25)) {
30-
expect(encodeURIComponent(orChain(batch)).length).toBeLessThan(1300);
31-
}
32-
});
33-
3422
it("rifiuta una dimensione non valida", () => {
3523
expect(() => chunk([1, 2], 0)).toThrow();
3624
});

src/core/senato-query-size.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { describe, it, expect } from "vitest";
22
import {
3+
SENATO_MAX_OR_TERMS,
34
SENATO_MAX_REQUEST_URI,
45
senatoRequestUriLength,
56
assertQueryFits,
67
} from "./senato-query-size.js";
8+
import { chunk } from "./chunk.js";
9+
import { OSR_PREFIXES } from "./prefixes.js";
710

811
describe("senato-query-size", () => {
912
it("misura la request-URI con l'encoding usato dal client", () => {
@@ -23,6 +26,22 @@ describe("senato-query-size", () => {
2326
);
2427
});
2528

29+
it("la OR-chain delle fiducie sfora intera, a blocchi di SENATO_MAX_OR_TERMS no", () => {
30+
// 53 fiducie in leg. 19: è il caso reale che mandava --keyword in 403.
31+
const nums = Array.from({ length: 53 }, (_, i) => String(1000 + i));
32+
const query = (batch: string[]) => `${OSR_PREFIXES}
33+
SELECT ?ddl ?f WHERE {
34+
?ddl a osr:Ddl ; osr:legislatura 19 ; osr:fase ?f .
35+
FILTER(${batch.map((n) => `STR(?f) = "S.${n}"`).join(" || ")})
36+
}`;
37+
expect(senatoRequestUriLength(query(nums))).toBeGreaterThan(
38+
SENATO_MAX_REQUEST_URI,
39+
);
40+
for (const batch of chunk(nums, SENATO_MAX_OR_TERMS)) {
41+
expect(() => assertQueryFits(query(batch))).not.toThrow();
42+
}
43+
});
44+
2645
it("il confine è esattamente 2047 accettata / 2048 rifiutata", () => {
2746
// padding calibrato sulla lunghezza reale, non stimato
2847
const fill = (target: number) => {

src/tools/senato-votes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ SELECT DISTINCT ?date ?label WHERE {
465465
// post-filtro (altrimenti il LIMIT taglierebbe prima del filtro).
466466
const paginate = input.ddlUri ? "" : `LIMIT ${input.limit}\nOFFSET ${input.offset}`;
467467
// Query scritta compatta di proposito: indentazione e a capo finiscono
468-
// nella request-URI, che oltre 2047 byte viene respinta con 403 (vedi
469-
// SENATO_MAX_OR_TERMS). La keyword entra tre volte — label, titolo e
468+
// nella request-URI, che oltre SENATO_MAX_REQUEST_URI byte viene respinta
469+
// con 403 (di qui assertQueryFits, sotto). La keyword entra tre volte — label, titolo e
470470
// titoloBreve del DDL — quindi la lunghezza cresce di ~3 volte la keyword:
471471
// il margine recuperato qui è ciò che permette le keyword multi-parola.
472472
const coreSelect = `SELECT DISTINCT ?v ?date ?numero ?tipo ?label ?esito ?favorevoli ?contrari ?astenuti ?presenti ?votanti ?maggioranza ?ddl ?oggetto

0 commit comments

Comments
 (0)