Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,35 @@ single-document JSON is embedded as typed `result`, while successful NDJSON is
embedded as a stable typed `results` array even when it has one row. Successful
text remains `stdout`, while every failure uses one typed `error` object with a
stable `error_code`, `category`, safe `message` / `hint`, and `scope`.
`definition --json` / `--json=ndjson` / `--format json` use `results` for both
one and multiple definitions, including `--body`. Native document/array formats,
compact output, and explicit or automatic envelopes use `result`; unsupported
options and not-found failures retain their existing exit/error contracts.

Exit 11 records can additionally contain `partial_result: true` and typed
`results` (NDJSON) or `result` (count/document/envelope). This requires a validated
partial/interrupted terminal last in the stream or in matching envelope
`metadata.stream_terminal`, or a supported partial find count document. Reconcile
terminal counts with recognized rows and count/control records; retain `_debug`
and `profile` diagnostic objects without counting them as result rows. Bounded envelopes
validate rendered `result_count` while retaining inner scan counts only when their
explicit truncation metadata explains a difference. Scoped regex find with origin
filters also uses NDJSON and preserves unknown-origin partial results. Preserve
all rows, terminal/cursor, truncation, and authority fields. Consumers must still
check `status: "error"`, `exit_code: 11`, and the typed `error`; these records
still increment `command_failures` and do not establish authoritative absence.
For a partial `find --all`, resume with the retained `next_cursor` using the same
query and database; continue checking the child scan/authority flags on each page.
Bounded envelopes paginate with outer `metadata.next_cursor`, while
`metadata.stream_terminal` preserves the inner scan evidence.
Raw-stream diagnostics are not needed to recover these results. Parsing uses the
existing 10,485,760-character capture cap and depth 32, rejects duplicate keys,
invalid Unicode, mixed/truncated streams and conflicting command/exit/error
identities, and never promotes arbitrary failed stdout. Other failures or partial
formats without a recognized partial contract keep the typed-error fallback. Explicit
capture, cancellation, timeout and dispatch errors take precedence, and the parent
output budget applies to the entire retained payload.

The common serial/parallel record writer first projects valid child JSON errors
through `BatchChildErrorParser`, with a 64 KiB UTF-8 input cap, depth 16, unique
object keys, matching command/exit identity when supplied, and an explicit field
Expand Down Expand Up @@ -5506,6 +5535,32 @@ command / output format で projection を選び、成功した単一 document J
は型付き `result`、NDJSON は 1 row の場合も安定した型付き `results` array として埋め込む。
成功した text command は `stdout` のまま保持する一方、すべての失敗は安定した `error_code`、
`category`、安全な `message` / `hint`、`scope` を持つ共通の型付き `error` object を使う。
`definition --json` / `--json=ndjson` / `--format json` は、`--body` の有無や定義が
1件・複数件であるかにかかわらず `results` を使う。ネイティブの単一文書・配列形式、
compact 出力、明示または自動の envelope は `result` を使う。未対応オプションと
定義が見つからない失敗は、既存の終了コードとエラー形式を維持する。

終了コード11のレコードには、追加で `partial_result: true` と型付きの `results`
(NDJSON)または `result`(count・単一文書・envelope)を含められる。ストリームの末尾または
識別情報が一致する envelope の `metadata.stream_terminal` にある部分・中断の終端情報、
もしくは対応するfindの部分count文書の検証に成功した場合に限る。`_debug` と `profile` の
診断オブジェクトは結果行の件数に数えず保持する。終端件数を認識可能な結果行と
count・制御レコードに照合する。上限付きenvelopeは描画後の `result_count` を検証し、
明示的な切り詰め情報で差を説明できる場合だけ内側の走査件数を維持する。
スコープ付き正規表現findもoriginフィルター指定時はNDJSONとなり、判別不能なoriginによる部分結果を保持する。
結果行、終端情報、cursor、切り詰め情報、確定性のフィールドをすべて保持する。
利用側は引き続き `status: "error"`、`exit_code: 11`、型付き `error` を確認する必要がある。
これらも `command_failures` に加算され、結果がないことの確定的な証拠にはならない。
部分的な `find --all` は、保持した `next_cursor` を同じクエリとDBに渡して再開し、
各ページの走査状態と確定性フラグを確認する。上限付きenvelopeのページ送りは外側の
`metadata.next_cursor` を使い、`metadata.stream_terminal` は内側の走査情報として保持する。
結果の取得に生ストリームの診断は不要である。
解析は既存の10,485,760文字のcapture上限と深さ32を使い、重複キー、不正なUnicode、
混在・途中切断ストリーム、command・終了コード・errorの矛盾を拒否する。
任意の失敗stdoutを結果として扱わず、認識可能な部分結果の契約がない形式とその他の失敗は
型付きエラーへフォールバックする。明示的なcapture上限、取消、timeout、dispatchのエラーを
優先し、保持したペイロード全体に親の出力上限を適用する。

