agent-bios 0.19.3 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPENDENCIES.md +62 -20
- package/INSTALL.md +1 -1
- package/README.md +16 -21
- package/claude/agents/frontier.md +1 -1
- package/claude/agents/sweep.md +2 -1
- package/claude/agents/workhorse.md +2 -2
- package/claude/guides/claude-prompting.md +494 -167
- package/claude/guides/cli-multi-model-workflow.md +8 -7
- package/claude/guides/gpt-prompting.md +241 -111
- package/claude/guides/session-distill-workflow.md +93 -43
- package/claude/guides/tooling-gotchas.md +3 -1
- package/codex/agents/reviewer.toml +2 -2
- package/codex/agents/sweep.toml +1 -1
- package/codex/agents/workhorse.toml +2 -2
- package/codex/guides/claude-prompting.md +494 -167
- package/codex/guides/cli-multi-model-workflow.md +8 -7
- package/codex/guides/gpt-prompting.md +241 -111
- package/codex/guides/session-distill-workflow.md +93 -43
- package/codex/guides/tooling-gotchas.md +3 -1
- package/compose/assemble.py +4 -1
- package/compose/canary.sh +8 -6
- package/compose/host_platform.py +158 -15
- package/compose/instructions-state.py +183 -41
- package/compose/instructions_app.py +2 -2
- package/compose/instructions_install.py +222 -27
- package/compose/instructions_session.py +250 -75
- package/compose/instructions_setup.py +6 -6
- package/compose/instructions_setup_cli.py +2 -36
- package/compose/instructions_setup_i18n.py +3 -3
- package/compose/instructions_store.py +160 -3
- package/compose/instructions_transaction.py +29 -5
- package/compose/instructions_ui_runtime.py +2 -2
- package/compose/setup/START.md +1 -1
- package/docs/advanced-launch.md +4 -0
- package/docs/releases/0.19.4.md +99 -0
- package/docs/releases/0.20.0.md +102 -0
- package/docs/setup.md +4 -4
- package/install.sh +54 -20
- package/launch/agent-launch.py +171 -22
- package/launch/agent-launch.toml +64 -29
- package/launch/agent-launch.zsh +104 -13
- package/launch/claude_subcommands.py +179 -0
- package/launch/provision-venv.sh +1 -1
- package/launch/shell_integration.py +7 -1
- package/learn/collect-learning.py +60 -9
- package/learn/migrate-learnings.py +70 -4
- package/learn/redact.py +2 -1
- package/package.json +37 -4
- package/provenance.json +1 -1
- package/session-cost.py +141 -18
- package/session-distill/coverage.json +6 -0
- package/session-distill/distill.py +2575 -0
- package/session-distill/grammar/__init__.py +0 -0
- package/session-distill/grammar/owner_lines.py +874 -0
- package/session-distill/originators.json +9 -0
- package/session-distill/packets/cross_review.md +31 -0
- package/session-distill/packets/form.md +86 -0
- package/session-distill/packets/judge.md +81 -0
- package/session-distill/packets/placement_contract.md +90 -0
- package/session-distill/packets/propose.md +124 -0
- package/session-distill/packets/read.md +57 -0
- package/session-distill/packets/reconsider.md +53 -0
- package/session-distill/packets/s7b.md +65 -0
- package/session-distill/packets/s9b.md +39 -0
- package/session-distill/packets/stitch.md +35 -0
- package/session-distill/packets/sweep.md +33 -0
- package/session-distill/runlib/__init__.py +0 -0
- package/session-distill/runlib/bound.py +1102 -0
- package/session-distill/runlib/breaker.py +467 -0
- package/session-distill/runlib/census.py +2347 -0
- package/session-distill/runlib/claims.py +420 -0
- package/session-distill/runlib/controls.py +902 -0
- package/session-distill/runlib/coverage.py +881 -0
- package/session-distill/runlib/declare.py +888 -0
- package/session-distill/runlib/delivery_evidence.py +1145 -0
- package/session-distill/runlib/derive.py +812 -0
- package/session-distill/runlib/destinations.py +3072 -0
- package/session-distill/runlib/dispatch.py +7939 -0
- package/session-distill/runlib/drift.py +1077 -0
- package/session-distill/runlib/entry.py +401 -0
- package/session-distill/runlib/evidence.py +890 -0
- package/session-distill/runlib/exposure.py +1162 -0
- package/session-distill/runlib/gate.py +2727 -0
- package/session-distill/runlib/gitread.py +79 -0
- package/session-distill/runlib/inventory.py +19624 -0
- package/session-distill/runlib/journal.py +1919 -0
- package/session-distill/runlib/ledger.py +3210 -0
- package/session-distill/runlib/ledger_compat.py +101 -0
- package/session-distill/runlib/ledger_migration.py +190 -0
- package/session-distill/runlib/lifecycle_intake.py +693 -0
- package/session-distill/runlib/lineage.py +454 -0
- package/session-distill/runlib/measures.py +249 -0
- package/session-distill/runlib/monitor.py +1180 -0
- package/session-distill/runlib/operations.py +522 -0
- package/session-distill/runlib/packet.py +838 -0
- package/session-distill/runlib/placement.py +1769 -0
- package/session-distill/runlib/projection.py +4090 -0
- package/session-distill/runlib/ranking.py +740 -0
- package/session-distill/runlib/receipts.py +200 -0
- package/session-distill/runlib/records.py +1965 -0
- package/session-distill/runlib/search.py +249 -0
- package/session-distill/runlib/sequencing.py +829 -0
- package/session-distill/runlib/sources.py +641 -0
- package/session-distill/runlib/stage_adjudicate.py +845 -0
- package/session-distill/runlib/stage_apply.py +1378 -0
- package/session-distill/runlib/stage_approvals.py +758 -0
- package/session-distill/runlib/stage_close.py +1220 -0
- package/session-distill/runlib/stage_confirm.py +929 -0
- package/session-distill/runlib/stage_delivery.py +3080 -0
- package/session-distill/runlib/stage_form.py +2576 -0
- package/session-distill/runlib/stage_judge.py +4248 -0
- package/session-distill/runlib/stage_propose.py +3307 -0
- package/session-distill/runlib/stage_read.py +5179 -0
- package/session-distill/runlib/stage_render.py +2739 -0
- package/session-distill/runlib/stage_retrieve.py +924 -0
- package/session-distill/runlib/stage_review_korean.py +1002 -0
- package/session-distill/runlib/stage_review_proposals.py +1292 -0
- package/session-distill/runlib/stagelock.py +412 -0
- package/session-distill/runlib/stop.py +1061 -0
- package/session-distill/runlib/targets.py +809 -0
- package/session-distill/runlib/usage.py +280 -0
- package/session-distill/runlib/validate.py +319 -0
- package/session-distill/runlib/views.py +4327 -0
- package/session-distill/schemas/adjudication.schema.json +35 -0
- package/session-distill/schemas/approval.schema.json +35 -0
- package/session-distill/schemas/census.schema.json +128 -0
- package/session-distill/schemas/checks.schema.json +207 -0
- package/session-distill/schemas/claim.schema.json +16 -0
- package/session-distill/schemas/confirmation.schema.json +24 -0
- package/session-distill/schemas/coverage.schema.json +66 -0
- package/session-distill/schemas/cross_review.schema.json +24 -0
- package/session-distill/schemas/event.schema.json +20 -0
- package/session-distill/schemas/evidence.schema.json +20 -0
- package/session-distill/schemas/expected_observation.schema.json +18 -0
- package/session-distill/schemas/form.schema.json +103 -0
- package/session-distill/schemas/intake.schema.json +71 -0
- package/session-distill/schemas/inventory.schema.json +872 -0
- package/session-distill/schemas/judge.schema.json +77 -0
- package/session-distill/schemas/ledger.schema.json +313 -0
- package/session-distill/schemas/observation.schema.json +16 -0
- package/session-distill/schemas/propose.schema.json +555 -0
- package/session-distill/schemas/read.schema.json +76 -0
- package/session-distill/schemas/reconsider.schema.json +122 -0
- package/session-distill/schemas/run.schema.json +150 -0
- package/session-distill/schemas/s7b.schema.json +200 -0
- package/session-distill/schemas/s9b.schema.json +28 -0
- package/session-distill/schemas/stitch.schema.json +25 -0
- package/session-distill/schemas/sweep.schema.json +25 -0
- package/session-distill/seats.json +149 -0
- package/session-distill/tables/allowed_pairs.json +257 -0
- package/session-distill/tables/controls.json +30 -0
- package/session-distill/tables/delivery_evidence.json +36 -0
- package/session-distill/tables/delivery_evidence_fixtures.json +731 -0
- package/session-distill/tables/destinations.json +684 -0
- package/session-distill/tables/drift_layers.json +68 -0
- package/session-distill/tables/exposure_rules.json +192 -0
- package/session-distill/tables/placement_rules.json +148 -0
- package/session-distill/tables/propose_fixtures.json +154 -0
- package/session-distill/tables/ranking.json +194 -0
- package/session-distill/tables/redundancy.json +10 -0
- package/session-distill/tables/structural_rules.json +44 -0
- package/session-distill/tables/transition_fixtures.json +398 -0
- package/session-distill/tables/transitions.json +69 -0
- package/session-distill/tables/unit_outcome.json +67 -0
- package/session-distill/tables/unit_outcome_fixtures.json +2364 -0
- package/wrappers/claude-run.sh +481 -33
- package/wrappers/claude_hermetic_evidence.py +1423 -0
- package/wrappers/codex-helm.sh +44 -13
- package/wrappers/codex-run.sh +183 -20
- package/wrappers/codex_frame_filter.py +1199 -0
- package/wrappers/codex_protocol.py +737 -0
- package/wrappers/jsonl_lines.py +65 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""The full-source search of design §5.4: BM25 over the redacted text of every viewed version, clipped spans included.
|
|
3
|
+
|
|
4
|
+
An index holds, for every content block it was given, the keys the block contains: its lowercase
|
|
5
|
+
word tokens, and for a run of Hangul or CJK characters the overlapping character bigrams (a
|
|
6
|
+
Korean word carries its particles, so the word itself rarely equals the word a term names). A
|
|
7
|
+
term (a retrieval term of an expected observation, §7.3) is a word or a phrase. A block is a
|
|
8
|
+
**match** for a term when it holds every key of the term and the term, normalized, occurs in the
|
|
9
|
+
block's normalized text; the second test needs the text, so `search` is given `text_of`, a
|
|
10
|
+
function from a document reference to its projected text. The index narrows, the text decides.
|
|
11
|
+
|
|
12
|
+
A hit is scored with BM25 (k1 1.2, b 0.75), the phrase being the unit: tf is the number of
|
|
13
|
+
occurrences in the block, df the number of blocks that matched the phrase, document length the
|
|
14
|
+
block's token count. The score ranks and is reported; whether a block is a hit does not depend on it.
|
|
15
|
+
Search only adds reading, it never closes a claim (§5.4): a term that matches nothing is not
|
|
16
|
+
evidence that nothing was said, and the caller keeps it as such.
|
|
17
|
+
|
|
18
|
+
The index is JSON (`dump`/`load`), never compressed: the run directory is swept as text for what
|
|
19
|
+
must not be in it.
|
|
20
|
+
|
|
21
|
+
search.py --self-test
|
|
22
|
+
"""
|
|
23
|
+
import json
|
|
24
|
+
import math
|
|
25
|
+
import pathlib
|
|
26
|
+
import re
|
|
27
|
+
import sys
|
|
28
|
+
|
|
29
|
+
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
30
|
+
from runlib import projection # noqa: E402 - the one owner of the projection's current version
|
|
31
|
+
|
|
32
|
+
WORD = re.compile(r"\w+", re.UNICODE)
|
|
33
|
+
CJK = re.compile(r"[-ヿ㐀-䶿一-鿿가-힣]+")
|
|
34
|
+
MAX_KEY = 40 # a longer token is an encoded blob, not a word anyone searches for
|
|
35
|
+
K1, B = 1.2, 0.75
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class SearchError(Exception):
|
|
39
|
+
"""A refusal; the message starts with its named code."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def keys_of(text):
|
|
43
|
+
"""The set of keys a text holds, and its token count."""
|
|
44
|
+
words = [w.lower() for w in WORD.findall(text)]
|
|
45
|
+
keys = {w for w in words if len(w) <= MAX_KEY}
|
|
46
|
+
for run in CJK.findall(text):
|
|
47
|
+
keys.update(run[i:i + 2] for i in range(len(run) - 1))
|
|
48
|
+
return keys, len(words)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def normalize(text):
|
|
52
|
+
return " ".join(w.lower() for w in WORD.findall(text))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def term_keys(term):
|
|
56
|
+
"""The keys every matching block holds: a word is itself, and CJK characters stand as their bigrams
|
|
57
|
+
(so a term of one CJK character has no key; `search` refuses it by name)."""
|
|
58
|
+
keys = set()
|
|
59
|
+
for word in WORD.findall(term):
|
|
60
|
+
word = word.lower()
|
|
61
|
+
if CJK.search(word):
|
|
62
|
+
for run in CJK.findall(word):
|
|
63
|
+
keys.update(run[i:i + 2] for i in range(len(run) - 1))
|
|
64
|
+
elif len(word) <= MAX_KEY:
|
|
65
|
+
keys.add(word)
|
|
66
|
+
return keys
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def occurrences(term, text):
|
|
70
|
+
"""How many times `term` occurs in `text`, by the normalization both go through."""
|
|
71
|
+
want, have = normalize(term), normalize(text)
|
|
72
|
+
if not want:
|
|
73
|
+
return 0
|
|
74
|
+
if CJK.search(term):
|
|
75
|
+
return have.replace(" ", "").count(want.replace(" ", ""))
|
|
76
|
+
return f" {have} ".count(f" {want} ")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class Index:
|
|
80
|
+
def __init__(self, version_sha="", redaction_version=""):
|
|
81
|
+
self.version_sha, self.redaction_version = version_sha, redaction_version
|
|
82
|
+
self.docs, self.postings = [], {}
|
|
83
|
+
|
|
84
|
+
def add(self, ref, text):
|
|
85
|
+
"""Add one block under `ref` (a JSON-able reference such as `[line, json_pointer]`)."""
|
|
86
|
+
keys, length = keys_of(text)
|
|
87
|
+
number = len(self.docs)
|
|
88
|
+
self.docs.append({"ref": ref, "length": length})
|
|
89
|
+
for key in keys:
|
|
90
|
+
self.postings.setdefault(key, []).append(number)
|
|
91
|
+
return number
|
|
92
|
+
|
|
93
|
+
def to_json(self):
|
|
94
|
+
return {"version_sha": self.version_sha, "redaction_version": self.redaction_version,
|
|
95
|
+
"docs": self.docs, "postings": {k: self.postings[k] for k in sorted(self.postings)}}
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def from_json(cls, data):
|
|
99
|
+
index = cls(data["version_sha"], data["redaction_version"])
|
|
100
|
+
index.docs, index.postings = data["docs"], data["postings"]
|
|
101
|
+
return index
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def dump(index, path):
|
|
105
|
+
with open(path, "w", encoding="utf-8") as handle:
|
|
106
|
+
json.dump(index.to_json(), handle, ensure_ascii=False, separators=(",", ":"))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def load(path, version=None):
|
|
110
|
+
"""The index at `path`, refused by name when it was built under another projection.
|
|
111
|
+
|
|
112
|
+
The version is checked where the index is CONSUMED, not only where a quote is verified: an index built
|
|
113
|
+
under a projection that masked less lists the words of text the current one would have masked, so a
|
|
114
|
+
search over it can name a block by a term that should not have survived. `version=False` reads it
|
|
115
|
+
without the check, which only a tool that is migrating one may ask for."""
|
|
116
|
+
with open(path, encoding="utf-8") as handle:
|
|
117
|
+
index = Index.from_json(json.load(handle))
|
|
118
|
+
if version is not False:
|
|
119
|
+
want = projection.CURRENT if version is None else version
|
|
120
|
+
if index.redaction_version != want:
|
|
121
|
+
raise SearchError(f"REDACTION_VERSION_MISMATCH {path}: the index was built under "
|
|
122
|
+
f"{index.redaction_version!r}, the projection is {want!r}; build it again")
|
|
123
|
+
return index
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def search(index, terms, text_of):
|
|
127
|
+
"""Hits for `terms`: `[{ref, score, terms}]`, best first, ties in document order.
|
|
128
|
+
|
|
129
|
+
A block is a hit when it matches at least one term; `terms` lists the ones it matched."""
|
|
130
|
+
if not terms:
|
|
131
|
+
raise SearchError("SEARCH_NO_TERMS: a search needs at least one retrieval term")
|
|
132
|
+
for term in terms:
|
|
133
|
+
if not isinstance(term, str) or not term_keys(term):
|
|
134
|
+
raise SearchError(f"SEARCH_TERM_UNUSABLE {term!r}: a term needs a word, or two CJK characters; one that names nothing "
|
|
135
|
+
"would be skipped silently and read as 'searched, nothing found'")
|
|
136
|
+
count = len(index.docs)
|
|
137
|
+
average = (sum(d["length"] for d in index.docs) / count) if count else 0.0
|
|
138
|
+
found = {}
|
|
139
|
+
for term in terms:
|
|
140
|
+
lists = [index.postings.get(k) for k in term_keys(term)]
|
|
141
|
+
if any(l is None for l in lists):
|
|
142
|
+
continue
|
|
143
|
+
candidates = set(lists[0]).intersection(*map(set, lists[1:]))
|
|
144
|
+
matched = {n: occurrences(term, text_of(index.docs[n]["ref"])) for n in sorted(candidates)}
|
|
145
|
+
matched = {n: tf for n, tf in matched.items() if tf}
|
|
146
|
+
df = len(matched)
|
|
147
|
+
if not df:
|
|
148
|
+
continue
|
|
149
|
+
idf = math.log(1 + (count - df + 0.5) / (df + 0.5))
|
|
150
|
+
for n, tf in matched.items():
|
|
151
|
+
length = index.docs[n]["length"]
|
|
152
|
+
weight = idf * tf * (K1 + 1) / (tf + K1 * (1 - B + B * length / average)) if average else 0.0
|
|
153
|
+
hit = found.setdefault(n, {"ref": index.docs[n]["ref"], "score": 0.0, "terms": []})
|
|
154
|
+
hit["score"] += weight
|
|
155
|
+
hit["terms"].append(term)
|
|
156
|
+
return [found[n] for n in sorted(found, key=lambda n: (-found[n]["score"], n))]
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def self_test():
|
|
160
|
+
failures = []
|
|
161
|
+
blocks = {
|
|
162
|
+
0: "Could you show me the plain version of that?",
|
|
163
|
+
1: "the plain text of the version control log", # both words, not the phrase
|
|
164
|
+
2: "PLAIN VERSION please, the plain version again", # case, two occurrences
|
|
165
|
+
3: "database migration finished without errors",
|
|
166
|
+
4: "쉽게 설명해줘, 처음 보는 사람도 이해할 수 있게",
|
|
167
|
+
5: "설명이 너무 어렵다",
|
|
168
|
+
6: "version 2.1.304 (build a1b2c3)",
|
|
169
|
+
}
|
|
170
|
+
index = Index("ab" * 32, projection.CURRENT)
|
|
171
|
+
for n, text in blocks.items():
|
|
172
|
+
index.add([n, "/message/content"], text)
|
|
173
|
+
text_of = lambda ref: blocks[ref[0]] # noqa: E731
|
|
174
|
+
|
|
175
|
+
def refs(terms):
|
|
176
|
+
return [h["ref"][0] for h in search(index, terms, text_of)]
|
|
177
|
+
|
|
178
|
+
if refs(["plain version"]) != [2, 0]: # positive control: the phrase, the block with two occurrences ranks first
|
|
179
|
+
failures.append(f"the phrase 'plain version' hit {refs(['plain version'])}, expected [2, 0]")
|
|
180
|
+
if set(refs(["version"])) != {0, 1, 2, 6}:
|
|
181
|
+
failures.append(f"'version' hit {sorted(refs(['version']))}, expected the four blocks that hold the word")
|
|
182
|
+
if 1 in refs(["plain version"]):
|
|
183
|
+
failures.append("a block with both words apart matched the phrase")
|
|
184
|
+
if set(refs(["migration", "plain version"])) != {0, 2, 3}:
|
|
185
|
+
failures.append("two terms did not union their hits")
|
|
186
|
+
if refs(["not in any block"]) != []:
|
|
187
|
+
failures.append("a term in no block hit something")
|
|
188
|
+
if 4 not in refs(["설명해줘"]) or 5 in refs(["설명해줘"]):
|
|
189
|
+
failures.append(f"a Korean word hit {refs(['설명해줘'])}, expected the block that holds it and not the one that holds only its stem")
|
|
190
|
+
if set(refs(["설명"])) != {4, 5}:
|
|
191
|
+
failures.append(f"a Korean stem hit {refs(['설명'])}, expected both blocks")
|
|
192
|
+
if refs(["2.1.304"]) != [6]:
|
|
193
|
+
failures.append(f"a dotted number hit {refs(['2.1.304'])}")
|
|
194
|
+
scores = [h["score"] for h in search(index, ["plain version"], text_of)]
|
|
195
|
+
if not (scores[0] > scores[1] > 0):
|
|
196
|
+
failures.append(f"scores do not rank by tf: {scores}")
|
|
197
|
+
if search(index, ["plain version"], text_of) != search(index, ["plain version"], text_of):
|
|
198
|
+
failures.append("the same search gave two answers")
|
|
199
|
+
# the index narrows and the text decides: a text_of that disagrees with the index is believed
|
|
200
|
+
if refs(["plain version"]) and search(index, ["plain version"], lambda ref: "nothing relevant"):
|
|
201
|
+
failures.append("a hit was reported for a block whose text does not hold the term")
|
|
202
|
+
# round trip through JSON
|
|
203
|
+
import tempfile
|
|
204
|
+
with tempfile.TemporaryDirectory() as td:
|
|
205
|
+
dump(index, td + "/i.json")
|
|
206
|
+
# M#5: an index built under another projection is refused where it is CONSUMED, not only where a
|
|
207
|
+
# quote is verified: it lists the words of text the current projection would have masked, so a
|
|
208
|
+
# search over it can name a block by a term that should not have survived. Positive first, above.
|
|
209
|
+
stale = Index("ab" * 32, "r1")
|
|
210
|
+
dump(stale, td + "/stale.json")
|
|
211
|
+
try:
|
|
212
|
+
load(td + "/stale.json")
|
|
213
|
+
failures.append("an index built under another projection version was loaded")
|
|
214
|
+
except SearchError as exc:
|
|
215
|
+
if "REDACTION_VERSION_MISMATCH" not in str(exc):
|
|
216
|
+
failures.append(f"a stale index was refused unnamed: {exc}")
|
|
217
|
+
if load(td + "/stale.json", version=False).redaction_version != "r1":
|
|
218
|
+
failures.append("an explicit unchecked load did not read the stale index it was asked for")
|
|
219
|
+
if load(td + "/i.json").to_json() != index.to_json():
|
|
220
|
+
failures.append("the index did not survive a JSON round trip")
|
|
221
|
+
raw = open(td + "/i.json", encoding="utf-8").read()
|
|
222
|
+
if "plain" not in raw:
|
|
223
|
+
failures.append("instrument control: the dumped index is not readable as text, so a text sweep could not see into it")
|
|
224
|
+
for label, terms, code in (("no terms", [], "SEARCH_NO_TERMS"), ("a blank term", ["plain version", " "], "SEARCH_TERM_UNUSABLE"),
|
|
225
|
+
("punctuation only", ["!!"], "SEARCH_TERM_UNUSABLE"), ("a non-string term", [None], "SEARCH_TERM_UNUSABLE"),
|
|
226
|
+
("one CJK character", ["왜"], "SEARCH_TERM_UNUSABLE")):
|
|
227
|
+
try:
|
|
228
|
+
search(index, terms, text_of)
|
|
229
|
+
failures.append(f"{label}: a search with an unusable term was run")
|
|
230
|
+
except SearchError as exc:
|
|
231
|
+
if code not in str(exc):
|
|
232
|
+
failures.append(f"{label}: refused unnamed: {exc}")
|
|
233
|
+
long = Index()
|
|
234
|
+
long.add([0, "/x"], "z" * 60 + " ordinary")
|
|
235
|
+
if "z" * 60 in long.postings or "ordinary" not in long.postings:
|
|
236
|
+
failures.append("a token longer than MAX_KEY was indexed, or an ordinary one was not")
|
|
237
|
+
for failure in failures:
|
|
238
|
+
print(f"search --self-test [FAIL] {failure}")
|
|
239
|
+
if failures:
|
|
240
|
+
return 1
|
|
241
|
+
print(f"search --self-test: OK ({len(blocks)} blocks; phrase, word, case, apart-words, Korean word and stem, dotted number, "
|
|
242
|
+
"two terms, ranking by tf, determinism, the text decides, JSON round trip, an unusable term refused by name)")
|
|
243
|
+
return 0
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
if __name__ == "__main__":
|
|
247
|
+
if "--self-test" not in sys.argv[1:]:
|
|
248
|
+
sys.exit("usage: search.py --self-test")
|
|
249
|
+
sys.exit(self_test())
|