serial / parallel 共通の record writer は、まず `BatchChildErrorParser` で有効な子 JSON エラーを
許可フィールドへ射影する。入力は UTF-8 で 64 KiB、深さ 16 に制限し、object key の一意性と、
指定されている command / exit の一致を検証する。単独の `status: "error"` object、または
Expand Down
4 changes: 4 additions & 0 deletions TESTING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ Candidate-ordered parallel-index recovery tests must prove that the fatal result
Batch `--json-summary` coverage keeps side-effect-free dispatch plus successful JSON, single-row NDJSON, and JSON-looking text projection in one seeded fixture when the assertions stay distinct; include case-insensitive format values, command-specific JSON formats, and alias-injected JSON defaults so batch classification cannot drift from child parsers. Serialized-output exhaustion remains a separate boundary fixture because of its large escaped payload. Assert `result` / `results` versus raw `stdout` presence explicitly, compare `output_chars` with the actual captured stream length, and cover repeated malformed lines up to the input cap so neither syntax sniffing nor envelope overhead can bypass the transport bounds. Typed-failure coverage reuses one mixed scalar/array/schema/policy/child-failure input across serial and parallel modes, asserts stable ordered categories, and keeps timeout, caller cancellation, and explicit `--include-raw-streams` behavior in focused fixtures. Shared line-preparation/accounting coverage compares mixed blank, valid, malformed, and unsupported input across serial and parallel modes, including ordered records, first failure, counters, limits, and output characters. Output-limit drain coverage gates two active workers without sleeps, proves the batch remains pending until the held worker completes, keeps an unpublished input-limit record out of committed counters, verifies console restoration after the join, and replays only accepted-but-undispatched nonblank input records in source order before pump-buffered future input with fresh line numbers and counters on the next invocation; blocked-input preservation remains in the focused cancellation fixture. Cancellation coverage includes pre-cancelled setup, cancellation after an earlier failure and after parallel item preparation, and a blocking stdin reader that proves both prompt wake-up and preservation of an in-flight line for the next batch invocation.
Issue #5282 coverage in `QueryCommandRunnerBatchIssue5282Tests.cs` keeps only literal `db schema` and `db integrity` forms batch-dispatchable, compares standalone, serial, and parallel typed results plus inherited and explicit database provenance, and preserves structured missing/corrupt errors, byte budgets, cancellation, and input order. Aliases, unknown arguments, mixed modes, and all mutating maintenance forms must remain fail-closed.
Issue #5259 pairs `BatchChildErrorParserTests` with `QueryCommandRunnerBatchIssue5259Tests`: preserve direct/child E028 classification and every measured budget/retry field for status explanations and search arrays in serial/parallel batches, alongside mixed success/text failures, explicit raw-stream compatibility, parent-budget accounting, and the existing cancellation/timeout fixtures. Parser coverage must retain malformed/duplicate/type/identity rejection, unpaired Unicode surrogate escapes in values and property names, UTF-8 byte and depth boundaries, unknown-minimum/reduce-size retry variants, nested envelopes, text bounds, and secret/path/control sanitization without unknown-field reflection.
Issue #5344 pairs `QueryCommandRunnerBatchIssue5344Tests` with `BatchChildPartialResultParserTests`. Share a small capped-find fixture for direct/batch row, cursor-resume, count, envelope and zero-row parity; preserve exit 11, incomplete flags, ordered mixed-batch failure accounting, optional raw streams and parent-budget fallback. Share definition fixtures across zero/one/multiple matches, body and supported output variants, retaining unsupported-option errors. Reject malformed, duplicate, invalid-Unicode, over-depth, oversized, mixed and unrelated partial captures. Run on net8/net9 with existing batch cancellation/timeout, JSON-envelope, find and #5259 E028 regressions. Nested batch integration remains console-sensitive; pure parser tests do not mutate shared state.
The #5344 partial fixture also covers scoped regex origin filters in row/count/envelope modes and serial/parallel `--verbose` / `--profile` diagnostics with zero or nonzero results. Parser controls must retain diagnostic objects without counting them as rows, reject missing rows and mismatched terminal/envelope counts, and accept zero-row controls and count records; explicit bounded-envelope truncation keeps its inner scan metadata.
Argument-validation variants that only differ by invalid scalar input share one database fixture and iterate within a fact when no per-case state or discovery identity is required.
Positional `files` glob coverage shares one indexed-file fixture and iterates `*`, `?`, and recursive `**` patterns in a fact, matching the exact tokens that a quoted shell argument passes to the CLI.
Excerpt focus coverage reuses one indexed fixture for line-only leading-window behavior, the focus-length dependency, and focus-column range validation; zero and non-numeric focus-column values share one indexed Markdown fixture.
Expand Down Expand Up @@ -1837,6 +1839,8 @@ dotnet test --filter "FullyQualifiedName~GitHelperTests"
batch `--json-summary` coverage は、assertion を明確に保てる場合、副作用なし dispatch と成功時の JSON / 1 row NDJSON / JSON に見える text projection を1つの seeded fixture で共有し、case-insensitive な format 値、command 固有の JSON format、alias が内部追加する JSON default も含めて child parser と batch classification の drift を防いでください。serialized output の枯渇は escape を多く含む大きな payload の境界 fixture として分離します。test 側で `result` / `results` と raw `stdout` の有無を明示し、`output_chars` を実際に捕捉した stream 長と比較し、input cap までの malformed line 反復も検証して、syntax sniffing や envelope overhead が transport 上限を迂回しないようにしてください。typed failure coverage は scalar / array / schema / policy / child failure を混在させた1つの input を serial / parallel mode で共有し、安定した順序と category を検証してください。timeout、caller cancellation、明示的な `--include-raw-streams` の挙動は焦点を絞った fixture に分離します。共有 line preparation / accounting の coverage では blank、valid、malformed、unsupported input の混在を serial / parallel mode で比較し、record 順、first failure、counter、limit、output character 数を固定します。output-limit drain coverage は sleep なしの gate で active worker 2つを保持し、一方の worker が完了するまで batch が pending のままであること、未配送の input-limit record が確定済み counter に混入しないこと、join 後に console が復元されること、受理済みでも未 dispatch の nonblank input record だけが source 順で pump buffer 内の後続入力より前に戻され、次の invocation では line number と counter が新しく付け直されることを検証します。blocked input の保持は focused cancellation fixture に分離してください。cancellation coverage には事前 cancel 済み setup、先行 failure 後と parallel item 準備後の cancellation、blocking stdin reader を含め、型付き summary、迅速な wait 解除、同時に読み取った line が次の batch invocation 用に保持されることを決定的に検証します。
#5282 の coverage は `QueryCommandRunnerBatchIssue5282Tests.cs` で、literal の `db schema` と `db integrity` だけを batch dispatch 可能に保ち、standalone / serial / parallel の型付き result と継承・明示した database provenance を比較します。構造化された missing / corrupt error、byte budget、cancellation、入力順を維持し、alias、未知の引数、mode の混在、変更を伴うすべての maintenance form を fail-closed に固定してください。
Issue #5259 は `BatchChildErrorParserTests` と `QueryCommandRunnerBatchIssue5259Tests` を対にし、status 説明と search 配列の直接実行/子実行における E028 分類および全サイズ・再試行フィールドを逐次/並列 batch で維持します。成功/text 失敗の混在、生 stream の明示指定互換性、親上限の計数、既存の取消/timeout fixture も検証してください。parser は不正 JSON/重複/型/identity の拒否、値と property 名の不対 Unicode surrogate escape、UTF-8 byte/深さの境界、最小値不明/サイズ縮小の再試行、nested envelope、文字数上限、および未知フィールドを反映しない機密情報/path/制御文字の除去を検証します。
Issue #5344 は `QueryCommandRunnerBatchIssue5344Tests` と `BatchChildPartialResultParserTests` を組み合わせます。小さな走査上限付きfind fixtureで、直接実行とbatchの結果行・cursor再開・count・envelope・0件結果を比較し、終了コード11、不完全性フラグ、混在batchの入力順と失敗件数、生ストリームの任意指定、親上限によるフォールバックを維持します。definitionは同じfixtureで0件・1件・複数件、本文と対応出力形式、未対応オプションのエラーを検証します。不正JSON、重複、不正Unicode、深さ・サイズ上限超過、混在出力、無関係な部分出力を拒否してください。既存のbatch取消・timeout、JSON envelope、find、#5259のE028回帰とともにnet8/net9で実行します。入れ子のbatch統合テストはconsole-sensitiveとし、純粋なparserテストは共有状態を変更しません。
#5344の部分結果fixtureは、スコープ付き正規表現のoriginフィルターを結果行・count・envelopeで検証し、逐次/並列の `--verbose` / `--profile` 診断も結果が0件・1件以上の両方で確認します。parserは診断オブジェクトを結果行の件数に数えず保持し、行の欠落、終端・envelope件数の不一致を拒否し、0件の制御レコードとcountレコードを受け付け、明示的な上限付きenvelopeの切り詰めでは内側の走査情報を保持してください。
invalid scalar input だけが異なる argument-validation variant は、case ごとの state や discovery identity が不要なら1つの database fixture を共有し、fact 内で反復してください。
`files` の positional glob coverage は1つの indexed-file fixture を共有し、quote された shell 引数が CLI に渡す token と同じ `*`、`?`、recursive `**` pattern を fact 内で反復してください。
excerpt の focus coverage は、line-only 時の先頭側 window、focus-length の依存関係、focus-column の範囲検証を1つの indexed fixture で共有してください。focus-column の zero / non-numeric value も1つの indexed Markdown fixture を再利用してください。
Expand Down
Loading
Loading