Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0d44fe8f5 | ||
|
|
11c188523a | ||
|
|
794debe565 | ||
|
|
f379bc3882 | ||
|
|
97b76aa20a | ||
|
|
8ea0432ffc | ||
|
|
b9d9a474cf | ||
|
|
b88cdc248a | ||
|
|
c039dd81d5 | ||
|
|
58d23e42b6 |
@@ -76,9 +76,6 @@ explicit path or endpoint and do not need it.
|
|||||||
Facts retain all-recorded-events-before-selection scope. Other qlog layouts
|
Facts retain all-recorded-events-before-selection scope. Other qlog layouts
|
||||||
and PCAP correlation are unsupported.
|
and PCAP correlation are unsupported.
|
||||||
- User-owned Electron runtime already open: `list_electron_targets`.
|
- User-owned Electron runtime already open: `list_electron_targets`.
|
||||||
- Packet-field discovery: `inspect_packet_fields` searches installed protocols
|
|
||||||
and field names/types before choosing fields for `inspect_packet_capture`.
|
|
||||||
Query/page the relevant records; registrations do not establish observed traffic.
|
|
||||||
- Recorded packet captures: `inspect_packet_capture` with selected TShark fields,
|
- Recorded packet captures: `inspect_packet_capture` with selected TShark fields,
|
||||||
display filters and decode-as rules. Requires Linux, util-linux prlimit and `REA_TSHARK_COMMAND`; see
|
display filters and decode-as rules. Requires Linux, util-linux prlimit and `REA_TSHARK_COMMAND`; see
|
||||||
[capture guide](https://github.com/morluto/rea/blob/main/docs/packet-captures.md).
|
[capture guide](https://github.com/morluto/rea/blob/main/docs/packet-captures.md).
|
||||||
@@ -92,9 +89,6 @@ explicit path or endpoint and do not need it.
|
|||||||
[packet summaries](https://github.com/morluto/rea/blob/main/docs/pcap-analysis.md).
|
[packet summaries](https://github.com/morluto/rea/blob/main/docs/pcap-analysis.md).
|
||||||
Select an exact DNS question for address pages; page exhaustion does not prove
|
Select an exact DNS question for address pages; page exhaustion does not prove
|
||||||
network completeness. This reads recordings and does not acquire traffic.
|
network completeness. This reads recordings and does not acquire traffic.
|
||||||
- Decoder discovery: `inspect_signal_decoders` searches installed decoder IDs
|
|
||||||
or selected decoder help, including channels and options. Query and page the
|
|
||||||
relevant details before choosing settings; this does not scan hardware.
|
|
||||||
- Recorded logic/signal traces: `decode_signal_recording` with explicit decoder,
|
- Recorded logic/signal traces: `decode_signal_recording` with explicit decoder,
|
||||||
channel and protocol settings. On Linux with util-linux prlimit, supply sigrok-cli 0.7.2 through
|
channel and protocol settings. On Linux with util-linux prlimit, supply sigrok-cli 0.7.2 through
|
||||||
`REA_SIGROK_COMMAND`; see [recording guide](https://github.com/morluto/rea/blob/main/docs/signal-recordings.md).
|
`REA_SIGROK_COMMAND`; see [recording guide](https://github.com/morluto/rea/blob/main/docs/signal-recordings.md).
|
||||||
|
|||||||
@@ -83,14 +83,6 @@ names, the native API record, and value-flow summaries. Pseudocode offsets and l
|
|||||||
code units; use the returned `next_offset` for continuation. Provider limitations
|
code units; use the returned `next_offset` for continuation. Provider limitations
|
||||||
and unavailable facts remain explicit; the complete parent Evidence is retained.
|
and unavailable facts remain explicit; the complete parent Evidence is retained.
|
||||||
|
|
||||||
`inspect_macho` on a large framework returns megabytes of imports and exports.
|
|
||||||
Select `detail: "summary"` for slice identity, UUID and per-collection counts,
|
|
||||||
then page rows with `view: {kind: "macho", facet: "exports", offset: 0, limit: 64}`
|
|
||||||
and `normalized_result.parent_evidence_id`. Facets are entrypoints,
|
|
||||||
architectures, build_metadata, load_commands, dependencies, imports, exports,
|
|
||||||
segments and provenance. `source_exhaustive: false` means unreturned symbols
|
|
||||||
may exist.
|
|
||||||
|
|
||||||
To see which functions or Objective-C methods a Mach-O actually calls in one
|
To see which functions or Objective-C methods a Mach-O actually calls in one
|
||||||
run, use `observe_native_calls` with explicit breakpoints and a bounded
|
run, use `observe_native_calls` with explicit breakpoints and a bounded
|
||||||
`duration_ms`/`max_events`. It launches a new process under LLDB, so the target
|
`duration_ms`/`max_events`. It launches a new process under LLDB, so the target
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ jobs:
|
|||||||
- run: sudo apt-get update && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y tshark util-linux python3
|
- run: sudo apt-get update && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y tshark util-linux python3
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build:cached
|
- run: npm run build:cached
|
||||||
- run: npm run test:focused -- tests/boundary/captures/fieldDiscovery.test.ts src/process/LinuxResourceLimits.test.ts tests/boundary/captures/captureProvider.test.ts tests/boundary/captures/captureDescriptorCleanup.test.ts tests/boundary/captures/resourceLimits.test.ts tests/boundary/captures/packetOutput.test.ts tests/boundary/mcp/packetCaptureMcp.test.ts tests/boundary/cli/captureCleanup.test.ts
|
- run: npm run test:focused -- src/process/LinuxResourceLimits.test.ts tests/boundary/captures/captureProvider.test.ts tests/boundary/captures/captureDescriptorCleanup.test.ts tests/boundary/captures/resourceLimits.test.ts tests/boundary/captures/packetOutput.test.ts tests/boundary/mcp/packetCaptureMcp.test.ts tests/boundary/cli/captureCleanup.test.ts
|
||||||
- run: node scripts/verify-packet-capture.mjs
|
- run: node scripts/verify-packet-capture.mjs
|
||||||
env:
|
env:
|
||||||
REA_TSHARK_COMMAND: /usr/bin/tshark
|
REA_TSHARK_COMMAND: /usr/bin/tshark
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ jobs:
|
|||||||
- run: sudo apt-get update && sudo apt-get install -y sigrok-cli util-linux python3
|
- run: sudo apt-get update && sudo apt-get install -y sigrok-cli util-linux python3
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build:cached
|
- run: npm run build:cached
|
||||||
- run: npm run test:focused -- tests/boundary/signals/decoderDiscovery.test.ts src/process/LinuxResourceLimits.test.ts src/domain/signals/annotationTextWindow.test.ts tests/boundary/signals/recordingProvider.test.ts tests/boundary/signals/recordingDescriptorCleanup.test.ts tests/boundary/signals/resourceLimits.test.ts tests/boundary/mcp/signalRecordingMcp.test.ts tests/boundary/cli/signalCleanup.test.ts
|
- run: npm run test:focused -- src/process/LinuxResourceLimits.test.ts src/domain/signals/annotationTextWindow.test.ts tests/boundary/signals/recordingProvider.test.ts tests/boundary/signals/recordingDescriptorCleanup.test.ts tests/boundary/signals/resourceLimits.test.ts tests/boundary/mcp/signalRecordingMcp.test.ts tests/boundary/cli/signalCleanup.test.ts
|
||||||
- run: node scripts/verify-signal-recording.mjs
|
- run: node scripts/verify-signal-recording.mjs
|
||||||
env:
|
env:
|
||||||
REA_SIGROK_COMMAND: /usr/bin/sigrok-cli
|
REA_SIGROK_COMMAND: /usr/bin/sigrok-cli
|
||||||
|
|||||||
@@ -72,5 +72,3 @@ Thumbs.db
|
|||||||
|
|
||||||
# Complete static website output, including generated language editions.
|
# Complete static website output, including generated language editions.
|
||||||
website/_site/
|
website/_site/
|
||||||
# Temporary translation output prepared before replacing the complete site.
|
|
||||||
website/.i18n-*/
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"threshold": 3.5,
|
"threshold": 3.0,
|
||||||
"reporters": ["consoleFull"],
|
"reporters": ["consoleFull"],
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"node_modules/**",
|
"node_modules/**",
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ def project_record(state, secrets):
|
|||||||
safe_bytes, credential_url = transport_value(value, path, transport_url)
|
safe_bytes, credential_url = transport_value(value, path, transport_url)
|
||||||
content_base64 = base64.b64encode(value).decode("ascii")
|
content_base64 = base64.b64encode(value).decode("ascii")
|
||||||
digest = hashlib.sha256(value).hexdigest()
|
digest = hashlib.sha256(value).hexdigest()
|
||||||
hidden = any(secret in value or secret in safe_bytes for secret in byte_secrets) or any(secret in content_base64 or secret in digest or secret in str(len(value)) for secret in secrets)
|
hidden = any(secret in value or secret in safe_bytes for secret in byte_secrets) or any(secret in content_base64 or secret in digest for secret in secrets)
|
||||||
safe_text = None
|
safe_text = None
|
||||||
try:
|
try:
|
||||||
safe_text = safe_bytes.decode("utf-8", errors="strict")
|
safe_text = safe_bytes.decode("utf-8", errors="strict")
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ Resolution follows dyld:
|
|||||||
- `@rpath` tries each `LC_RPATH` of the loading image first, then those of the
|
- `@rpath` tries each `LC_RPATH` of the loading image first, then those of the
|
||||||
image that loaded it, up to the process root.
|
image that loaded it, up to the process root.
|
||||||
- Dependencies load dependents-first in load-command order, and each image
|
- Dependencies load dependents-first in load-command order, and each image
|
||||||
loads once per process. A later @rpath request whose install name matches an
|
loads once per process. A later request whose install name matches an
|
||||||
already loaded image reuses it.
|
already loaded image reuses it.
|
||||||
- Symlinks such as `Versions/Current` are followed inside the analyzed root.
|
- Symlinks such as `Versions/Current` are followed inside the analyzed root.
|
||||||
An escape through `..` or an absolute link is `escapes-target`.
|
An escape through `..` or an absolute link is `escapes-target`.
|
||||||
|
|||||||
@@ -57,10 +57,6 @@ Hopper installation or any file write. Declining or pressing Ctrl-C makes no
|
|||||||
changes. Agent configuration writes preserve unrelated entries and comments,
|
changes. Agent configuration writes preserve unrelated entries and comments,
|
||||||
create backups, use atomic replacement, and verify their result. Setup and
|
create backups, use atomic replacement, and verify their result. Setup and
|
||||||
uninstall retain an existing `.rea.backup` rather than replacing the first snapshot.
|
uninstall retain an existing `.rea.backup` rather than replacing the first snapshot.
|
||||||
If that snapshot differs from the current configuration, setup previews and
|
|
||||||
preserves a verified `.rea.backup.<sha256>.recovery` copy of the current bytes.
|
|
||||||
Both snapshots remain available; a failed rollback reports the current recovery
|
|
||||||
copy's path and the restore failure.
|
|
||||||
Setup also retains valid environment overrides in REA's existing server entry,
|
Setup also retains valid environment overrides in REA's existing server entry,
|
||||||
such as `REA_MCP_INPUT_SCHEMA_PROFILE` and `REA_MCP_MAX_RESPONSE_BYTES`.
|
such as `REA_MCP_INPUT_SCHEMA_PROFILE` and `REA_MCP_MAX_RESPONSE_BYTES`.
|
||||||
Detected provider settings replace only matching environment keys.
|
Detected provider settings replace only matching environment keys.
|
||||||
|
|||||||
@@ -104,15 +104,6 @@ static inferences. Dynamic or ambiguous IPC is retained without a pairing edge.
|
|||||||
Runtime entities retain passive-CDP authority, while a successful static/runtime
|
Runtime entities retain passive-CDP authority, while a successful static/runtime
|
||||||
correspondence is a separately identified cross-layer inference.
|
correspondence is a separately identified cross-layer inference.
|
||||||
|
|
||||||
Source module links retain their resolution mode. Static imports in `.ts` and
|
|
||||||
`.tsx` are `compiler-dependent` when compiler options have not been retained.
|
|
||||||
REA compares Node import and require resolution: a shared outcome remains
|
|
||||||
available with a limitation; divergent outcomes remain unavailable with both
|
|
||||||
conditional branches and their limitations. This models source relationships,
|
|
||||||
not verified emitted code or execution. A declaration file found only through
|
|
||||||
an emitted-extension fallback is retained as a candidate, not a runtime target;
|
|
||||||
an explicitly selected path keeps its original identity.
|
|
||||||
|
|
||||||
## Evidence and authority
|
## Evidence and authority
|
||||||
|
|
||||||
Every observation and edge carries all of the following:
|
Every observation and edge carries all of the following:
|
||||||
|
|||||||
@@ -23,14 +23,6 @@ artifact digest and structural graph ID. Semantic tracing requires the semantic
|
|||||||
relation graph and reports when it is unavailable rather than treating missing
|
relation graph and reports when it is unavailable rather than treating missing
|
||||||
data as an empty graph.
|
data as an empty graph.
|
||||||
|
|
||||||
Explicit TypeScript `import type` and `export type` declarations remain source
|
|
||||||
facts and do not create runtime import or export relationships. Type export names
|
|
||||||
are reported separately from value export names. Inline `type` specifiers can
|
|
||||||
leave an empty import or re-export with side effects under
|
|
||||||
[`verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig/verbatimModuleSyntax.html);
|
|
||||||
REA retains those dependency candidates and reports the unavailable compiler
|
|
||||||
options rather than assuming the dependency is erased.
|
|
||||||
|
|
||||||
The semantic graph wire format stores shared non-location provenance once in
|
The semantic graph wire format stores shared non-location provenance once in
|
||||||
its required `evidence_contexts` table. Each node, relation, fingerprint, and
|
its required `evidence_contexts` table. Each node, relation, fingerprint, and
|
||||||
unknown retains its exact `evidence.location` and names the owning context with
|
unknown retains its exact `evidence.location` and names the owning context with
|
||||||
|
|||||||
+2
-15
@@ -147,8 +147,8 @@ after target content was read.
|
|||||||
|
|
||||||
## Retained application Evidence inputs
|
## Retained application Evidence inputs
|
||||||
|
|
||||||
`analyze_javascript_application`, `inspect_binary_layout`, `inspect_artifact`,
|
`analyze_javascript_application`, `inspect_binary_layout`, `inspect_artifact`, and
|
||||||
`inspect_wasm_artifact`, and `inspect_macho` accept `detail`:
|
`inspect_wasm_artifact` accept `detail`:
|
||||||
`complete` (default) returns the complete analysis Evidence; `summary` records
|
`complete` (default) returns the complete analysis Evidence; `summary` records
|
||||||
that complete Evidence in the session and returns the derived
|
that complete Evidence in the session and returns the derived
|
||||||
`inspect_analysis_view` summary Evidence instead. Its
|
`inspect_analysis_view` summary Evidence instead. Its
|
||||||
@@ -218,19 +218,6 @@ attempting oversized delivery, and returns the same summary with an exact
|
|||||||
`parent_evidence_id` for later export or facet reads. Delivery detail does not
|
`parent_evidence_id` for later export or facet reads. Delivery detail does not
|
||||||
reach WABT or change the original source Evidence ID.
|
reach WABT or change the original source Evidence ID.
|
||||||
|
|
||||||
Completed `inspect_macho` Evidence supports a summary and
|
|
||||||
`view: {kind: "macho", facet: "exports", offset: 0, limit: 64}`. Facets are
|
|
||||||
`entrypoints`, `architectures`, `build_metadata`, `load_commands`,
|
|
||||||
`dependencies`, `imports`, `exports`, `segments`, and `provenance`; pages return
|
|
||||||
the original rows. The summary keeps the selected slice, header fields and UUID,
|
|
||||||
and replaces each collection with its returned count, reported total and
|
|
||||||
`exhaustive` flag. Each page repeats the paged collection's `source_total` and
|
|
||||||
`source_exhaustive`; exhausting a non-exhaustive collection does not establish
|
|
||||||
that unreturned symbols are absent. Large frameworks return megabytes of
|
|
||||||
symbols (Electron Framework: 2.5 MB of imports and exports, 3.3 KB as a
|
|
||||||
summary), so select `detail: "summary"` on the first call. Delivery detail
|
|
||||||
never reaches the native tools or changes the source Evidence ID.
|
|
||||||
|
|
||||||
`trace_application_feature`, `trace_javascript_semantics`,
|
`trace_application_feature`, `trace_javascript_semantics`,
|
||||||
`compare_application_versions`, `compare_source_to_bundle`, and
|
`compare_application_versions`, `compare_source_to_bundle`, and
|
||||||
`compare_javascript_export_shapes` accept complete inline application Evidence
|
`compare_javascript_export_shapes` accept complete inline application Evidence
|
||||||
|
|||||||
@@ -128,49 +128,3 @@ Each provider admits one inspection at a time, including acquisition and cleanup
|
|||||||
An occupied provider returns a retryable capacity error before acquiring another
|
An occupied provider returns a retryable capacity error before acquiring another
|
||||||
file or worker. Closing the provider stops new admission and drains accepted work;
|
file or worker. Closing the provider stops new admission and drains accepted work;
|
||||||
failed cleanup remains owned and can be retried.
|
failed cleanup remains owned and can be retried.
|
||||||
|
|
||||||
## Discover protocols and field names
|
|
||||||
|
|
||||||
`inspect_packet_fields` / `inspect-packet-fields` queries the installed TShark
|
|
||||||
registration glossary before selecting fields for capture inspection:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
rea inspect-packet-fields --query usb
|
|
||||||
rea inspect-packet-fields --kind fields --protocol usb --query idVendor
|
|
||||||
rea inspect-packet-fields --kind fields --protocol udp --all
|
|
||||||
```
|
|
||||||
|
|
||||||
`kind` defaults to `protocols`; `fields` selects field definitions. `protocol`
|
|
||||||
selects an exact protocol abbreviation (the protocol itself or its child fields).
|
|
||||||
`query` is a case-insensitive literal substring in name, abbreviation or field
|
|
||||||
description. `offset` skips matching records; `limit` defaults to 50. MCP
|
|
||||||
`limit: null` or CLI `--all` requests all remaining matches within the resource
|
|
||||||
budget. `--all` and `--limit` conflict. The window reports examined records of
|
|
||||||
the selected kind before filters, matching records, returned records and
|
|
||||||
`has_more`; it never counts capture packets.
|
|
||||||
|
|
||||||
Returned records preserve field type, parent protocol, display base, bitmask,
|
|
||||||
description and original glossary line number. Empty producer strings remain
|
|
||||||
empty; protocol records have null field-only properties. Repeated abbreviations
|
|
||||||
remain separate registrations. A listed field is an installation capability, not
|
|
||||||
proof that the field appears in a selected recording.
|
|
||||||
|
|
||||||
The adapter uses the documented `tshark -G fields` grammar under its existing
|
|
||||||
private empty profile and Linux process limits. TShark 4.6.9's full glossary was
|
|
||||||
measured at 22,303,197 bytes; discovery admits at most **32 MiB** combined command
|
|
||||||
output (capture inspection remains at **4 MiB**). Parsing walks lines once and
|
|
||||||
constructs objects only for the selected page. Returned strings are copied so
|
|
||||||
retained pages do not retain the complete glossary string. Before constructing a selected
|
|
||||||
record it charges six times the source UTF-8 bytes plus 512 bytes against an
|
|
||||||
**8 MiB** representation budget, covering JSON escaping and record bookkeeping.
|
|
||||||
If that budget would be exceeded, narrow the query or page size; results are not
|
|
||||||
silently truncated. This is a conservative admission budget, not measured heap
|
|
||||||
usage. Parent pipe buffers and producer per-process limits remain distinct.
|
|
||||||
|
|
||||||
Tool/limiter identity, version, stderr and selected arguments are retained in
|
|
||||||
Evidence. No capture, interface or device is opened. Discovery shares capture
|
|
||||||
analysis's admission slot and cleanup owner. Each call rereads the glossary;
|
|
||||||
installed plugins, libraries and global configuration remain trusted and are not
|
|
||||||
fully fingerprinted. There is no cache or snapshot-consistent pagination claim.
|
|
||||||
The real Linux lane checks public CLI/MCP queries against the direct glossary,
|
|
||||||
including USB vendor-ID typing, negative queries and paging.
|
|
||||||
|
|||||||
@@ -106,37 +106,3 @@ One decode is admitted at a time, including acquisition and cleanup. Excess
|
|||||||
requests receive a retryable capacity error before acquiring another file or
|
requests receive a retryable capacity error before acquiring another file or
|
||||||
worker. Shutdown closes admission and drains accepted work; failed cleanup
|
worker. Shutdown closes admission and drains accepted work; failed cleanup
|
||||||
remains owned and retryable.
|
remains owned and retryable.
|
||||||
|
|
||||||
## Discover decoders before choosing settings
|
|
||||||
|
|
||||||
`inspect_signal_decoders` / `inspect-signal-decoders` queries the **installed**
|
|
||||||
sigrok catalog without opening a recording or scanning devices:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
rea inspect-signal-decoders --query uart
|
|
||||||
rea inspect-signal-decoders --decoder uart --query baud
|
|
||||||
rea inspect-signal-decoders --decoder i2c --offset 0 --limit 50
|
|
||||||
```
|
|
||||||
|
|
||||||
Omit `decoder` to search decoder IDs and names. Supply one exact decoder ID to
|
|
||||||
read its literal help, including required/optional channels, options, annotation
|
|
||||||
classes and documentation. `query` is a case-insensitive literal substring;
|
|
||||||
matching help retains original one-based line numbers. Empty query selects all.
|
|
||||||
`offset` skips matches; `limit` defaults to 50. MCP `limit: null` or CLI `--all`
|
|
||||||
returns all remaining matches; CLI `--all` and `--limit` conflict.
|
|
||||||
The window reports examined, matching and returned records and `has_more`.
|
|
||||||
A filtered empty page is not evidence that the installation has no decoders.
|
|
||||||
|
|
||||||
Discovery refuses more than 65,535 line separators before constructing record
|
|
||||||
objects (65,536-line representation budget), in addition to the 4 MiB output cap.
|
|
||||||
Exceeding that budget is a resource failure with captured output. Returned text
|
|
||||||
is copied so a retained page does not keep the complete producer output alive.
|
|
||||||
|
|
||||||
Discovery shares decoding's owned process, admission slot, resource limits,
|
|
||||||
cleanup retries and Evidence delivery. It records the executable and limiter
|
|
||||||
identities, version banner and warnings. Failed version checks and malformed
|
|
||||||
producer output preserve diagnostics. Help is producer text, not an independently
|
|
||||||
validated parameter schema. Each request probes again; it does not cache or claim
|
|
||||||
stable pages across installation changes. Libraries/decoder modules remain
|
|
||||||
trusted and are not fully fingerprinted. Catalog output includes a SHA-256 of
|
|
||||||
its executable, not a digest of the complete installation.
|
|
||||||
|
|||||||
@@ -153,12 +153,8 @@ the private runtime, isolating Ghidra preferences, logs, and caches.
|
|||||||
Process creation assigns a suspended child atomically to an owned Job Object.
|
Process creation assigns a suspended child atomically to an owned Job Object.
|
||||||
Membership and kill-on-owner-close policy are verified before resume.
|
Membership and kill-on-owner-close policy are verified before resume.
|
||||||
Breakaway is disabled. Only the child's default file owner is normalized;
|
Breakaway is disabled. Only the child's default file owner is normalized;
|
||||||
the caller token stays unchanged. Caller priority is preserved, and caller CPU
|
the caller token stays unchanged. Caller CPU affinity and priority are
|
||||||
affinity whenever the caller and the child share a processor group. A child that
|
preserved. Close, cancellation, timeout, startup failure, and provider failure
|
||||||
Windows places in another group keeps that group's default when the caller asked
|
|
||||||
for no bound of its own; a caller pinned to fewer processors than its group
|
|
||||||
holds is refused there rather than widened.
|
|
||||||
Close, cancellation, timeout, startup failure, and provider failure
|
|
||||||
terminate the job and verify all members have settled before runtime cleanup.
|
terminate the job and verify all members have settled before runtime cleanup.
|
||||||
Cleanup removes admitted objects by handle and unlinks reparse entries without
|
Cleanup removes admitted objects by handle and unlinks reparse entries without
|
||||||
following their targets. Abrupt owner death kills the job but can leave
|
following their targets. Abrupt owner death kills the job but can leave
|
||||||
|
|||||||
@@ -69,22 +69,10 @@ without this lane reports Windows native controls as unavailable.
|
|||||||
limits only for its JavaScript helpers when running on Bun, which ignores
|
limits only for its JavaScript helpers when running on Bun, which ignores
|
||||||
their V8 heap flags; Node.js launches are unchanged.
|
their V8 heap flags; Node.js launches are unchanged.
|
||||||
- Only the suspended child's default file owner is normalized. Caller token
|
- Only the suspended child's default file owner is normalized. Caller token
|
||||||
privileges and ownership remain unchanged. Caller process priority is
|
privileges and ownership remain unchanged. Caller CPU affinity and process
|
||||||
preserved in the child, and caller CPU affinity whenever both occupy the same
|
priority are preserved in the child. Environment names are sorted and
|
||||||
processor group. Windows chooses a new process's group itself and rejects a
|
deduplicated using Windows ordinal comparison, preserving their native Unicode
|
||||||
mask belonging to another group, so a child placed elsewhere keeps that
|
semantics and caller-selected values.
|
||||||
group's default when the caller asked for no bound of its own. A caller
|
|
||||||
deliberately pinned to fewer processors than its group holds is a constraint
|
|
||||||
such a child cannot express, and is refused rather than widened to that
|
|
||||||
group's default. A mask covering its group's whole active set does not
|
|
||||||
distinguish a caller Windows placed in that group from one that selected the
|
|
||||||
group deliberately, so such a child can still be placed elsewhere: its
|
|
||||||
processor count stays bounded, its group placement is not preserved, and
|
|
||||||
neither that case nor the refusal above has a verification lane, because both
|
|
||||||
need a host whose processors span more than one group.
|
|
||||||
Environment names are sorted and deduplicated using Windows
|
|
||||||
ordinal comparison, preserving their native Unicode semantics and
|
|
||||||
caller-selected values.
|
|
||||||
- Cleanup walks locked directory objects, removes files by handle, and unlinks
|
- Cleanup walks locked directory objects, removes files by handle, and unlinks
|
||||||
reparse entries without traversing their targets. Failed removal retains the
|
reparse entries without traversing their targets. Failed removal retains the
|
||||||
root and ancestor leases for retry; a partially removed runtime accepts only
|
root and ancestor leases for retry; a partially removed runtime accepts only
|
||||||
|
|||||||
@@ -68,18 +68,6 @@ static ULONGLONG jobMemoryLimit(napi_env env, napi_value value) {
|
|||||||
return limit;
|
return limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An affinity mask is meaningful only inside one processor group, so only a
|
|
||||||
// process occupying exactly one group has a group a child can inherit. A
|
|
||||||
// process whose threads span groups, or whose membership cannot be read, has no
|
|
||||||
// single group.
|
|
||||||
static bool singleProcessorGroup(HANDLE process, USHORT& group) {
|
|
||||||
USHORT count = 1;
|
|
||||||
std::array<USHORT, 1> groups{};
|
|
||||||
if (!GetProcessGroupAffinity(process, &count, groups.data()) || count != 1) return false;
|
|
||||||
group = groups[0];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pipe(Handle& read, Handle& write, bool parentReads = true) {
|
static void pipe(Handle& read, Handle& write, bool parentReads = true) {
|
||||||
SECURITY_ATTRIBUTES attributes{sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
|
SECURITY_ATTRIBUTES attributes{sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
|
||||||
HANDLE rawRead, rawWrite;
|
HANDLE rawRead, rawWrite;
|
||||||
@@ -180,27 +168,11 @@ std::unique_ptr<Process> spawnProcess(const std::wstring& command, const std::ws
|
|||||||
TOKEN_OWNER owner{reinterpret_cast<TOKEN_USER*>(tokenUser.data())->User.Sid};
|
TOKEN_OWNER owner{reinterpret_cast<TOKEN_USER*>(tokenUser.data())->User.Sid};
|
||||||
require(SetTokenInformation(token.get(), TokenOwner, &owner, sizeof(owner)),
|
require(SetTokenInformation(token.get(), TokenOwner, &owner, sizeof(owner)),
|
||||||
"Set suspended process file owner failed", command);
|
"Set suspended process file owner failed", command);
|
||||||
// A mask names processors inside one processor group, and Windows assigns a
|
|
||||||
// new process to a group of its own choosing, so a mask belonging to another
|
|
||||||
// group is rejected (ERROR_INVALID_PARAMETER). An unconstrained caller, whose
|
|
||||||
// mask is its group's whole active set, asks for no bound the child's own
|
|
||||||
// group cannot give, so such a child keeps that group's default and the spawn
|
|
||||||
// proceeds. A narrower mask is a deliberate CPU constraint that a child in
|
|
||||||
// another group cannot express, and silently widening it would hand the
|
|
||||||
// provider tree the whole group, so that spawn fails naming the constraint.
|
|
||||||
DWORD_PTR affinity = 0, systemAffinity = 0;
|
DWORD_PTR affinity = 0, systemAffinity = 0;
|
||||||
require(GetProcessAffinityMask(GetCurrentProcess(), &affinity, &systemAffinity),
|
require(GetProcessAffinityMask(GetCurrentProcess(), &affinity, &systemAffinity),
|
||||||
"Read caller process affinity failed", command);
|
"Read caller process affinity failed", command);
|
||||||
USHORT callerGroup = 0, childGroup = 0;
|
if (affinity != 0)
|
||||||
const bool sharedGroup = singleProcessorGroup(GetCurrentProcess(), callerGroup) &&
|
|
||||||
singleProcessorGroup(result->process.get(), childGroup) &&
|
|
||||||
callerGroup == childGroup;
|
|
||||||
if (affinity != 0 && sharedGroup)
|
|
||||||
require(SetProcessAffinityMask(result->process.get(), affinity), "Preserve caller process affinity failed", command);
|
require(SetProcessAffinityMask(result->process.get(), affinity), "Preserve caller process affinity failed", command);
|
||||||
else
|
|
||||||
require(affinity == 0 || affinity == systemAffinity,
|
|
||||||
"Caller CPU affinity cannot bound an owned process in another processor group", command,
|
|
||||||
ERROR_INVALID_PARAMETER);
|
|
||||||
const DWORD priority = GetPriorityClass(GetCurrentProcess());
|
const DWORD priority = GetPriorityClass(GetCurrentProcess());
|
||||||
require(priority != 0 && SetPriorityClass(result->process.get(), priority),
|
require(priority != 0 && SetPriorityClass(result->process.get(), priority),
|
||||||
"Preserve caller process priority failed", command);
|
"Preserve caller process priority failed", command);
|
||||||
|
|||||||
@@ -45,20 +45,6 @@ class Generator:
|
|||||||
assert "ows-secret" not in json.dumps(projected), projected
|
assert "ows-secret" not in json.dumps(projected), projected
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
assert projected["binary_fields"][-1]["state"] == "redacted", projected
|
assert projected["binary_fields"][-1]["state"] == "redacted", projected
|
||||||
body = b"A" * 12345
|
|
||||||
state = {"response": {"content": body}}
|
|
||||||
control = adapter.project_record(state, [])
|
|
||||||
field = control["binary_fields"][0]
|
|
||||||
assert field["state"] == "retained" and field["bytes"] == len(body), control
|
|
||||||
for literal in ["12345", "2345"]:
|
|
||||||
# Only the generated byte count matches this exclusion.
|
|
||||||
assert literal not in control["reported"]["response"]["content"]
|
|
||||||
assert literal not in field["content_base64"] and literal not in field["sha256"]
|
|
||||||
projected = adapter.project_record(state, [literal])
|
|
||||||
assert projected["reported"]["response"]["content"] is None, projected
|
|
||||||
assert projected["binary_fields"] == [{"pointer": "/response/content", "representation": "producer-bytes", "state": "redacted", "content_base64": None, "bytes": None, "sha256": None}], projected
|
|
||||||
assert {"pointer": "/response/content", "reason": "explicit-sensitive-value"} in projected["redactions"], projected
|
|
||||||
assert literal not in json.dumps(projected), projected
|
|
||||||
(root / "native-error-classifications.json").write_text(json.dumps({"passed": len(classifications) + 2}))
|
(root / "native-error-classifications.json").write_text(json.dumps({"passed": len(classifications) + 2}))
|
||||||
first = http.HTTPFlow(connection.Client(peername=("127.0.0.1", 1), sockname=("127.0.0.1", 2)), connection.Server(address=("example.test", 80)))
|
first = http.HTTPFlow(connection.Client(peername=("127.0.0.1", 1), sockname=("127.0.0.1", 2)), connection.Server(address=("example.test", 80)))
|
||||||
first.id = "original-producer-id"
|
first.id = "original-producer-id"
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { execFile } from "node:child_process";
|
import { readFile, readdir, stat } from "node:fs/promises";
|
||||||
import { promisify } from "node:util";
|
import { basename } from "node:path";
|
||||||
import { readdir, stat } from "node:fs/promises";
|
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Observe leftover demo processes on a dedicated clean Linux runner, including
|
* Observe leftover demo processes on a dedicated clean Linux runner, including
|
||||||
@@ -17,9 +14,6 @@ export const assertCleanLinuxHopperRuntime = async (
|
|||||||
: [process.env.HOPPER_LAUNCHER_PATH]),
|
: [process.env.HOPPER_LAUNCHER_PATH]),
|
||||||
],
|
],
|
||||||
) => {
|
) => {
|
||||||
const { stdout } = await execFileAsync("ps", ["-ax", "-o", "command="]);
|
|
||||||
if (/\/opt\/hopper\/bin\/Hopper|\bXvfb\b|hopper-demo-x11\.py/u.test(stdout))
|
|
||||||
throw new Error("Clean Linux runner retained a Hopper demo process");
|
|
||||||
const launchers = [];
|
const launchers = [];
|
||||||
for (const path of launcherPaths) {
|
for (const path of launcherPaths) {
|
||||||
try {
|
try {
|
||||||
@@ -28,18 +22,34 @@ export const assertCleanLinuxHopperRuntime = async (
|
|||||||
if (error?.code !== "ENOENT") throw error;
|
if (error?.code !== "ENOENT") throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (launchers.length === 0) return;
|
|
||||||
// /proc exposes the executed file even when argv[0] names a removed symlink.
|
// /proc exposes the executed file even when argv[0] names a removed symlink.
|
||||||
// Compare file identity, not a display path or a process name.
|
// Compare file identity, not a display path or a process name.
|
||||||
let inspectionError;
|
let inspectionError;
|
||||||
for (const entry of await readdir("/proc", { withFileTypes: true })) {
|
for (const entry of await readdir("/proc", { withFileTypes: true })) {
|
||||||
if (!entry.isDirectory() || !/^\d+$/u.test(entry.name)) continue;
|
if (!entry.isDirectory() || !/^\d+$/u.test(entry.name)) continue;
|
||||||
let executable;
|
let retainedRuntime;
|
||||||
try {
|
try {
|
||||||
executable = await stat(`/proc/${entry.name}/exe`, { bigint: true });
|
// procfs preserves argument boundaries. A caller merely mentioning a
|
||||||
|
// runtime in its script text or other arguments is not that runtime.
|
||||||
|
const arguments_ = (
|
||||||
|
await readFile(`/proc/${entry.name}/cmdline`, "utf8")
|
||||||
|
).split("\0");
|
||||||
|
retainedRuntime =
|
||||||
|
arguments_[0] === "/opt/hopper/bin/Hopper" ||
|
||||||
|
basename(arguments_[0] ?? "") === "Xvfb" ||
|
||||||
|
(basename(arguments_[0] ?? "") === "python3" &&
|
||||||
|
basename(arguments_[1] ?? "") === "hopper-demo-x11.py");
|
||||||
|
if (!retainedRuntime && launchers.length > 0) {
|
||||||
|
const executable = await stat(`/proc/${entry.name}/exe`, {
|
||||||
|
bigint: true,
|
||||||
|
});
|
||||||
|
retainedRuntime = launchers.some(
|
||||||
|
({ dev, ino }) => dev === executable.dev && ino === executable.ino,
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error?.code === "ENOENT" || error?.code === "ESRCH") continue;
|
if (error?.code === "ENOENT" || error?.code === "ESRCH") continue;
|
||||||
// Other users' executables may be unreadable. The setup lane launches
|
// Other users' process facts may be unreadable. The setup lane launches
|
||||||
// providers as the caller; unreadable caller-owned processes fail closed.
|
// providers as the caller; unreadable caller-owned processes fail closed.
|
||||||
if (error?.code === "EACCES") {
|
if (error?.code === "EACCES") {
|
||||||
const owner = await stat(`/proc/${entry.name}`).catch((cause) => {
|
const owner = await stat(`/proc/${entry.name}`).catch((cause) => {
|
||||||
@@ -53,11 +63,7 @@ export const assertCleanLinuxHopperRuntime = async (
|
|||||||
inspectionError ??= error;
|
inspectionError ??= error;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (
|
if (retainedRuntime)
|
||||||
launchers.some(
|
|
||||||
({ dev, ino }) => dev === executable.dev && ino === executable.ino,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
throw new Error("Clean Linux runner retained a Hopper demo process");
|
throw new Error("Clean Linux runner retained a Hopper demo process");
|
||||||
}
|
}
|
||||||
if (inspectionError !== undefined) throw inspectionError;
|
if (inspectionError !== undefined) throw inspectionError;
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import type { z } from "zod";
|
||||||
|
|
||||||
|
import type { analysisStringSchema } from "../../src/domain/hopperValues.js";
|
||||||
|
|
||||||
type VerifierCall = (
|
type VerifierCall = (
|
||||||
name: string,
|
name: string,
|
||||||
arguments_?: Record<string, unknown>,
|
arguments_?: Record<string, unknown>,
|
||||||
@@ -25,6 +29,3 @@ export function verifyHopperStringObjects(
|
|||||||
}[];
|
}[];
|
||||||
readonly displayEscapesExcludedFromMatching: true;
|
readonly displayEscapesExcludedFromMatching: true;
|
||||||
}>;
|
}>;
|
||||||
import type { z } from "zod";
|
|
||||||
|
|
||||||
import type { analysisStringSchema } from "../../src/domain/hopperValues.js";
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { estimateTokenCount } from "tokenx";
|
|
||||||
import { execFile } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
import { readFile, writeFile, readdir, mkdir, rm } from "node:fs/promises";
|
import { readFile, writeFile, readdir } from "node:fs/promises";
|
||||||
import { isAbsolute, join } from "node:path";
|
import { isAbsolute, join } from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
@@ -92,20 +91,6 @@ const source = pcap(1, [
|
|||||||
// LINKTYPE_BLUETOOTH_HCI_H4 = 187; H4 command packet, HCI Reset opcode 0x0c03, no parameters.
|
// LINKTYPE_BLUETOOTH_HCI_H4 = 187; H4 command packet, HCI Reset opcode 0x0c03, no parameters.
|
||||||
const bluetoothSource = pcap(187, [Buffer.from("01030c00", "hex")]);
|
const bluetoothSource = pcap(187, [Buffer.from("01030c00", "hex")]);
|
||||||
let cases = 0;
|
let cases = 0;
|
||||||
const discoveryMeasurements = [];
|
|
||||||
const inheritedAddressSpace = (await readFile("/proc/self/limits", "utf8"))
|
|
||||||
.split("\n")
|
|
||||||
.find((line) => line.startsWith("Max address space "))
|
|
||||||
?.trim()
|
|
||||||
.match(/^Max address space\s+(\S+)\s+(\S+)\s+bytes$/u);
|
|
||||||
assert.ok(inheritedAddressSpace);
|
|
||||||
const expectedAddressSpace = Math.min(
|
|
||||||
1073741824,
|
|
||||||
...inheritedAddressSpace
|
|
||||||
.slice(1)
|
|
||||||
.map((value) => (value === "unlimited" ? Infinity : Number(value))),
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await writeFile(path, source);
|
await writeFile(path, source);
|
||||||
await writeFile(bluetooth, bluetoothSource);
|
await writeFile(bluetooth, bluetoothSource);
|
||||||
@@ -136,16 +121,14 @@ try {
|
|||||||
.digest("hex"),
|
.digest("hex"),
|
||||||
);
|
);
|
||||||
assert.equal(report.hardware_acquisition, "not-performed");
|
assert.equal(report.hardware_acquisition, "not-performed");
|
||||||
assert.equal(report.limits.address_space_bytes, expectedAddressSpace);
|
assert.equal(report.limits.address_space_bytes, 1073741824);
|
||||||
assert.equal(report.tool.configured_path, process.env.REA_TSHARK_COMMAND);
|
assert.equal(report.tool.configured_path, process.env.REA_TSHARK_COMMAND);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
report.resource_limiter.configured_path,
|
report.resource_limiter.configured_path,
|
||||||
process.env.REA_TSHARK_PRLIMIT_COMMAND ?? "/usr/bin/prlimit",
|
process.env.REA_TSHARK_PRLIMIT_COMMAND ?? "/usr/bin/prlimit",
|
||||||
);
|
);
|
||||||
assert.ok(
|
assert.ok(
|
||||||
report.resource_limiter.arguments.includes(
|
report.resource_limiter.arguments.includes("--as=1073741824:1073741824"),
|
||||||
`--as=${expectedAddressSpace}:${expectedAddressSpace}`,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
assert.equal(report.configuration, "private-empty-personal-profile");
|
assert.equal(report.configuration, "private-empty-personal-profile");
|
||||||
const flags = Object.entries(input)
|
const flags = Object.entries(input)
|
||||||
@@ -330,133 +313,6 @@ try {
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
cases++;
|
cases++;
|
||||||
const discovery = (await client.listTools()).tools.find(
|
|
||||||
({ name }) => name === "inspect_packet_fields",
|
|
||||||
);
|
|
||||||
assert.ok(discovery?.outputSchema);
|
|
||||||
assert.ok(ajv.validateSchema(discovery.inputSchema));
|
|
||||||
assert.ok(ajv.validateSchema(discovery.outputSchema));
|
|
||||||
const nativeProfile = join(root.path, "native-profile");
|
|
||||||
await mkdir(nativeProfile);
|
|
||||||
const native = (
|
|
||||||
await execute(process.env.REA_TSHARK_COMMAND, ["-G", "fields"], {
|
|
||||||
env: { ...environment, WIRESHARK_CONFIG_DIR: nativeProfile },
|
|
||||||
timeout: 30000,
|
|
||||||
maxBuffer: 32 * 1024 * 1024,
|
|
||||||
})
|
|
||||||
).stdout;
|
|
||||||
await rm(nativeProfile, { recursive: true });
|
|
||||||
const nativeLines = native.split(/\r?\n/);
|
|
||||||
if (nativeLines.at(-1) === "") nativeLines.pop();
|
|
||||||
for (const input of [
|
|
||||||
{ query: "usb" },
|
|
||||||
{ limit: 1 },
|
|
||||||
{ offset: 1, limit: 2 },
|
|
||||||
{ kind: "fields", protocol: "usb", query: "idVendor" },
|
|
||||||
{ kind: "fields", protocol: "udp", limit: null },
|
|
||||||
{ kind: "fields", query: "rea_no_such_field" },
|
|
||||||
]) {
|
|
||||||
const started = performance.now();
|
|
||||||
const response = await client.callTool({
|
|
||||||
name: discovery.name,
|
|
||||||
arguments: input,
|
|
||||||
});
|
|
||||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
|
||||||
assert.ok(
|
|
||||||
ajv.validate(discovery.outputSchema, response.structuredContent),
|
|
||||||
JSON.stringify(ajv.errors),
|
|
||||||
);
|
|
||||||
const evidence = parseEvidence(response.structuredContent);
|
|
||||||
const report = evidence.normalized_result;
|
|
||||||
const kind = input.kind ?? "protocols";
|
|
||||||
const query = (input.query ?? "").toLowerCase();
|
|
||||||
const expectedMatches = nativeLines.flatMap((line, index) => {
|
|
||||||
const columns = line.split("\t");
|
|
||||||
if ((kind === "protocols") !== (columns[0] === "P")) return [];
|
|
||||||
if (
|
|
||||||
input.protocol !== undefined &&
|
|
||||||
(columns[0] === "P" ? columns[2] : columns[4]) !== input.protocol
|
|
||||||
)
|
|
||||||
return [];
|
|
||||||
if (
|
|
||||||
![
|
|
||||||
columns[1],
|
|
||||||
columns[2],
|
|
||||||
...(columns[0] === "F" ? [columns[7]] : []),
|
|
||||||
].some((value) => value.toLowerCase().includes(query))
|
|
||||||
)
|
|
||||||
return [];
|
|
||||||
return [{ sourceLine: index + 1, columns }];
|
|
||||||
});
|
|
||||||
const offset = input.offset ?? 0;
|
|
||||||
const limit = input.limit === null ? undefined : (input.limit ?? 50);
|
|
||||||
const expectedPage = expectedMatches.slice(
|
|
||||||
offset,
|
|
||||||
limit === undefined ? undefined : offset + limit,
|
|
||||||
);
|
|
||||||
assert.deepEqual(
|
|
||||||
report.records.map((record) => record.source_line),
|
|
||||||
expectedPage.map((record) => record.sourceLine),
|
|
||||||
);
|
|
||||||
assert.deepEqual(report.output_window, {
|
|
||||||
examined: nativeLines.filter((line) =>
|
|
||||||
line.startsWith(kind === "protocols" ? "P\t" : "F\t"),
|
|
||||||
).length,
|
|
||||||
matching: expectedMatches.length,
|
|
||||||
returned: expectedPage.length,
|
|
||||||
has_more:
|
|
||||||
Math.max(0, expectedMatches.length - offset) > expectedPage.length,
|
|
||||||
});
|
|
||||||
discoveryMeasurements.push({
|
|
||||||
input,
|
|
||||||
elapsed_ms: +(performance.now() - started).toFixed(2),
|
|
||||||
response_bytes: Buffer.byteLength(JSON.stringify(response)),
|
|
||||||
estimated_tokens_one_tool_request_response: estimateTokenCount(
|
|
||||||
JSON.stringify(discovery) +
|
|
||||||
JSON.stringify(input) +
|
|
||||||
JSON.stringify(response),
|
|
||||||
),
|
|
||||||
});
|
|
||||||
for (const record of report.records) {
|
|
||||||
const columns = nativeLines[record.source_line - 1].split("\t");
|
|
||||||
assert.equal(record.name, columns[1]);
|
|
||||||
assert.equal(record.abbreviation, columns[2]);
|
|
||||||
assert.equal(record.field_type, columns[0] === "F" ? columns[3] : null);
|
|
||||||
assert.equal(
|
|
||||||
record.parent_protocol,
|
|
||||||
columns[0] === "F" ? columns[4] : null,
|
|
||||||
);
|
|
||||||
assert.equal(record.description, columns[0] === "F" ? columns[7] : null);
|
|
||||||
assert.equal(record.display_base, columns[0] === "F" ? columns[5] : null);
|
|
||||||
assert.equal(record.bitmask, columns[0] === "F" ? columns[6] : null);
|
|
||||||
}
|
|
||||||
if (input.query === "idVendor")
|
|
||||||
assert.ok(
|
|
||||||
report.records.some(
|
|
||||||
(row) =>
|
|
||||||
row.abbreviation === "usb.idVendor" &&
|
|
||||||
row.field_type === "FT_UINT16",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (input.query === "usb")
|
|
||||||
assert.ok(report.records.some((row) => row.abbreviation === "usb"));
|
|
||||||
if (input.query === "rea_no_such_field")
|
|
||||||
assert.equal(report.output_window.matching, 0);
|
|
||||||
const flags = Object.entries(input).flatMap(([key, value]) =>
|
|
||||||
value === null ? ["--all"] : [`--${key}`, String(value)],
|
|
||||||
);
|
|
||||||
const cli = JSON.parse(
|
|
||||||
(
|
|
||||||
await execute(
|
|
||||||
process.execPath,
|
|
||||||
[entrypoint, "inspect-packet-fields", ...flags, "--format", "json"],
|
|
||||||
{ env: environment, timeout: 60000, maxBuffer: 16 * 1024 * 1024 },
|
|
||||||
)
|
|
||||||
).stdout,
|
|
||||||
);
|
|
||||||
assert.deepEqual(cli.normalized_result, report);
|
|
||||||
cases++;
|
|
||||||
}
|
|
||||||
await client.close();
|
await client.close();
|
||||||
assert.deepEqual((await readdir(root.path)).sort(), [
|
assert.deepEqual((await readdir(root.path)).sort(), [
|
||||||
"bluetooth.pcap",
|
"bluetooth.pcap",
|
||||||
@@ -473,9 +329,6 @@ console.log(
|
|||||||
{
|
{
|
||||||
status: "passed",
|
status: "passed",
|
||||||
cases,
|
cases,
|
||||||
discovery_measurements: discoveryMeasurements,
|
|
||||||
measurement_scope:
|
|
||||||
"Warm MCP server, fresh TShark processes; tokenx estimates include one advertised tool/request/response, not billed usage. Model-driven selection, CPU and peak process-family memory are unmeasured; no cache/speedup claim.",
|
|
||||||
host: `${process.platform}/${process.arch}`,
|
host: `${process.platform}/${process.arch}`,
|
||||||
scope:
|
scope:
|
||||||
"real TShark CLI/MCP; synthetic Ethernet/IPv4/UDP/DNS and Bluetooth HCI PCAP; no hardware acquisition",
|
"real TShark CLI/MCP; synthetic Ethernet/IPv4/UDP/DNS and Bluetooth HCI PCAP; no hardware acquisition",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { estimateTokenCount } from "tokenx";
|
|
||||||
import { execFile } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
import { readFile, writeFile, readdir } from "node:fs/promises";
|
import { readFile, writeFile, readdir } from "node:fs/promises";
|
||||||
@@ -69,20 +68,6 @@ for (const byte of Buffer.from("REA")) {
|
|||||||
lines.push(`#${tick + 1000}`, "1!");
|
lines.push(`#${tick + 1000}`, "1!");
|
||||||
const source = lines.join("\n") + "\n";
|
const source = lines.join("\n") + "\n";
|
||||||
let cases = 0;
|
let cases = 0;
|
||||||
const discoveryMeasurements = [];
|
|
||||||
const inheritedAddressSpace = (await readFile("/proc/self/limits", "utf8"))
|
|
||||||
.split("\n")
|
|
||||||
.find((line) => line.startsWith("Max address space "))
|
|
||||||
?.trim()
|
|
||||||
.match(/^Max address space\s+(\S+)\s+(\S+)\s+bytes$/u);
|
|
||||||
assert.ok(inheritedAddressSpace);
|
|
||||||
const expectedAddressSpace = Math.min(
|
|
||||||
1073741824,
|
|
||||||
...inheritedAddressSpace
|
|
||||||
.slice(1)
|
|
||||||
.map((value) => (value === "unlimited" ? Infinity : Number(value))),
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await writeFile(path, source);
|
await writeFile(path, source);
|
||||||
await client.connect(transport);
|
await client.connect(transport);
|
||||||
@@ -119,16 +104,14 @@ try {
|
|||||||
createHash("sha256").update(source).digest("hex"),
|
createHash("sha256").update(source).digest("hex"),
|
||||||
);
|
);
|
||||||
assert.equal(report.hardware_acquisition, "not-performed");
|
assert.equal(report.hardware_acquisition, "not-performed");
|
||||||
assert.equal(report.limits.address_space_bytes, expectedAddressSpace);
|
assert.equal(report.limits.address_space_bytes, 1073741824);
|
||||||
assert.equal(report.tool.configured_path, process.env.REA_SIGROK_COMMAND);
|
assert.equal(report.tool.configured_path, process.env.REA_SIGROK_COMMAND);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
report.resource_limiter.configured_path,
|
report.resource_limiter.configured_path,
|
||||||
process.env.REA_SIGROK_PRLIMIT_COMMAND ?? "/usr/bin/prlimit",
|
process.env.REA_SIGROK_PRLIMIT_COMMAND ?? "/usr/bin/prlimit",
|
||||||
);
|
);
|
||||||
assert.ok(
|
assert.ok(
|
||||||
report.resource_limiter.arguments.includes(
|
report.resource_limiter.arguments.includes("--as=1073741824:1073741824"),
|
||||||
`--as=${expectedAddressSpace}:${expectedAddressSpace}`,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
assert.equal(report.diagnostics, "");
|
assert.equal(report.diagnostics, "");
|
||||||
const flags = Object.entries(input)
|
const flags = Object.entries(input)
|
||||||
@@ -262,88 +245,6 @@ try {
|
|||||||
});
|
});
|
||||||
assert.equal(invalid.isError, true);
|
assert.equal(invalid.isError, true);
|
||||||
cases++;
|
cases++;
|
||||||
const discoveryTool = (await client.listTools()).tools.find(
|
|
||||||
({ name }) => name === "inspect_signal_decoders",
|
|
||||||
);
|
|
||||||
assert.ok(discoveryTool?.outputSchema);
|
|
||||||
assert.ok(ajv.validateSchema(discoveryTool.inputSchema));
|
|
||||||
assert.ok(ajv.validateSchema(discoveryTool.outputSchema));
|
|
||||||
const nativeHelp = (
|
|
||||||
await execute(
|
|
||||||
process.env.REA_SIGROK_COMMAND,
|
|
||||||
["--dont-scan", "--protocol-decoders=uart", "--show"],
|
|
||||||
{ env: environment, timeout: 30000, maxBuffer: 4 * 1024 * 1024 },
|
|
||||||
)
|
|
||||||
).stdout.split(/\r?\n/);
|
|
||||||
if (nativeHelp.at(-1) === "") nativeHelp.pop();
|
|
||||||
for (const input of [
|
|
||||||
{ query: "uart" },
|
|
||||||
{ limit: 1 },
|
|
||||||
{ offset: 1, limit: 2 },
|
|
||||||
{ decoder: "uart", query: "BaUd" },
|
|
||||||
{ decoder: "uart", offset: 50, limit: null },
|
|
||||||
{ query: "rea_no_such_decoder" },
|
|
||||||
]) {
|
|
||||||
const started = performance.now();
|
|
||||||
const response = await client.callTool({
|
|
||||||
name: discoveryTool.name,
|
|
||||||
arguments: input,
|
|
||||||
});
|
|
||||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
|
||||||
assert.ok(
|
|
||||||
ajv.validate(discoveryTool.outputSchema, response.structuredContent),
|
|
||||||
JSON.stringify(ajv.errors),
|
|
||||||
);
|
|
||||||
const evidence = parseEvidence(response.structuredContent);
|
|
||||||
const report = evidence.normalized_result;
|
|
||||||
discoveryMeasurements.push({
|
|
||||||
input,
|
|
||||||
elapsed_ms: +(performance.now() - started).toFixed(2),
|
|
||||||
response_bytes: Buffer.byteLength(JSON.stringify(response)),
|
|
||||||
estimated_tokens_one_tool_request_response: estimateTokenCount(
|
|
||||||
JSON.stringify(discoveryTool) +
|
|
||||||
JSON.stringify(input) +
|
|
||||||
JSON.stringify(response),
|
|
||||||
),
|
|
||||||
});
|
|
||||||
if (input.decoder) {
|
|
||||||
const matched = nativeHelp
|
|
||||||
.map((text, i) => ({ line_number: i + 1, text }))
|
|
||||||
.filter(({ text }) =>
|
|
||||||
text.toLowerCase().includes((input.query ?? "").toLowerCase()),
|
|
||||||
);
|
|
||||||
assert.deepEqual(
|
|
||||||
report.help_lines,
|
|
||||||
matched.slice(
|
|
||||||
input.offset ?? 0,
|
|
||||||
input.limit === null
|
|
||||||
? undefined
|
|
||||||
: (input.offset ?? 0) + (input.limit ?? 50),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (input.query === "uart")
|
|
||||||
assert.ok(report.decoders.some(({ id }) => id === "uart"));
|
|
||||||
const flags = Object.entries(input).flatMap(([key, value]) =>
|
|
||||||
value === null ? ["--all"] : [`--${key}`, String(value)],
|
|
||||||
);
|
|
||||||
const cli = JSON.parse(
|
|
||||||
(
|
|
||||||
await execute(
|
|
||||||
process.execPath,
|
|
||||||
[entrypoint, "inspect-signal-decoders", ...flags, "--format", "json"],
|
|
||||||
{ env: environment, timeout: 60000, maxBuffer: 8 * 1024 * 1024 },
|
|
||||||
)
|
|
||||||
).stdout,
|
|
||||||
);
|
|
||||||
assert.deepEqual(cli.normalized_result, report);
|
|
||||||
cases++;
|
|
||||||
}
|
|
||||||
const unavailable = await client.callTool({
|
|
||||||
name: discoveryTool.name,
|
|
||||||
arguments: { decoder: "rea_no_such_decoder" },
|
|
||||||
});
|
|
||||||
assert.equal(unavailable.isError, true);
|
|
||||||
cases++;
|
|
||||||
await client.close();
|
await client.close();
|
||||||
assert.deepEqual((await readdir(root.path)).sort(), [
|
assert.deepEqual((await readdir(root.path)).sort(), [
|
||||||
"paged.vcd",
|
"paged.vcd",
|
||||||
@@ -359,9 +260,6 @@ console.log(
|
|||||||
{
|
{
|
||||||
status: "passed",
|
status: "passed",
|
||||||
cases,
|
cases,
|
||||||
discovery_measurements: discoveryMeasurements,
|
|
||||||
measurement_scope:
|
|
||||||
"Warm MCP server, fresh sigrok processes; tokenx estimates include one advertised tool/request/response, not billed model usage. No model-driven selection benchmark, CPU or peak process-family memory measurement; no cache or speedup claim.",
|
|
||||||
host: `${process.platform}/${process.arch}`,
|
host: `${process.platform}/${process.arch}`,
|
||||||
scope:
|
scope:
|
||||||
"real sigrok UART VCD through compiled CLI/MCP; no physical acquisition",
|
"real sigrok UART VCD through compiled CLI/MCP; no physical acquisition",
|
||||||
|
|||||||
@@ -662,42 +662,6 @@ setInterval(()=>{},1000);\n`,
|
|||||||
unicodeNamesPreserved: true,
|
unicodeNamesPreserved: true,
|
||||||
});
|
});
|
||||||
report.processes.windowsEnvironmentSemantics = true;
|
report.processes.windowsEnvironmentSemantics = true;
|
||||||
// Observed through this process's own id: a separate probe process would
|
|
||||||
// get its own processor group, so it cannot stand in for the process that
|
|
||||||
// spawns the child.
|
|
||||||
const callerAffinity = JSON.parse(
|
|
||||||
execFileSync(boundaryFixture, ["affinity", String(process.pid)], {
|
|
||||||
encoding: "utf8",
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const affinityChild = native.call("process_spawn", [
|
|
||||||
boundaryFixture,
|
|
||||||
`${quote(boundaryFixture)} affinity`,
|
|
||||||
workspace,
|
|
||||||
environment,
|
|
||||||
]);
|
|
||||||
const observedAffinity = await wait(affinityChild);
|
|
||||||
native.call("process_close", [affinityChild.handle]);
|
|
||||||
assert.equal(observedAffinity.exitCode, 0);
|
|
||||||
const childAffinity = JSON.parse(observedAffinity.output);
|
|
||||||
// Masks cross as hexadecimal strings because a mask can exceed the
|
|
||||||
// safe-integer range. Sharing one processor group makes the caller's mask
|
|
||||||
// applicable, so it must be inherited exactly. Windows placing the child in
|
|
||||||
// another group is only permitted when the caller asked for no bound of its
|
|
||||||
// own, which its group's whole active set establishes; a narrower mask has
|
|
||||||
// to fail the spawn rather than widen to that group's default.
|
|
||||||
const sharedGroup =
|
|
||||||
callerAffinity.singleProcessorGroup &&
|
|
||||||
childAffinity.singleProcessorGroup &&
|
|
||||||
callerAffinity.processorGroup === childAffinity.processorGroup;
|
|
||||||
if (sharedGroup)
|
|
||||||
assert.equal(childAffinity.affinityMask, callerAffinity.affinityMask);
|
|
||||||
else assert.equal(callerAffinity.affinityMask, callerAffinity.systemMask);
|
|
||||||
report.processes.callerAffinityBoundsOwnedProcessOrRefusesToWiden = true;
|
|
||||||
report.callerAffinity = {
|
|
||||||
...callerAffinity,
|
|
||||||
sharedGroupWithChild: sharedGroup,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
const ownerFixture = join(workspace, "owner.mjs");
|
const ownerFixture = join(workspace, "owner.mjs");
|
||||||
const ownerPidFile = join(workspace, "crash-child.pid");
|
const ownerPidFile = join(workspace, "crash-child.pid");
|
||||||
|
|||||||
@@ -84,24 +84,6 @@ describe("parseAdbDevicesOutput", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("accepts complete multiword states and rejects state prefixes", () => {
|
|
||||||
const output = [
|
|
||||||
"serial-no-permission no permissions usb:1-1",
|
|
||||||
"serial-bad-device deviceXYZ ",
|
|
||||||
"serial-bad-offline offline-ish",
|
|
||||||
"serial-bad-auth unauthorizedXYZ",
|
|
||||||
].join("\n");
|
|
||||||
const { devices, unparsedLines } = parseAdbDevicesOutput(output);
|
|
||||||
expect(devices.map(({ serial, state }) => [serial, state])).toEqual([
|
|
||||||
["serial-no-permission", "no permissions"],
|
|
||||||
]);
|
|
||||||
expect(unparsedLines).toEqual([
|
|
||||||
"serial-bad-device deviceXYZ ",
|
|
||||||
"serial-bad-offline offline-ish",
|
|
||||||
"serial-bad-auth unauthorizedXYZ",
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns unrecognized lines instead of dropping them", () => {
|
it("returns unrecognized lines instead of dropping them", () => {
|
||||||
const output = [
|
const output = [
|
||||||
"List of devices attached",
|
"List of devices attached",
|
||||||
|
|||||||
+25
-14
@@ -10,15 +10,11 @@ import {
|
|||||||
adbHostFileName,
|
adbHostFileName,
|
||||||
type AdbHostFileNameReason,
|
type AdbHostFileNameReason,
|
||||||
} from "./AdbHostFileName.js";
|
} from "./AdbHostFileName.js";
|
||||||
import {
|
|
||||||
ADB_DEVICE_STATES,
|
|
||||||
type AdbDeviceState,
|
|
||||||
} from "../domain/adb/adbDeviceAnalysis.js";
|
|
||||||
|
|
||||||
/** One device exactly as `adb devices -l` reports it. */
|
/** One device exactly as `adb devices -l` reports it. */
|
||||||
export interface AdbDeviceEntry {
|
export interface AdbDeviceEntry {
|
||||||
readonly serial: string;
|
readonly serial: string;
|
||||||
readonly state: AdbDeviceState;
|
readonly state: string;
|
||||||
readonly transport: "usb" | "tcp" | "unknown";
|
readonly transport: "usb" | "tcp" | "unknown";
|
||||||
readonly product: string | null;
|
readonly product: string | null;
|
||||||
readonly model: string | null;
|
readonly model: string | null;
|
||||||
@@ -28,6 +24,25 @@ export interface AdbDeviceEntry {
|
|||||||
readonly kind_basis: "emulator_serial_prefix" | "usb_transport" | "none";
|
readonly kind_basis: "emulator_serial_prefix" | "usb_transport" | "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device states adb prints after the serial, longest first so two-word
|
||||||
|
* states match before their single-word prefixes. A line whose remainder
|
||||||
|
* starts with none of them is not a device line.
|
||||||
|
*/
|
||||||
|
const DEVICE_STATES = [
|
||||||
|
"no permissions",
|
||||||
|
"unauthorized",
|
||||||
|
"authorizing",
|
||||||
|
"offline",
|
||||||
|
"recovery",
|
||||||
|
"sideload",
|
||||||
|
"connecting",
|
||||||
|
"bootloader",
|
||||||
|
"device",
|
||||||
|
"unknown",
|
||||||
|
"host",
|
||||||
|
] as const;
|
||||||
|
|
||||||
const DEVICE_LINE = /^(\S+)\s+(.*)$/u;
|
const DEVICE_LINE = /^(\S+)\s+(.*)$/u;
|
||||||
|
|
||||||
const metadataValue = (remainder: string, key: string): string | null => {
|
const metadataValue = (remainder: string, key: string): string | null => {
|
||||||
@@ -58,15 +73,11 @@ export const parseAdbDevicesOutput = (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const match = DEVICE_LINE.exec(line);
|
const match = DEVICE_LINE.exec(line);
|
||||||
const state = ADB_DEVICE_STATES.find((candidate) => {
|
const state = DEVICE_STATES.find((candidate) =>
|
||||||
const remainder = match?.[2];
|
match?.[2]?.startsWith(candidate),
|
||||||
if (remainder === undefined || !remainder.startsWith(candidate))
|
);
|
||||||
return false;
|
|
||||||
const next = remainder[candidate.length];
|
|
||||||
return next === undefined || /\s/u.test(next);
|
|
||||||
});
|
|
||||||
if (match === null || state === undefined) {
|
if (match === null || state === undefined) {
|
||||||
if (rawLine.trim() !== "") unparsedLines.push(rawLine);
|
if (line.trim() !== "") unparsedLines.push(line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const serial = match[1]!;
|
const serial = match[1]!;
|
||||||
@@ -181,7 +192,7 @@ export const parsePackageListOutput = (
|
|||||||
if (line === "") continue;
|
if (line === "") continue;
|
||||||
const match = PACKAGE_LINE.exec(line);
|
const match = PACKAGE_LINE.exec(line);
|
||||||
if (match === null) {
|
if (match === null) {
|
||||||
unparsedLines.push(rawLine);
|
unparsedLines.push(line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
packages.push({
|
packages.push({
|
||||||
|
|||||||
@@ -121,52 +121,6 @@ fi`,
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("refuses device listings with an invalid state token", async () => {
|
|
||||||
const malformedLine = "serial deviceXYZ ";
|
|
||||||
const { binary } = await writeAdbStub(
|
|
||||||
() => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fi
|
|
||||||
if [ "$1" = "devices" ]; then
|
|
||||||
printf 'List of devices attached\\n${malformedLine}\\n'
|
|
||||||
exit 0
|
|
||||||
fi`,
|
|
||||||
);
|
|
||||||
const result = await providerOver(binary).execute({
|
|
||||||
operation: "list_adb_devices",
|
|
||||||
input: {},
|
|
||||||
});
|
|
||||||
expect(result.ok).toBe(false);
|
|
||||||
if (result.ok) return;
|
|
||||||
expect(result.error._tag).toBe("AnalysisProtocolError");
|
|
||||||
expect(result.error.message).toContain(malformedLine);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("lists rescue and detached transports alongside online devices", async () => {
|
|
||||||
const { binary } = await writeAdbStub(
|
|
||||||
() => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fi
|
|
||||||
if [ "$1" = "devices" ]; then
|
|
||||||
printf 'List of devices attached\\n'
|
|
||||||
printf 'serial-online device transport_id:1\\n'
|
|
||||||
printf 'serial-rescue rescue transport_id:2\\n'
|
|
||||||
printf 'serial-detached detached transport_id:3\\n'
|
|
||||||
exit 0
|
|
||||||
fi`,
|
|
||||||
);
|
|
||||||
const result = await evidenceResult(providerOver(binary), {
|
|
||||||
operation: "list_adb_devices",
|
|
||||||
input: {},
|
|
||||||
});
|
|
||||||
expect(result.devices).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({ serial: "serial-online", state: "device" }),
|
|
||||||
expect.objectContaining({ serial: "serial-rescue", state: "rescue" }),
|
|
||||||
expect.objectContaining({
|
|
||||||
serial: "serial-detached",
|
|
||||||
state: "detached",
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("inspects a device through the getprop whitelist", async () => {
|
it("inspects a device through the getprop whitelist", async () => {
|
||||||
const { binary } = await writeAdbStub(
|
const { binary } = await writeAdbStub(
|
||||||
() => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fi
|
() => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fi
|
||||||
@@ -626,34 +580,6 @@ it("projects package details from dumpsys package output", async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Android 10 and 11 append ": restricted=true" to hard- and soft-restricted
|
|
||||||
// entries of the requested-permissions list (Settings.dumpPackageLPr).
|
|
||||||
it("counts requested permissions that the device marks as restricted", async () => {
|
|
||||||
const { binary } = await writeAdbStub(
|
|
||||||
shellStub({
|
|
||||||
"dumpsys:package": `Packages:
|
|
||||||
Package [com.example] (abcdef):
|
|
||||||
userId=10234
|
|
||||||
versionName=1.2.3
|
|
||||||
requested permissions:
|
|
||||||
android.permission.INTERNET
|
|
||||||
android.permission.WRITE_EXTERNAL_STORAGE: restricted=true
|
|
||||||
android.permission.CAMERA
|
|
||||||
install permissions:
|
|
||||||
android.permission.INTERNET: granted=true
|
|
||||||
`,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const result = await evidenceResult(providerOver(binary), {
|
|
||||||
operation: "inspect_adb_package",
|
|
||||||
input: { serial: "emulator-5554", package: "com.example" },
|
|
||||||
});
|
|
||||||
expect(result).toMatchObject({
|
|
||||||
requested_permissions_count: 3,
|
|
||||||
coverage: "complete",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("reports an uninstalled package from dumpsys refusal output", async () => {
|
it("reports an uninstalled package from dumpsys refusal output", async () => {
|
||||||
const { binary } = await writeAdbStub(
|
const { binary } = await writeAdbStub(
|
||||||
shellStub({ "dumpsys:package": "Unable to find package: com.absent\n" }),
|
shellStub({ "dumpsys:package": "Unable to find package: com.absent\n" }),
|
||||||
|
|||||||
@@ -236,11 +236,7 @@ export const parseDumpsysPackageOutput = (
|
|||||||
inPermissions = true;
|
inPermissions = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Android 10 and 11 mark restricted entries as "NAME: restricted=true".
|
if (inPermissions && /^\s{2,}[A-Za-z0-9._]+$/.test(line)) {
|
||||||
if (
|
|
||||||
inPermissions &&
|
|
||||||
/^\s{2,}[A-Za-z0-9._]+(?:: restricted=true)?$/u.test(line)
|
|
||||||
) {
|
|
||||||
permissions += 1;
|
permissions += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,11 +199,9 @@ export class JadxMcpTransport implements Transport {
|
|||||||
throw new Error(`JADX MCP frame exceeds ${MAX_FRAME_BYTES} bytes`);
|
throw new Error(`JADX MCP frame exceeds ${MAX_FRAME_BYTES} bytes`);
|
||||||
this.#appendFrame(fragment, frameBytes);
|
this.#appendFrame(fragment, frameBytes);
|
||||||
if (newline === -1) return;
|
if (newline === -1) return;
|
||||||
const line = new TextDecoder("utf-8", {
|
const line = this.#frameBuffer
|
||||||
fatal: true,
|
.subarray(0, this.#frameLength)
|
||||||
// Preserve a leading BOM so the JSON-RPC parser can reject it.
|
.toString("utf8");
|
||||||
ignoreBOM: true,
|
|
||||||
}).decode(this.#frameBuffer.subarray(0, this.#frameLength));
|
|
||||||
this.#frameBuffer = Buffer.alloc(0);
|
this.#frameBuffer = Buffer.alloc(0);
|
||||||
this.#frameLength = 0;
|
this.#frameLength = 0;
|
||||||
this.onmessage?.(deserializeMessage(line));
|
this.onmessage?.(deserializeMessage(line));
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ const workflowAvailabilityFor = ({
|
|||||||
remediation:
|
remediation:
|
||||||
"On Linux x64, set absolute REA_PWNTOOLS_PYTHON to caller-supplied Python with pwntools 4.15.0. No active binary target is required.",
|
"On Linux x64, set absolute REA_PWNTOOLS_PYTHON to caller-supplied Python with pwntools 4.15.0. No active binary target is required.",
|
||||||
};
|
};
|
||||||
if (name === "inspect_packet_capture" || name === "inspect_packet_fields")
|
if (name === "inspect_packet_capture")
|
||||||
return policy.packetCaptureEnabled === true
|
return policy.packetCaptureEnabled === true
|
||||||
? { reason: "available", remediation: null }
|
? { reason: "available", remediation: null }
|
||||||
: {
|
: {
|
||||||
@@ -405,7 +405,7 @@ const workflowAvailabilityFor = ({
|
|||||||
remediation:
|
remediation:
|
||||||
"On Linux, supply TShark 4.x via absolute REA_TSHARK_COMMAND and util-linux prlimit (REA_TSHARK_PRLIMIT_COMMAND, default /usr/bin/prlimit). No active binary target or hardware is required; the tool is checked at execution.",
|
"On Linux, supply TShark 4.x via absolute REA_TSHARK_COMMAND and util-linux prlimit (REA_TSHARK_PRLIMIT_COMMAND, default /usr/bin/prlimit). No active binary target or hardware is required; the tool is checked at execution.",
|
||||||
};
|
};
|
||||||
if (name === "decode_signal_recording" || name === "inspect_signal_decoders")
|
if (name === "decode_signal_recording")
|
||||||
return policy.signalRecordingEnabled === true
|
return policy.signalRecordingEnabled === true
|
||||||
? { reason: "available", remediation: null }
|
? { reason: "available", remediation: null }
|
||||||
: {
|
: {
|
||||||
|
|||||||
@@ -78,9 +78,7 @@ export const readJsonObjectFile = (
|
|||||||
value === null ||
|
value === null ||
|
||||||
Array.isArray(value)
|
Array.isArray(value)
|
||||||
)
|
)
|
||||||
return err(
|
throw new TypeError("JSON document root must be an object");
|
||||||
invalidJson(operation, "JSON document root must be an object"),
|
|
||||||
);
|
|
||||||
for (const members of scans)
|
for (const members of scans)
|
||||||
for (const [key, member] of members) {
|
for (const [key, member] of members) {
|
||||||
if (!Object.hasOwn(value, key)) continue;
|
if (!Object.hasOwn(value, key)) continue;
|
||||||
@@ -179,9 +177,7 @@ export const readJsonObjectFile = (
|
|||||||
signal === undefined ? {} : { signal },
|
signal === undefined ? {} : { signal },
|
||||||
);
|
);
|
||||||
if (!rootObject)
|
if (!rootObject)
|
||||||
return err(
|
throw new TypeError("JSON document root must be an object");
|
||||||
invalidJson(operation, "JSON document root must be an object"),
|
|
||||||
);
|
|
||||||
const digest = hash.digest("hex");
|
const digest = hash.digest("hex");
|
||||||
if (previousDigest !== undefined && digest !== previousDigest)
|
if (previousDigest !== undefined && digest !== previousDigest)
|
||||||
throw new RegularFileChangedError(path);
|
throw new RegularFileChangedError(path);
|
||||||
|
|||||||
@@ -2,16 +2,12 @@ import { createHash } from "node:crypto";
|
|||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import {
|
import { installMacHopper, type MacHopperInstallHost } from "./MacHopper.js";
|
||||||
installMacHopper,
|
|
||||||
type MacHopperBundleVerification,
|
|
||||||
type MacHopperInstallHost,
|
|
||||||
} from "./MacHopper.js";
|
|
||||||
|
|
||||||
class FakeMacHopperHost implements MacHopperInstallHost {
|
class FakeMacHopperHost implements MacHopperInstallHost {
|
||||||
readonly archive = new TextEncoder().encode("hopper-dmg");
|
readonly archive = new TextEncoder().encode("hopper-dmg");
|
||||||
archiveOk = true;
|
archiveOk = true;
|
||||||
verification: MacHopperBundleVerification = "verified";
|
valid = true;
|
||||||
existing = false;
|
existing = false;
|
||||||
mountSucceeds = true;
|
mountSucceeds = true;
|
||||||
copySucceeds = true;
|
copySucceeds = true;
|
||||||
@@ -19,7 +15,6 @@ class FakeMacHopperHost implements MacHopperInstallHost {
|
|||||||
badHash = false;
|
badHash = false;
|
||||||
unmounts = 0;
|
unmounts = 0;
|
||||||
cleanups = 0;
|
cleanups = 0;
|
||||||
installs = 0;
|
|
||||||
opens = 0;
|
opens = 0;
|
||||||
replaces = false;
|
replaces = false;
|
||||||
|
|
||||||
@@ -52,7 +47,7 @@ class FakeMacHopperHost implements MacHopperInstallHost {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
appBundle = () => Promise.resolve("/mounted/Hopper Disassembler.app");
|
appBundle = () => Promise.resolve("/mounted/Hopper Disassembler.app");
|
||||||
validBundle = () => Promise.resolve(this.verification);
|
validBundle = () => Promise.resolve(this.valid);
|
||||||
destinationExists = () => Promise.resolve(this.existing);
|
destinationExists = () => Promise.resolve(this.existing);
|
||||||
installBundle = (
|
installBundle = (
|
||||||
_source: string,
|
_source: string,
|
||||||
@@ -60,7 +55,6 @@ class FakeMacHopperHost implements MacHopperInstallHost {
|
|||||||
_stage: string,
|
_stage: string,
|
||||||
replaceExisting: boolean,
|
replaceExisting: boolean,
|
||||||
) => {
|
) => {
|
||||||
this.installs += 1;
|
|
||||||
this.replaces = replaceExisting;
|
this.replaces = replaceExisting;
|
||||||
return Promise.resolve(this.copySucceeds);
|
return Promise.resolve(this.copySucceeds);
|
||||||
};
|
};
|
||||||
@@ -121,7 +115,7 @@ describe("macOS Hopper installation", () => {
|
|||||||
|
|
||||||
it("cleans and detaches after bundle validation fails", async () => {
|
it("cleans and detaches after bundle validation fails", async () => {
|
||||||
const host = new FakeMacHopperHost();
|
const host = new FakeMacHopperHost();
|
||||||
host.verification = "invalid_signature";
|
host.valid = false;
|
||||||
await expect(installMacHopper({}, host)).resolves.toEqual({
|
await expect(installMacHopper({}, host)).resolves.toEqual({
|
||||||
status: "failed",
|
status: "failed",
|
||||||
reason: "bundle",
|
reason: "bundle",
|
||||||
@@ -129,17 +123,4 @@ describe("macOS Hopper installation", () => {
|
|||||||
expect(host.unmounts).toBe(1);
|
expect(host.unmounts).toBe(1);
|
||||||
expect(host.cleanups).toBe(1);
|
expect(host.cleanups).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports a publisher mismatch without copying or launching the bundle", async () => {
|
|
||||||
const host = new FakeMacHopperHost();
|
|
||||||
host.verification = "unverified_publisher";
|
|
||||||
await expect(installMacHopper({}, host)).resolves.toEqual({
|
|
||||||
status: "failed",
|
|
||||||
reason: "publisher_verification_failed",
|
|
||||||
});
|
|
||||||
expect(host.installs).toBe(0);
|
|
||||||
expect(host.opens).toBe(0);
|
|
||||||
expect(host.unmounts).toBe(1);
|
|
||||||
expect(host.cleanups).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,35 +24,7 @@ const execFileAsync = promisify(execFile);
|
|||||||
const RELEASES_URL =
|
const RELEASES_URL =
|
||||||
"https://www.hopperapp.com/include/files-api.php?request=releases&public=true";
|
"https://www.hopperapp.com/include/files-api.php?request=releases&public=true";
|
||||||
const DOWNLOAD_PREFIX = "https://www.hopperapp.com:443/downloader/public/";
|
const DOWNLOAD_PREFIX = "https://www.hopperapp.com:443/downloader/public/";
|
||||||
|
const BUNDLE_IDENTIFIER = "com.cryptic-apps.hopper-web-4";
|
||||||
/**
|
|
||||||
* Apple publisher identity pinned for the official Hopper macOS bundle. The
|
|
||||||
* team identifier was captured from `Hopper-6.6.0-demo.dmg` at
|
|
||||||
* `https://www.hopperapp.com:443/downloader/public/Hopper-6.6.0-demo.dmg`
|
|
||||||
* (34846271 bytes, SHA-1 0be530f038249742590992199c7b042ea20ca955) with
|
|
||||||
* `codesign -dvvv`, which reported
|
|
||||||
* `Authority=Developer ID Application: Cryptic Apps (2AMA2753NF)`.
|
|
||||||
*/
|
|
||||||
export const HOPPER_PUBLISHER = Object.freeze({
|
|
||||||
bundleIdentifier: "com.cryptic-apps.hopper-web-4",
|
|
||||||
teamIdentifier: "2AMA2753NF",
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Code requirement enforcing the bundle identifier and signing team together.
|
|
||||||
* The identifier is read from the sealed CodeDirectory, so it cannot be changed
|
|
||||||
* by editing `Info.plist` the way the previous string comparison could.
|
|
||||||
*/
|
|
||||||
const HOPPER_PUBLISHER_REQUIREMENT =
|
|
||||||
`= identifier "${HOPPER_PUBLISHER.bundleIdentifier}"` +
|
|
||||||
` and anchor apple generic` +
|
|
||||||
` and certificate leaf[subject.OU] = "${HOPPER_PUBLISHER.teamIdentifier}"`;
|
|
||||||
|
|
||||||
/** Outcome of reading a mounted bundle's signature and publisher identity. */
|
|
||||||
export type MacHopperBundleVerification =
|
|
||||||
| "verified"
|
|
||||||
| "invalid_signature"
|
|
||||||
| "unverified_publisher";
|
|
||||||
|
|
||||||
/** Stable network and command effects disclosed before macOS Hopper setup. */
|
/** Stable network and command effects disclosed before macOS Hopper setup. */
|
||||||
export const macHopperInstallDisclosure = {
|
export const macHopperInstallDisclosure = {
|
||||||
@@ -60,7 +32,6 @@ export const macHopperInstallDisclosure = {
|
|||||||
commands: [
|
commands: [
|
||||||
"hdiutil attach -readonly -nobrowse -mountpoint <private-mount> <verified-hopper.dmg>",
|
"hdiutil attach -readonly -nobrowse -mountpoint <private-mount> <verified-hopper.dmg>",
|
||||||
"codesign --verify --deep --strict <mounted-hopper.app>",
|
"codesign --verify --deep --strict <mounted-hopper.app>",
|
||||||
`codesign --verify --strict '-R${HOPPER_PUBLISHER_REQUIREMENT}' <mounted-hopper.app>`,
|
|
||||||
"ditto <mounted-hopper.app> <user-Applications-stage>",
|
"ditto <mounted-hopper.app> <user-Applications-stage>",
|
||||||
"open <installed-hopper.app>",
|
"open <installed-hopper.app>",
|
||||||
] as const,
|
] as const,
|
||||||
@@ -81,7 +52,6 @@ export type MacHopperInstallResult =
|
|||||||
| "integrity"
|
| "integrity"
|
||||||
| "mount"
|
| "mount"
|
||||||
| "bundle"
|
| "bundle"
|
||||||
| "publisher_verification_failed"
|
|
||||||
| "destination_exists"
|
| "destination_exists"
|
||||||
| "copy"
|
| "copy"
|
||||||
| "launcher_missing";
|
| "launcher_missing";
|
||||||
@@ -99,7 +69,7 @@ export interface MacHopperInstallHost {
|
|||||||
mount(packagePath: string, mountPath: string): Promise<boolean>;
|
mount(packagePath: string, mountPath: string): Promise<boolean>;
|
||||||
unmount(mountPath: string): Promise<void>;
|
unmount(mountPath: string): Promise<void>;
|
||||||
appBundle(mountPath: string): Promise<string | undefined>;
|
appBundle(mountPath: string): Promise<string | undefined>;
|
||||||
validBundle(appPath: string): Promise<MacHopperBundleVerification>;
|
validBundle(appPath: string): Promise<boolean>;
|
||||||
destinationExists(path: string): Promise<boolean>;
|
destinationExists(path: string): Promise<boolean>;
|
||||||
installBundle(
|
installBundle(
|
||||||
source: string,
|
source: string,
|
||||||
@@ -154,12 +124,8 @@ export const installMacHopper = async (
|
|||||||
return { status: "failed", reason: "mount" };
|
return { status: "failed", reason: "mount" };
|
||||||
mounted = true;
|
mounted = true;
|
||||||
const source = await host.appBundle(mountPath);
|
const source = await host.appBundle(mountPath);
|
||||||
if (source === undefined) return { status: "failed", reason: "bundle" };
|
if (source === undefined || !(await host.validBundle(source)))
|
||||||
const verification = await host.validBundle(source);
|
|
||||||
if (verification === "invalid_signature")
|
|
||||||
return { status: "failed", reason: "bundle" };
|
return { status: "failed", reason: "bundle" };
|
||||||
if (verification === "unverified_publisher")
|
|
||||||
return { status: "failed", reason: "publisher_verification_failed" };
|
|
||||||
const stage = `${destination}.rea-stage`;
|
const stage = `${destination}.rea-stage`;
|
||||||
if (
|
if (
|
||||||
!(await host.installBundle(
|
!(await host.installBundle(
|
||||||
@@ -256,21 +222,25 @@ export const systemMacHopperInstallHost = (
|
|||||||
environment,
|
environment,
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
return "invalid_signature";
|
return false;
|
||||||
if (
|
try {
|
||||||
!(await commandSucceeds(
|
const identifier = (
|
||||||
"codesign",
|
await execFileAsync(
|
||||||
|
"/usr/libexec/PlistBuddy",
|
||||||
[
|
[
|
||||||
"--verify",
|
"-c",
|
||||||
"--strict",
|
"Print :CFBundleIdentifier",
|
||||||
`-R${HOPPER_PUBLISHER_REQUIREMENT}`,
|
join(appPath, "Contents/Info.plist"),
|
||||||
appPath,
|
|
||||||
],
|
],
|
||||||
environment,
|
{ env: environment },
|
||||||
))
|
|
||||||
)
|
)
|
||||||
return "unverified_publisher";
|
).stdout.trim();
|
||||||
return "verified";
|
return identifier === BUNDLE_IDENTIFIER;
|
||||||
|
} catch (cause: unknown) {
|
||||||
|
// best-effort cleanup: optional bundle probing; unreadable means invalid.
|
||||||
|
void cause;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async destinationExists(path) {
|
async destinationExists(path) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const createProgressReporter = (
|
|||||||
} = {},
|
} = {},
|
||||||
): ProgressReporter => {
|
): ProgressReporter => {
|
||||||
const minimumIntervalMs = options.minimumIntervalMs ?? 100;
|
const minimumIntervalMs = options.minimumIntervalMs ?? 100;
|
||||||
const now = options.now ?? (() => performance.now());
|
const now = options.now ?? Date.now;
|
||||||
let lastCompleted = -1;
|
let lastCompleted = -1;
|
||||||
let lastSentAt = Number.NEGATIVE_INFINITY;
|
let lastSentAt = Number.NEGATIVE_INFINITY;
|
||||||
let sequence = 0;
|
let sequence = 0;
|
||||||
|
|||||||
@@ -12,14 +12,12 @@ import {
|
|||||||
detectReferenceSourceLanguage,
|
detectReferenceSourceLanguage,
|
||||||
} from "../domain/referenceSourceClassification.js";
|
} from "../domain/referenceSourceClassification.js";
|
||||||
import type { HistoricalSourceGraphInput } from "../domain/referenceSourceGraph.js";
|
import type { HistoricalSourceGraphInput } from "../domain/referenceSourceGraph.js";
|
||||||
import {
|
import { parseReferenceSourceImports } from "../domain/referenceSourceImportParsing.js";
|
||||||
parseReferenceSourceImports,
|
|
||||||
PARSEABLE_REFERENCE_SOURCE_LANGUAGES,
|
|
||||||
} from "../domain/referenceSourceImportParsing.js";
|
|
||||||
import type {
|
import type {
|
||||||
ReferenceSourceEntry,
|
ReferenceSourceEntry,
|
||||||
ReferenceSourceRead,
|
ReferenceSourceRead,
|
||||||
} from "../reference/ReferenceSourceReaderTypes.js";
|
} from "../reference/ReferenceSourceReaderTypes.js";
|
||||||
|
import { PARSEABLE_REFERENCE_SOURCE_LANGUAGES } from "./ReferenceSourceImportTypes.js";
|
||||||
import { typescriptEmittedSourceCandidates } from "./TypeScriptEmittedSourceCandidates.js";
|
import { typescriptEmittedSourceCandidates } from "./TypeScriptEmittedSourceCandidates.js";
|
||||||
|
|
||||||
export interface ParsedReferenceSourceEntries {
|
export interface ParsedReferenceSourceEntries {
|
||||||
@@ -104,11 +102,7 @@ const resolveInternalSpecifier = (
|
|||||||
]);
|
]);
|
||||||
// Retain present runtime files first; substitute only a missing counterpart.
|
// Retain present runtime files first; substitute only a missing counterpart.
|
||||||
// Counterparts cover explicit filenames, not directory/index resolution.
|
// Counterparts cover explicit filenames, not directory/index resolution.
|
||||||
candidates.push(
|
candidates.push(...typescriptEmittedSourceCandidates(fromPath, normalized));
|
||||||
...typescriptEmittedSourceCandidates(fromPath, normalized).map(
|
|
||||||
({ path }) => path,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const match = lookupPath.resolveCandidates(candidates);
|
const match = lookupPath.resolveCandidates(candidates);
|
||||||
return match === undefined
|
return match === undefined
|
||||||
? { to: normalized, resolution: "unresolved" }
|
? { to: normalized, resolution: "unresolved" }
|
||||||
|
|||||||
@@ -87,3 +87,6 @@ export const DEFAULT_REFERENCE_SOURCE_IGNORE_PATTERNS = [
|
|||||||
".coverage",
|
".coverage",
|
||||||
"*.log",
|
"*.log",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
export const PARSEABLE_REFERENCE_SOURCE_LANGUAGES: ReadonlySet<string> =
|
||||||
|
new Set(["JavaScript", "TypeScript", "JSX", "TSX"]);
|
||||||
|
|||||||
@@ -19,17 +19,6 @@ export interface RegularFileReadOptions {
|
|||||||
readonly resources?: ArtifactResourceScope;
|
readonly resources?: ArtifactResourceScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class InvalidUtf8FileError extends TypeError {
|
|
||||||
readonly _tag = "InvalidUtf8FileError";
|
|
||||||
constructor(
|
|
||||||
readonly path: string,
|
|
||||||
cause: unknown,
|
|
||||||
) {
|
|
||||||
super(`File is not valid UTF-8: ${path}`, { cause });
|
|
||||||
this.name = this._tag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type RegularFileReadOutcome<Value> =
|
export type RegularFileReadOutcome<Value> =
|
||||||
| { readonly kind: "completed"; readonly value: Value }
|
| { readonly kind: "completed"; readonly value: Value }
|
||||||
| { readonly kind: "failed"; readonly cause: unknown };
|
| { readonly kind: "failed"; readonly cause: unknown };
|
||||||
@@ -153,34 +142,7 @@ const withRegularFileOwned = async <Value>(
|
|||||||
export const readRegularFile = (
|
export const readRegularFile = (
|
||||||
path: string,
|
path: string,
|
||||||
options: RegularFileReadOptions = {},
|
options: RegularFileReadOptions = {},
|
||||||
): Promise<Buffer> => readRegularFileContent(path, (bytes) => bytes, options);
|
): Promise<Buffer> =>
|
||||||
|
|
||||||
/** Read valid UTF-8 without replacing source bytes or stripping an initial BOM. */
|
|
||||||
export const readRegularFileText = (
|
|
||||||
path: string,
|
|
||||||
options: RegularFileReadOptions = {},
|
|
||||||
): Promise<string> =>
|
|
||||||
readRegularFileContent(
|
|
||||||
path,
|
|
||||||
(bytes) => {
|
|
||||||
try {
|
|
||||||
return new TextDecoder("utf-8", {
|
|
||||||
fatal: true,
|
|
||||||
ignoreBOM: true,
|
|
||||||
}).decode(bytes);
|
|
||||||
} catch (cause: unknown) {
|
|
||||||
if (!(cause instanceof TypeError)) throw cause;
|
|
||||||
throw new InvalidUtf8FileError(path, cause);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
|
|
||||||
const readRegularFileContent = <Value>(
|
|
||||||
path: string,
|
|
||||||
decode: (bytes: Buffer) => Value,
|
|
||||||
options: RegularFileReadOptions,
|
|
||||||
): Promise<Value> =>
|
|
||||||
withRegularFile(
|
withRegularFile(
|
||||||
path,
|
path,
|
||||||
async (handle, stats) => {
|
async (handle, stats) => {
|
||||||
@@ -191,7 +153,30 @@ const readRegularFileContent = <Value>(
|
|||||||
);
|
);
|
||||||
if (bytes === undefined || bytes.length !== stats.size)
|
if (bytes === undefined || bytes.length !== stats.size)
|
||||||
throw new RegularFileChangedError(path);
|
throw new RegularFileChangedError(path);
|
||||||
return decode(bytes);
|
return bytes;
|
||||||
},
|
},
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** Read one admitted regular file as UTF-8 without waiting on a pipe. */
|
||||||
|
export const readRegularFileText = async (
|
||||||
|
path: string,
|
||||||
|
options: RegularFileReadOptions = {},
|
||||||
|
): Promise<string> => {
|
||||||
|
try {
|
||||||
|
return (await readRegularFile(path, options)).toString("utf8");
|
||||||
|
} catch (cause: unknown) {
|
||||||
|
if (
|
||||||
|
cause instanceof RegularFileCleanupFailure &&
|
||||||
|
cause.outcome.kind === "completed" &&
|
||||||
|
Buffer.isBuffer(cause.outcome.value)
|
||||||
|
)
|
||||||
|
throw new RegularFileCleanupFailure(
|
||||||
|
cause.path,
|
||||||
|
cause.owner,
|
||||||
|
{ kind: "completed", value: cause.outcome.value.toString("utf8") },
|
||||||
|
cause.cleanupCause,
|
||||||
|
);
|
||||||
|
throw cause;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -54,40 +54,6 @@ describe("setup workflow", () => {
|
|||||||
expect(result.remediation).toContain("could not be updated");
|
expect(result.remediation).toContain("could not be updated");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports a failed config rollback with its destination and recovery backup", async () => {
|
|
||||||
const host = new FakeSetupHost();
|
|
||||||
host.hopper = "/Applications/Hopper";
|
|
||||||
host.clients = [{ name: "codex", configPath: "/fixture/codex.json" }];
|
|
||||||
host.clientResults.set("codex", {
|
|
||||||
status: "failed",
|
|
||||||
reason: "rollback",
|
|
||||||
backupPath: "/fixture/codex.json.rea.backup",
|
|
||||||
failure: {
|
|
||||||
kind: "restore",
|
|
||||||
path: "/fixture/codex.json",
|
|
||||||
detail: "permission denied",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await runSetup(
|
|
||||||
{ ...options(true), clientIds: ["codex"] },
|
|
||||||
host,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.clients.codex).toEqual({
|
|
||||||
status: "failed",
|
|
||||||
reason: "rollback",
|
|
||||||
backupPath: "/fixture/codex.json.rea.backup",
|
|
||||||
failure: {
|
|
||||||
kind: "restore",
|
|
||||||
path: "/fixture/codex.json",
|
|
||||||
detail: "permission denied",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(result.remediation).toContain("permission denied");
|
|
||||||
expect(result.remediation).toContain("/fixture/codex.json.rea.backup");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("explains skill installation recovery", async () => {
|
it("explains skill installation recovery", async () => {
|
||||||
const host = new FakeSetupHost();
|
const host = new FakeSetupHost();
|
||||||
host.hopper = "/Applications/Hopper";
|
host.hopper = "/Applications/Hopper";
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import {
|
|||||||
} from "./ClientConfigurationDocument.js";
|
} from "./ClientConfigurationDocument.js";
|
||||||
import { dshDocument, DshCordisDocument } from "./DshCordisPatch.js";
|
import { dshDocument, DshCordisDocument } from "./DshCordisPatch.js";
|
||||||
import { constants as fsConstants } from "node:fs";
|
import { constants as fsConstants } from "node:fs";
|
||||||
import { createHash } from "node:crypto";
|
|
||||||
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
|
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
|
||||||
import { dirname } from "node:path";
|
import { dirname } from "node:path";
|
||||||
import writeFileAtomic from "write-file-atomic";
|
import writeFileAtomic from "write-file-atomic";
|
||||||
@@ -30,7 +29,6 @@ import { npxRegistrationCommand } from "./ClientRegistrationIdentity.js";
|
|||||||
import { MCP_STARTUP_POLICY } from "../mcpStartupPolicy.js";
|
import { MCP_STARTUP_POLICY } from "../mcpStartupPolicy.js";
|
||||||
import { resolveClientConfigTransactionPath } from "./ClientConfigPath.js";
|
import { resolveClientConfigTransactionPath } from "./ClientConfigPath.js";
|
||||||
import {
|
import {
|
||||||
readRegularFile,
|
|
||||||
readRegularFileText,
|
readRegularFileText,
|
||||||
RegularFileCleanupFailure,
|
RegularFileCleanupFailure,
|
||||||
} from "./RegularFileRead.js";
|
} from "./RegularFileRead.js";
|
||||||
@@ -42,26 +40,6 @@ import type {
|
|||||||
} from "./SetupTypes.js";
|
} from "./SetupTypes.js";
|
||||||
import type { SetupClient } from "./SupportedClients.js";
|
import type { SetupClient } from "./SupportedClients.js";
|
||||||
|
|
||||||
export class ClientConfigurationCleanupRollbackFailure extends RegularFileCleanupFailure<string> {
|
|
||||||
constructor(
|
|
||||||
failure: RegularFileCleanupFailure<string>,
|
|
||||||
readonly configurationFailure: Extract<
|
|
||||||
ClientConfigurationResult,
|
|
||||||
{ readonly status: "failed"; readonly reason: "rollback" }
|
|
||||||
>,
|
|
||||||
) {
|
|
||||||
super(
|
|
||||||
failure.path,
|
|
||||||
failure.owner,
|
|
||||||
failure.outcome,
|
|
||||||
new AggregateError(
|
|
||||||
[failure.cleanupCause, new Error(configurationFailure.failure.detail)],
|
|
||||||
`Configuration readback cleanup and rollback failed: ${configurationFailure.failure.path}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure one supported client's native stdio MCP registration shape. */
|
/** Configure one supported client's native stdio MCP registration shape. */
|
||||||
export const configureClientConfiguration = (
|
export const configureClientConfiguration = (
|
||||||
client: SetupClient,
|
client: SetupClient,
|
||||||
@@ -189,23 +167,11 @@ const persistClientConfiguration = async ({
|
|||||||
}: ClientConfigurationUpdate): Promise<ClientConfigurationResult> => {
|
}: ClientConfigurationUpdate): Promise<ClientConfigurationResult> => {
|
||||||
const backupPath =
|
const backupPath =
|
||||||
original === undefined ? undefined : `${client.configPath}.rea.backup`;
|
original === undefined ? undefined : `${client.configPath}.rea.backup`;
|
||||||
let recoveryBackupPath: string | undefined;
|
|
||||||
if (backupPath !== undefined && original !== undefined) {
|
|
||||||
const selection = await selectCurrentRecoveryBackup(backupPath, original);
|
|
||||||
if (!selection.ok) return { status: "failed", reason: "backup" };
|
|
||||||
if (
|
if (
|
||||||
!(await preserveConfigBackup(transactionPath, selection.value.backupPath))
|
backupPath !== undefined &&
|
||||||
|
!(await preserveConfigBackup(transactionPath, backupPath))
|
||||||
)
|
)
|
||||||
return { status: "failed", reason: "backup" };
|
return { status: "failed", reason: "backup" };
|
||||||
const verified = await selectCurrentRecoveryBackup(backupPath, original);
|
|
||||||
if (
|
|
||||||
!verified.ok ||
|
|
||||||
verified.value.backupPath !== selection.value.backupPath ||
|
|
||||||
!verified.value.present
|
|
||||||
)
|
|
||||||
return { status: "failed", reason: "backup" };
|
|
||||||
recoveryBackupPath = verified.value.backupPath;
|
|
||||||
}
|
|
||||||
// A native OpenCode V2 entry replaces REA's legacy V1 entry, which would
|
// A native OpenCode V2 entry replaces REA's legacy V1 entry, which would
|
||||||
// otherwise conflict with it.
|
// otherwise conflict with it.
|
||||||
const legacyPath = legacyClientServerPath(
|
const legacyPath = legacyClientServerPath(
|
||||||
@@ -273,39 +239,19 @@ const persistClientConfiguration = async ({
|
|||||||
!clientConfigurationValuesEqual(readback.servers[name], entry),
|
!clientConfigurationValuesEqual(readback.servers[name], entry),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return rollbackOrReadbackFailure(
|
await restoreConfig(transactionPath, original);
|
||||||
transactionPath,
|
return { status: "failed", reason: "readback" };
|
||||||
original,
|
|
||||||
recoveryBackupPath,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
if (cause instanceof RegularFileCleanupFailure) {
|
if (cause instanceof RegularFileCleanupFailure) throw cause;
|
||||||
const rollback = await restoreConfig(transactionPath, original);
|
|
||||||
if (!rollback.ok)
|
|
||||||
throw new ClientConfigurationCleanupRollbackFailure(cause, {
|
|
||||||
status: "failed",
|
|
||||||
reason: "rollback",
|
|
||||||
...(recoveryBackupPath === undefined
|
|
||||||
? {}
|
|
||||||
: { backupPath: recoveryBackupPath }),
|
|
||||||
failure: rollback.error,
|
|
||||||
});
|
|
||||||
throw cause;
|
|
||||||
}
|
|
||||||
// Readback failure restores the transaction before reporting.
|
// Readback failure restores the transaction before reporting.
|
||||||
void cause;
|
void cause;
|
||||||
return rollbackOrReadbackFailure(
|
await restoreConfig(transactionPath, original);
|
||||||
transactionPath,
|
return { status: "failed", reason: "readback" };
|
||||||
original,
|
|
||||||
recoveryBackupPath,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
status: "configured",
|
status: "configured",
|
||||||
...(recoveryBackupPath === undefined
|
...(backupPath === undefined ? {} : { backupPath }),
|
||||||
? {}
|
|
||||||
: { backupPath: recoveryBackupPath }),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -460,18 +406,9 @@ export const inspectClientConfiguration = async (
|
|||||||
"The existing configuration is malformed. Repair it before setup applies any other changes.",
|
"The existing configuration is malformed. Repair it before setup applies any other changes.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const backupSelection = await selectCurrentRecoveryBackup(
|
|
||||||
`${client.configPath}.rea.backup`,
|
|
||||||
original,
|
|
||||||
);
|
|
||||||
if (!backupSelection.ok)
|
|
||||||
return {
|
|
||||||
status: "invalid",
|
|
||||||
remediation: backupSelection.error.detail,
|
|
||||||
};
|
|
||||||
return {
|
return {
|
||||||
status: "update",
|
status: "update",
|
||||||
backupPath: backupSelection.value.backupPath,
|
backupPath: `${client.configPath}.rea.backup`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -536,101 +473,19 @@ const preserveConfigBackup = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
interface RecoveryBackupSelection {
|
|
||||||
readonly backupPath: string;
|
|
||||||
readonly present: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface RecoveryBackupSelectionFailure {
|
|
||||||
readonly kind: "unreadable" | "occupied";
|
|
||||||
readonly path: string;
|
|
||||||
readonly detail: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectCurrentRecoveryBackup = async (
|
|
||||||
firstBackupPath: string,
|
|
||||||
original: string,
|
|
||||||
): Promise<Result<RecoveryBackupSelection, RecoveryBackupSelectionFailure>> => {
|
|
||||||
const expected = Buffer.from(original, "utf8");
|
|
||||||
let firstBackup: Buffer | undefined;
|
|
||||||
try {
|
|
||||||
firstBackup = await readRegularFile(firstBackupPath, {
|
|
||||||
symlinks: "reject",
|
|
||||||
});
|
|
||||||
} catch (cause: unknown) {
|
|
||||||
if (cause instanceof RegularFileCleanupFailure) throw cause;
|
|
||||||
if (!isMissing(cause))
|
|
||||||
return err({
|
|
||||||
kind: "unreadable",
|
|
||||||
path: firstBackupPath,
|
|
||||||
detail: `The recovery backup could not be checked: ${errorDetail(cause)}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (firstBackup === undefined)
|
|
||||||
return ok({ backupPath: firstBackupPath, present: false });
|
|
||||||
if (firstBackup.equals(expected))
|
|
||||||
return ok({ backupPath: firstBackupPath, present: true });
|
|
||||||
|
|
||||||
const digest = createHash("sha256").update(original, "utf8").digest("hex");
|
|
||||||
const recoveryPath = `${firstBackupPath}.${digest}.recovery`;
|
|
||||||
let recovery: Buffer | undefined;
|
|
||||||
try {
|
|
||||||
recovery = await readRegularFile(recoveryPath, { symlinks: "reject" });
|
|
||||||
} catch (cause: unknown) {
|
|
||||||
if (cause instanceof RegularFileCleanupFailure) throw cause;
|
|
||||||
if (!isMissing(cause))
|
|
||||||
return err({
|
|
||||||
kind: "unreadable",
|
|
||||||
path: recoveryPath,
|
|
||||||
detail: `The recovery backup could not be checked: ${errorDetail(cause)}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (recovery !== undefined && !recovery.equals(expected))
|
|
||||||
return err({
|
|
||||||
kind: "occupied",
|
|
||||||
path: recoveryPath,
|
|
||||||
detail: `The recovery path already contains different data: ${recoveryPath}`,
|
|
||||||
});
|
|
||||||
return ok({ backupPath: recoveryPath, present: recovery !== undefined });
|
|
||||||
};
|
|
||||||
|
|
||||||
const restoreConfig = async (
|
const restoreConfig = async (
|
||||||
path: string,
|
path: string,
|
||||||
original: string | undefined,
|
original: string | undefined,
|
||||||
): Promise<
|
): Promise<void> => {
|
||||||
Result<
|
|
||||||
void,
|
|
||||||
{ readonly kind: "restore"; readonly path: string; readonly detail: string }
|
|
||||||
>
|
|
||||||
> => {
|
|
||||||
try {
|
try {
|
||||||
if (original === undefined) await rm(path, { force: true });
|
if (original === undefined) await rm(path, { force: true });
|
||||||
else await writeFile(path, original, { encoding: "utf8", mode: 0o600 });
|
else await writeFile(path, original, { encoding: "utf8", mode: 0o600 });
|
||||||
return ok(undefined);
|
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
return err({ kind: "restore", path, detail: errorDetail(cause) });
|
// The backup remains available for the remediation reported by setup.
|
||||||
|
void cause;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const rollbackOrReadbackFailure = async (
|
|
||||||
targetPath: string,
|
|
||||||
original: string | undefined,
|
|
||||||
backupPath: string | undefined,
|
|
||||||
): Promise<ClientConfigurationResult> => {
|
|
||||||
const rollback = await restoreConfig(targetPath, original);
|
|
||||||
return rollback.ok
|
|
||||||
? { status: "failed", reason: "readback" }
|
|
||||||
: {
|
|
||||||
status: "failed",
|
|
||||||
reason: "rollback",
|
|
||||||
...(backupPath === undefined ? {} : { backupPath }),
|
|
||||||
failure: rollback.error,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorDetail = (cause: unknown): string =>
|
|
||||||
cause instanceof Error ? cause.message : String(cause);
|
|
||||||
|
|
||||||
/** Whether REA's entry matches, no legacy entry remains, and no client disable list suppresses it. */
|
/** Whether REA's entry matches, no legacy entry remains, and no client disable list suppresses it. */
|
||||||
const registrationCurrent = (
|
const registrationCurrent = (
|
||||||
parsed: ClientConfigurationDocument,
|
parsed: ClientConfigurationDocument,
|
||||||
|
|||||||
@@ -6,19 +6,15 @@ import type {
|
|||||||
} from "./SetupTypes.js";
|
} from "./SetupTypes.js";
|
||||||
import type { SetupClient } from "./SupportedClients.js";
|
import type { SetupClient } from "./SupportedClients.js";
|
||||||
|
|
||||||
export const failedConfigurationMessage = (
|
const failedConfigurationMessage = (
|
||||||
result: Extract<ClientConfigurationResult, { readonly status: "failed" }>,
|
reason: "path" | "backup" | "write" | "readback",
|
||||||
): string => {
|
): string => {
|
||||||
if (result.reason === "path")
|
if (reason === "path")
|
||||||
return "Agent configuration path could not be safely verified. Check its permissions and, if it is a symbolic link, verify that the link resolves to a regular file owned by the current user, then rerun setup.";
|
return "Agent configuration path could not be safely verified. Check its permissions and, if it is a symbolic link, verify that the link resolves to a regular file owned by the current user, then rerun setup.";
|
||||||
if (result.reason === "backup")
|
if (reason === "backup")
|
||||||
return "Agent configuration could not be backed up, so no change was made. Check file permissions, then rerun setup.";
|
return "Agent configuration could not be backed up, so no change was made. Check file permissions, then rerun setup.";
|
||||||
if (result.reason === "write")
|
if (reason === "write")
|
||||||
return "Agent configuration could not be updated. Check file permissions, then rerun setup.";
|
return "Agent configuration could not be updated. Check file permissions, then rerun setup.";
|
||||||
if (result.reason === "rollback")
|
|
||||||
return result.backupPath === undefined
|
|
||||||
? `Agent configuration rollback failed at ${result.failure.path}: ${result.failure.detail}; the failed first-run file may remain. Remove or repair it before rerunning setup.`
|
|
||||||
: `Agent configuration rollback failed at ${result.failure.path}: ${result.failure.detail}. Inspect the preserved backup at ${result.backupPath} and restore the intended configuration, then rerun setup.`;
|
|
||||||
return "Agent configuration could not be verified after writing. Repair the configuration file or restore its `.rea.backup`, then rerun setup.";
|
return "Agent configuration could not be verified after writing. Repair the configuration file or restore its `.rea.backup`, then rerun setup.";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -44,12 +40,12 @@ export const configureDetectedClients = async (options: {
|
|||||||
);
|
);
|
||||||
options.clients[client.name] = result;
|
options.clients[client.name] = result;
|
||||||
if (result.status === "failed") {
|
if (result.status === "failed") {
|
||||||
failure ??= failedConfigurationMessage(result);
|
failure ??= failedConfigurationMessage(result.reason);
|
||||||
options.onProgress?.({
|
options.onProgress?.({
|
||||||
actionId,
|
actionId,
|
||||||
label,
|
label,
|
||||||
state: "failed",
|
state: "failed",
|
||||||
detail: failedConfigurationMessage(result),
|
detail: failedConfigurationMessage(result.reason),
|
||||||
});
|
});
|
||||||
} else if (result.status === "configured") {
|
} else if (result.status === "configured") {
|
||||||
options.appliedActions.push(`configured_${client.name}`);
|
options.appliedActions.push(`configured_${client.name}`);
|
||||||
|
|||||||
@@ -33,11 +33,9 @@ import {
|
|||||||
} from "./SetupSkill.js";
|
} from "./SetupSkill.js";
|
||||||
import {
|
import {
|
||||||
clientConfigurationAligned,
|
clientConfigurationAligned,
|
||||||
ClientConfigurationCleanupRollbackFailure,
|
|
||||||
configureClientConfiguration,
|
configureClientConfiguration,
|
||||||
inspectClientConfiguration,
|
inspectClientConfiguration,
|
||||||
} from "./SetupClientConfiguration.js";
|
} from "./SetupClientConfiguration.js";
|
||||||
import { failedConfigurationMessage } from "./SetupClients.js";
|
|
||||||
import { setupInstallFailure } from "./SetupInstallFailure.js";
|
import { setupInstallFailure } from "./SetupInstallFailure.js";
|
||||||
import {
|
import {
|
||||||
RegularFileCleanupFailure,
|
RegularFileCleanupFailure,
|
||||||
@@ -277,12 +275,8 @@ const runClientConfigurationOperation = async <Value>(
|
|||||||
cleanup.outcome.kind === "failed"
|
cleanup.outcome.kind === "failed"
|
||||||
? cleanup.outcome.cause
|
? cleanup.outcome.cause
|
||||||
: cause.cleanupCause;
|
: cause.cleanupCause;
|
||||||
const rollbackMessage =
|
|
||||||
cause instanceof ClientConfigurationCleanupRollbackFailure
|
|
||||||
? ` ${failedConfigurationMessage(cause.configurationFailure)}`
|
|
||||||
: "";
|
|
||||||
throw configurationCleanupError(
|
throw configurationCleanupError(
|
||||||
`Could not safely access client configuration at ${cause.path}: ${errorMessage(primary)}.${rollbackMessage}`,
|
`Could not safely access client configuration at ${cause.path}: ${errorMessage(primary)}`,
|
||||||
cause,
|
cause,
|
||||||
cleanup.cleanup,
|
cleanup.cleanup,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
|
|
||||||
import { HOPPER_PUBLISHER } from "./MacHopper.js";
|
|
||||||
import { setupInstallFailure } from "./SetupInstallFailure.js";
|
|
||||||
|
|
||||||
describe("macOS Hopper setup failure projection", () => {
|
|
||||||
it("projects a publisher mismatch onto its own code and recovery", () => {
|
|
||||||
expect(setupInstallFailure("publisher_verification_failed")).toEqual({
|
|
||||||
status: "failed",
|
|
||||||
code: "publisher_verification_failed",
|
|
||||||
remediation: `The mounted Hopper application is not signed by the publisher REA pins (${HOPPER_PUBLISHER.bundleIdentifier}, Apple team ${HOPPER_PUBLISHER.teamIdentifier}); nothing was copied or launched. Install Hopper yourself and set HOPPER_LAUNCHER_PATH to its launcher, then rerun rea setup.`,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps a broken bundle distinct from a publisher mismatch", () => {
|
|
||||||
expect(setupInstallFailure("bundle")).toEqual({
|
|
||||||
status: "failed",
|
|
||||||
code: "bundle_invalid",
|
|
||||||
remediation:
|
|
||||||
"The mounted package did not contain the expected Hopper application bundle. Retry setup; if it repeats, update REA before installing.",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import { HOPPER_PUBLISHER } from "./MacHopper.js";
|
|
||||||
|
|
||||||
export type SetupFailureCode =
|
export type SetupFailureCode =
|
||||||
| "unsupported_host"
|
| "unsupported_host"
|
||||||
| "download_failed"
|
| "download_failed"
|
||||||
@@ -12,7 +10,6 @@ export type SetupFailureCode =
|
|||||||
| "destination_exists"
|
| "destination_exists"
|
||||||
| "mount_failed"
|
| "mount_failed"
|
||||||
| "bundle_invalid"
|
| "bundle_invalid"
|
||||||
| "publisher_verification_failed"
|
|
||||||
| "copy_failed"
|
| "copy_failed"
|
||||||
| "skill_install_failed"
|
| "skill_install_failed"
|
||||||
| "cleanup_failed";
|
| "cleanup_failed";
|
||||||
@@ -42,7 +39,6 @@ export type HopperInstallFailureReason =
|
|||||||
| "destination_exists"
|
| "destination_exists"
|
||||||
| "mount"
|
| "mount"
|
||||||
| "bundle"
|
| "bundle"
|
||||||
| "publisher_verification_failed"
|
|
||||||
| "copy";
|
| "copy";
|
||||||
|
|
||||||
/** Map provider installer failures to stable setup codes and safe recovery. */
|
/** Map provider installer failures to stable setup codes and safe recovery. */
|
||||||
@@ -119,12 +115,6 @@ export const setupInstallFailure = (
|
|||||||
remediation:
|
remediation:
|
||||||
"The mounted package did not contain the expected Hopper application bundle. Retry setup; if it repeats, update REA before installing.",
|
"The mounted package did not contain the expected Hopper application bundle. Retry setup; if it repeats, update REA before installing.",
|
||||||
};
|
};
|
||||||
case "publisher_verification_failed":
|
|
||||||
return {
|
|
||||||
status: "failed",
|
|
||||||
code: "publisher_verification_failed",
|
|
||||||
remediation: `The mounted Hopper application is not signed by the publisher REA pins (${HOPPER_PUBLISHER.bundleIdentifier}, Apple team ${HOPPER_PUBLISHER.teamIdentifier}); nothing was copied or launched. Install Hopper yourself and set HOPPER_LAUNCHER_PATH to its launcher, then rerun rea setup.`,
|
|
||||||
};
|
|
||||||
case "copy":
|
case "copy":
|
||||||
return {
|
return {
|
||||||
status: "failed",
|
status: "failed",
|
||||||
|
|||||||
@@ -320,5 +320,5 @@ const clientConfigurationDetail = (
|
|||||||
? " If this plan installs Hopper, REA will add HOPPER_LAUNCHER_PATH using the launcher path reported by that installation."
|
? " If this plan installs Hopper, REA will add HOPPER_LAUNCHER_PATH using the launcher path reported by that installation."
|
||||||
: " The HOPPER_LAUNCHER_PATH value shown above is the current fallback; if this plan installs Hopper, REA will replace it with the launcher path reported by that installation."
|
: " The HOPPER_LAUNCHER_PATH value shown above is the current fallback; if this plan installs Hopper, REA will replace it with the launcher path reported by that installation."
|
||||||
: "";
|
: "";
|
||||||
return `Add the REA MCP registration for ${client}; preserve unrelated configuration. The backup path reflects the configuration inspected for this plan; if that file changes before execution, setup will select a recovery path for its current contents. Command: ${command.map((part) => JSON.stringify(part)).join(" ")}.${environmentDetail}${hopperDetail}`;
|
return `Add the REA MCP registration for ${client}; preserve unrelated configuration. Command: ${command.map((part) => JSON.stringify(part)).join(" ")}.${environmentDetail}${hopperDetail}`;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,16 +26,6 @@ export type ClientConfigurationResult =
|
|||||||
| {
|
| {
|
||||||
readonly status: "failed";
|
readonly status: "failed";
|
||||||
readonly reason: "path" | "backup" | "write" | "readback";
|
readonly reason: "path" | "backup" | "write" | "readback";
|
||||||
}
|
|
||||||
| {
|
|
||||||
readonly status: "failed";
|
|
||||||
readonly reason: "rollback";
|
|
||||||
readonly backupPath?: string;
|
|
||||||
readonly failure: {
|
|
||||||
readonly kind: "restore";
|
|
||||||
readonly path: string;
|
|
||||||
readonly detail: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Read-only state used to block unsafe setup plans before any mutation. */
|
/** Read-only state used to block unsafe setup plans before any mutation. */
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ const EMITTED_SUFFIXES: ReadonlyArray<
|
|||||||
[".jsx", [".tsx", ".d.ts"]],
|
[".jsx", [".tsx", ".d.ts"]],
|
||||||
];
|
];
|
||||||
|
|
||||||
export interface TypeScriptEmittedSourceCandidate {
|
|
||||||
readonly path: string;
|
|
||||||
readonly kind: "implementation" | "declaration";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return TypeScript source counterparts for an explicit emitted filename.
|
* Return TypeScript source counterparts for an explicit emitted filename.
|
||||||
* Callers retain exact runtime-file precedence and must not use these for
|
* Callers retain exact runtime-file precedence and must not use these for
|
||||||
@@ -21,7 +16,7 @@ export interface TypeScriptEmittedSourceCandidate {
|
|||||||
export const typescriptEmittedSourceCandidates = (
|
export const typescriptEmittedSourceCandidates = (
|
||||||
sourcePath: string,
|
sourcePath: string,
|
||||||
candidate: string,
|
candidate: string,
|
||||||
): readonly TypeScriptEmittedSourceCandidate[] => {
|
): readonly string[] => {
|
||||||
if (!/\.(?:ts|tsx|mts|cts)$/u.test(sourcePath)) return [];
|
if (!/\.(?:ts|tsx|mts|cts)$/u.test(sourcePath)) return [];
|
||||||
const emitted = EMITTED_SUFFIXES.find(([suffix]) =>
|
const emitted = EMITTED_SUFFIXES.find(([suffix]) =>
|
||||||
candidate.endsWith(suffix),
|
candidate.endsWith(suffix),
|
||||||
@@ -30,8 +25,5 @@ export const typescriptEmittedSourceCandidates = (
|
|||||||
// Strip the matched suffix by length. posix.extname would miss dotfile
|
// Strip the matched suffix by length. posix.extname would miss dotfile
|
||||||
// names such as ".js", whose whole basename is the emitted suffix itself.
|
// names such as ".js", whose whole basename is the emitted suffix itself.
|
||||||
const stem = candidate.slice(0, candidate.length - emitted[0].length);
|
const stem = candidate.slice(0, candidate.length - emitted[0].length);
|
||||||
return emitted[1].map((suffix) => ({
|
return emitted[1].map((suffix) => `${stem}${suffix}`);
|
||||||
path: `${stem}${suffix}`,
|
|
||||||
kind: suffix.startsWith(".d.") ? "declaration" : "implementation",
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,11 +25,7 @@ import {
|
|||||||
import { isOwnedClientRegistrationCommand } from "./ClientRegistrationIdentity.js";
|
import { isOwnedClientRegistrationCommand } from "./ClientRegistrationIdentity.js";
|
||||||
import { dshDocument } from "./DshCordisPatch.js";
|
import { dshDocument } from "./DshCordisPatch.js";
|
||||||
import { resolveClientConfigTransactionPath } from "./ClientConfigPath.js";
|
import { resolveClientConfigTransactionPath } from "./ClientConfigPath.js";
|
||||||
import {
|
import { readRegularFileText } from "./RegularFileRead.js";
|
||||||
InvalidUtf8FileError,
|
|
||||||
RegularFileCleanupFailure,
|
|
||||||
readRegularFileText,
|
|
||||||
} from "./RegularFileRead.js";
|
|
||||||
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
|
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
|
||||||
import {
|
import {
|
||||||
manualRegistrationRemediation,
|
manualRegistrationRemediation,
|
||||||
@@ -273,17 +269,13 @@ const readClientConfiguration = async (
|
|||||||
try {
|
try {
|
||||||
original = await fileSystem.readText(transactionPath);
|
original = await fileSystem.readText(transactionPath);
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
const readFailure =
|
|
||||||
cause instanceof RegularFileCleanupFailure ? cause.cause : cause;
|
|
||||||
return itemRead(
|
return itemRead(
|
||||||
isMissing(cause)
|
isMissing(cause)
|
||||||
? item(client.name, "skipped", "Configuration does not exist.")
|
? item(client.name, "skipped", "Configuration does not exist.")
|
||||||
: item(
|
: item(
|
||||||
client.name,
|
client.name,
|
||||||
"failed",
|
"failed",
|
||||||
readFailure instanceof InvalidUtf8FileError
|
"Configuration could not be read. Check file permissions, then rerun uninstall.",
|
||||||
? "Configuration is not valid UTF-8 and was not changed. Repair it, then rerun uninstall."
|
|
||||||
: "Configuration could not be read. Check file permissions, then rerun uninstall.",
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export interface WebModuleArtifacts extends SelectedWebScriptArtifacts {
|
|||||||
|
|
||||||
/** Read selected local artifacts without refetching website assets. */
|
/** Read selected local artifacts without refetching website assets. */
|
||||||
export interface WebModuleArtifactPort {
|
export interface WebModuleArtifactPort {
|
||||||
close?(): Promise<void>;
|
|
||||||
load(
|
load(
|
||||||
input: WebModuleTraceInput,
|
input: WebModuleTraceInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { closeOwnedWebResources } from "./closeOwnedWebResources.js";
|
|
||||||
import { isAbsolute } from "node:path";
|
import { isAbsolute } from "node:path";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||||
@@ -71,13 +70,7 @@ export class WebModuleTraceService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
close(): Promise<void> {
|
close(): Promise<void> {
|
||||||
return closeOwnedWebResources(
|
return this.resolver.close?.() ?? Promise.resolve();
|
||||||
[
|
|
||||||
this.artifacts.close?.bind(this.artifacts),
|
|
||||||
this.resolver.close?.bind(this.resolver),
|
|
||||||
],
|
|
||||||
"Web module trace cleanup failed",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async trace(
|
async trace(
|
||||||
|
|||||||
@@ -12,6 +12,4 @@ export interface WebNetworkCapturePort {
|
|||||||
input: InspectWebNetworkCaptureInput,
|
input: InspectWebNetworkCaptureInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
): Promise<Result<WebNetworkCapture, AnalysisError>>;
|
): Promise<Result<WebNetworkCapture, AnalysisError>>;
|
||||||
/** Retry retained reader/runtime cleanup when the owning service shuts down. */
|
|
||||||
close?(): Promise<void>;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,11 +27,6 @@ const OPERATION = "inspect_web_network_capture";
|
|||||||
export class WebNetworkCaptureService {
|
export class WebNetworkCaptureService {
|
||||||
constructor(readonly port: WebNetworkCapturePort) {}
|
constructor(readonly port: WebNetworkCapturePort) {}
|
||||||
|
|
||||||
/** Release resources retained by the selected capture adapter. */
|
|
||||||
close(): Promise<void> {
|
|
||||||
return this.port.close?.() ?? Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return selected complete records inline, without inventing live browser attribution. */
|
/** Return selected complete records inline, without inventing live browser attribution. */
|
||||||
async inspect(
|
async inspect(
|
||||||
rawInput: unknown,
|
rawInput: unknown,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import type { ExecutionOptions } from "./AnalysisProvider.js";
|
|||||||
|
|
||||||
/** Read the caller-selected capture export and verify the selected source identity. */
|
/** Read the caller-selected capture export and verify the selected source identity. */
|
||||||
export interface WebScriptArtifactPort {
|
export interface WebScriptArtifactPort {
|
||||||
close?(): Promise<void>;
|
|
||||||
load(
|
load(
|
||||||
input: SelectedWebScriptInput,
|
input: SelectedWebScriptInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export interface WebSourceLocationArtifacts extends SelectedWebScriptArtifacts {
|
|||||||
|
|
||||||
/** Replaceable artifact acquisition boundary for a caller-selected pairing. */
|
/** Replaceable artifact acquisition boundary for a caller-selected pairing. */
|
||||||
export interface WebSourceLocationArtifactPort {
|
export interface WebSourceLocationArtifactPort {
|
||||||
close?(): Promise<void>;
|
|
||||||
load(
|
load(
|
||||||
input: WebSourceLocationInput,
|
input: WebSourceLocationInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { closeOwnedWebResources } from "./closeOwnedWebResources.js";
|
|
||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
import { isAbsolute } from "node:path";
|
import { isAbsolute } from "node:path";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
@@ -72,13 +71,7 @@ export class WebSourceLocationService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
close(): Promise<void> {
|
close(): Promise<void> {
|
||||||
return closeOwnedWebResources(
|
return this.decoder.close?.() ?? Promise.resolve();
|
||||||
[
|
|
||||||
this.artifacts.close?.bind(this.artifacts),
|
|
||||||
this.decoder.close?.bind(this.decoder),
|
|
||||||
],
|
|
||||||
"Web source-location cleanup failed",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Shared CLI/MCP workflow preserves raw declarations and every equal-position match. */
|
/** Shared CLI/MCP workflow preserves raw declarations and every equal-position match. */
|
||||||
@@ -181,7 +174,6 @@ export class WebSourceLocationService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const invalidOutput = (message: string): Result<never, AnalysisError> =>
|
const invalidOutput = (message: string): Result<never, AnalysisError> =>
|
||||||
err(new AnalysisOutputError(OPERATION, message));
|
err(new AnalysisOutputError(OPERATION, message));
|
||||||
const invalid = (
|
const invalid = (
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import type { Result } from "../../domain/result.js";
|
|||||||
/** Stable read and PE decoding boundary, independent of an active disassembler session. */
|
/** Stable read and PE decoding boundary, independent of an active disassembler session. */
|
||||||
export interface PeResourcesPort {
|
export interface PeResourcesPort {
|
||||||
readonly identity: ProviderIdentity;
|
readonly identity: ProviderIdentity;
|
||||||
close?(): Promise<void>;
|
|
||||||
inspect(
|
inspect(
|
||||||
input: InspectPeResourcesInput,
|
input: InspectPeResourcesInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ import { err, ok, type Result } from "../../domain/result.js";
|
|||||||
export class PeResourcesService {
|
export class PeResourcesService {
|
||||||
constructor(readonly provider: PeResourcesPort) {}
|
constructor(readonly provider: PeResourcesPort) {}
|
||||||
|
|
||||||
close(): Promise<void> {
|
|
||||||
return this.provider.close?.() ?? Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
async inspect(
|
async inspect(
|
||||||
rawInput: unknown,
|
rawInput: unknown,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
import {
|
|
||||||
inspectPacketFieldsInputSchema,
|
|
||||||
packetFieldsCatalogSchema,
|
|
||||||
type InspectPacketFieldsInput,
|
|
||||||
} from "../../domain/captures/packetFields.js";
|
|
||||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
|
||||||
import { isAbsolute } from "node:path";
|
import { isAbsolute } from "node:path";
|
||||||
import type {
|
import type {
|
||||||
AnalysisExecution,
|
AnalysisExecution,
|
||||||
@@ -30,10 +24,6 @@ export interface PacketCapturePort {
|
|||||||
input: InspectPacketCaptureInput,
|
input: InspectPacketCaptureInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
): Promise<Result<AnalysisExecution, AnalysisError>>;
|
): Promise<Result<AnalysisExecution, AnalysisError>>;
|
||||||
inspectFields(
|
|
||||||
input: InspectPacketFieldsInput,
|
|
||||||
options?: ExecutionOptions,
|
|
||||||
): Promise<Result<AnalysisExecution, AnalysisError>>;
|
|
||||||
close(): Promise<void>;
|
close(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,58 +74,14 @@ export class PacketCaptureService {
|
|||||||
"Capture analyzer returned malformed data or changed the selected artifact identity/options.",
|
"Capture analyzer returned malformed data or changed the selected artifact identity/options.",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return this.#evidence(operation, input.data, execution, options);
|
const evidence = createEvidence(execution.subject, execution.provider, {
|
||||||
}
|
|
||||||
async inspectFields(
|
|
||||||
raw: unknown,
|
|
||||||
options?: ExecutionOptions,
|
|
||||||
): Promise<Result<Evidence, AnalysisError>> {
|
|
||||||
const operation = "inspect_packet_fields";
|
|
||||||
if (options?.signal?.aborted)
|
|
||||||
return err(new AnalysisCancelledError(operation));
|
|
||||||
const input = inspectPacketFieldsInputSchema.safeParse(raw);
|
|
||||||
if (!input.success)
|
|
||||||
return err(
|
|
||||||
analysisInputErrorFromIssues(operation, input.error.issues, raw, {
|
|
||||||
cause: input.error,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const decoded = await this.provider.inspectFields(input.data, options);
|
|
||||||
if (!decoded.ok) return decoded;
|
|
||||||
const execution = decoded.value;
|
|
||||||
const report = packetFieldsCatalogSchema.safeParse(execution.result);
|
|
||||||
if (
|
|
||||||
!report.success ||
|
|
||||||
JSON.stringify(report.data.selection) !== JSON.stringify(input.data) ||
|
|
||||||
execution.subject?.path !== report.data.tool.path ||
|
|
||||||
execution.subject.sha256 !== report.data.tool.sha256
|
|
||||||
)
|
|
||||||
return err(
|
|
||||||
new AnalysisOutputError(
|
|
||||||
operation,
|
operation,
|
||||||
"Field discovery returned malformed data or changed the selected installation/options.",
|
parameters: input.data,
|
||||||
),
|
result: report.data,
|
||||||
);
|
|
||||||
return this.#evidence(operation, input.data, execution, options);
|
|
||||||
}
|
|
||||||
#evidence(
|
|
||||||
operation: string,
|
|
||||||
parameters: Readonly<Record<string, JsonValue>>,
|
|
||||||
execution: AnalysisExecution,
|
|
||||||
options?: ExecutionOptions,
|
|
||||||
): Result<Evidence, AnalysisError> {
|
|
||||||
const evidence = createEvidence(
|
|
||||||
execution.subject ?? undefined,
|
|
||||||
execution.provider,
|
|
||||||
{
|
|
||||||
operation,
|
|
||||||
parameters,
|
|
||||||
result: execution.result,
|
|
||||||
confidence: "observed",
|
confidence: "observed",
|
||||||
locations: execution.locations,
|
locations: execution.locations,
|
||||||
limitations: execution.limitations,
|
limitations: execution.limitations,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
return options?.signal?.aborted
|
return options?.signal?.aborted
|
||||||
? err(
|
? err(
|
||||||
new AnalysisCancelledError(operation, {
|
new AnalysisCancelledError(operation, {
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
/** Attempt every web workflow cleanup owner and report all failures. */
|
|
||||||
export const closeOwnedWebResources = async (
|
|
||||||
close: readonly ((() => Promise<void>) | undefined)[],
|
|
||||||
message: string,
|
|
||||||
): Promise<void> => {
|
|
||||||
const results = await Promise.allSettled(
|
|
||||||
close.flatMap((owner) =>
|
|
||||||
owner === undefined ? [] : [Promise.resolve().then(owner)],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const failures = results.flatMap((result) =>
|
|
||||||
result.status === "rejected" ? [result.reason] : [],
|
|
||||||
);
|
|
||||||
if (failures.length > 0) throw new AggregateError(failures, message);
|
|
||||||
};
|
|
||||||
@@ -809,42 +809,6 @@ it("keeps an active script message bucket after its last message is evicted", as
|
|||||||
await manager.closeAll();
|
await manager.closeAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("retains the newest contiguous messages across repeated budget evictions", async () => {
|
|
||||||
const { bindings, manager, started } = await startLocalAttachedSession();
|
|
||||||
expect(started.ok).toBe(true);
|
|
||||||
if (!started.ok) return;
|
|
||||||
bindings.device.session.nextPayload = { index: -1 };
|
|
||||||
const loaded = await manager.loadScript(started.value.sessionId, {
|
|
||||||
sourceKind: "inline",
|
|
||||||
source: "send({index: -1});",
|
|
||||||
});
|
|
||||||
expect(loaded.ok).toBe(true);
|
|
||||||
const script = bindings.device.session.scripts[0];
|
|
||||||
expect(script).toBeDefined();
|
|
||||||
if (script === undefined) return;
|
|
||||||
|
|
||||||
// About 500 of these fit the 16 MiB budget, so 2,000 sends evict and
|
|
||||||
// compact the queue several times.
|
|
||||||
const filler = "x".repeat(32_000);
|
|
||||||
for (let index = 0; index < 2_000; index += 1)
|
|
||||||
script.message.emit({ type: "send", payload: { index, filler } }, null);
|
|
||||||
|
|
||||||
const status = manager.status(started.value.sessionId);
|
|
||||||
expect(status?.messagesTruncated).toBe(true);
|
|
||||||
const indexes = (status?.messages ?? []).map(
|
|
||||||
(message) => (message as { payload: { index: number } }).payload.index,
|
|
||||||
);
|
|
||||||
expect(indexes.length).toBeGreaterThan(400);
|
|
||||||
expect(indexes.at(-1)).toBe(1_999);
|
|
||||||
expect(indexes).toEqual(
|
|
||||||
Array.from(
|
|
||||||
{ length: indexes.length },
|
|
||||||
(_, offset) => 2_000 - indexes.length + offset,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await manager.closeAll();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("serializes a final remote release against a new same-endpoint session", async () => {
|
it("serializes a final remote release against a new same-endpoint session", async () => {
|
||||||
const bindings = new FakeDeviceManager();
|
const bindings = new FakeDeviceManager();
|
||||||
let enteredRemoval: (() => void) | undefined;
|
let enteredRemoval: (() => void) | undefined;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import type { Result } from "../../domain/result.js";
|
|||||||
/** Replaceable offline build-information reader with no target-execution authority. */
|
/** Replaceable offline build-information reader with no target-execution authority. */
|
||||||
export interface GoBinaryPort {
|
export interface GoBinaryPort {
|
||||||
readonly identity: ProviderIdentity;
|
readonly identity: ProviderIdentity;
|
||||||
close?(): Promise<void>;
|
|
||||||
inspect(
|
inspect(
|
||||||
input: InspectGoBinaryInput,
|
input: InspectGoBinaryInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ const architectureForSubject = (architecture: string) => {
|
|||||||
export class GoBinaryService {
|
export class GoBinaryService {
|
||||||
constructor(readonly provider: GoBinaryPort) {}
|
constructor(readonly provider: GoBinaryPort) {}
|
||||||
|
|
||||||
close(): Promise<void> {
|
|
||||||
return this.provider.close?.() ?? Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Inspect one explicitly selected file without acquiring a binary session. */
|
/** Inspect one explicitly selected file without acquiring a binary session. */
|
||||||
async inspect(
|
async inspect(
|
||||||
rawInput: unknown,
|
rawInput: unknown,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
|
|
||||||
import { moduleResolutionModeForJavaScriptReference } from "../../domain/javascript/javascriptModuleResolutionMode.js";
|
import { moduleKindForJavaScriptReference } from "./JavaScriptArtifactPathResolution.js";
|
||||||
import { setImmediate } from "node:timers/promises";
|
import { setImmediate } from "node:timers/promises";
|
||||||
|
|
||||||
import { resolveJavaScriptSourceMapReferences } from "../../domain/javascript/javascriptSourceMapPaths.js";
|
import { resolveJavaScriptSourceMapReferences } from "../../domain/javascript/javascriptSourceMapPaths.js";
|
||||||
@@ -384,10 +384,7 @@ function* analyzeArtifactFileSteps<
|
|||||||
analysis.parse_status === "complete" || analysis.parse_status === "partial"
|
analysis.parse_status === "complete" || analysis.parse_status === "partial"
|
||||||
? yield* analyzeParsedJavaScriptSemanticsSteps(
|
? yield* analyzeParsedJavaScriptSemanticsSteps(
|
||||||
parsed,
|
parsed,
|
||||||
moduleResolutionModeForJavaScriptReference(
|
moduleKindForJavaScriptReference(file.path, "static-import"),
|
||||||
file.path,
|
|
||||||
"static-import",
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
const projected =
|
const projected =
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ export interface AstEdgeInput {
|
|||||||
|
|
||||||
/** Inferred static relationship edge values. */
|
/** Inferred static relationship edge values. */
|
||||||
export interface InferenceEdgeInput extends AstEdgeInput {
|
export interface InferenceEdgeInput extends AstEdgeInput {
|
||||||
readonly limitations?: readonly string[];
|
|
||||||
readonly relation:
|
readonly relation:
|
||||||
| "imports"
|
| "imports"
|
||||||
| "loads"
|
| "loads"
|
||||||
@@ -163,9 +162,6 @@ export const addStaticInferenceEdge = (
|
|||||||
range: input.range,
|
range: input.range,
|
||||||
operation: "map-static-relationship",
|
operation: "map-static-relationship",
|
||||||
coverage: input.coverage,
|
coverage: input.coverage,
|
||||||
...(input.limitations === undefined
|
|
||||||
? {}
|
|
||||||
: { limitations: input.limitations }),
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -351,7 +347,7 @@ export const resolveArtifactPath = (
|
|||||||
specifier: string,
|
specifier: string,
|
||||||
sourcePath: string,
|
sourcePath: string,
|
||||||
files: ReadonlyMap<string, JavaScriptArtifactFile>,
|
files: ReadonlyMap<string, JavaScriptArtifactFile>,
|
||||||
moduleKind?: "import" | "require" | "compiler-dependent",
|
moduleKind?: "import" | "require",
|
||||||
): string | null =>
|
): string | null =>
|
||||||
resolveArtifactPathByContext({
|
resolveArtifactPathByContext({
|
||||||
declaredPath: specifier,
|
declaredPath: specifier,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
javascriptAnalysisCoverage,
|
javascriptAnalysisCoverage,
|
||||||
linkElectronRoleToAsset,
|
linkElectronRoleToAsset,
|
||||||
moduleLookupKey,
|
moduleLookupKey,
|
||||||
|
resolveArtifactPath,
|
||||||
selfReferenceOmissions,
|
selfReferenceOmissions,
|
||||||
sourceNodeFor,
|
sourceNodeFor,
|
||||||
type JavaScriptArtifactGraphContext,
|
type JavaScriptArtifactGraphContext,
|
||||||
@@ -22,11 +23,9 @@ import {
|
|||||||
staticInferenceEvidence,
|
staticInferenceEvidence,
|
||||||
} from "./JavaScriptArtifactGraphEvidence.js";
|
} from "./JavaScriptArtifactGraphEvidence.js";
|
||||||
import {
|
import {
|
||||||
artifactPathResolutionProperties,
|
moduleKindForJavaScriptReference,
|
||||||
resolveArtifactPathByContext,
|
resolveArtifactPathByContext,
|
||||||
type ArtifactPathResolution,
|
|
||||||
} from "./JavaScriptArtifactPathResolution.js";
|
} from "./JavaScriptArtifactPathResolution.js";
|
||||||
import { moduleResolutionModeForJavaScriptReference } from "../../domain/javascript/javascriptModuleResolutionMode.js";
|
|
||||||
|
|
||||||
type StaticReference = JavaScriptStaticAnalysis["references"][number];
|
type StaticReference = JavaScriptStaticAnalysis["references"][number];
|
||||||
type StaticEndpoint = JavaScriptStaticAnalysis["endpoints"][number];
|
type StaticEndpoint = JavaScriptStaticAnalysis["endpoints"][number];
|
||||||
@@ -42,12 +41,9 @@ interface FindingInput<Value> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ResolvedReference {
|
interface ResolvedReference {
|
||||||
readonly path: string | null;
|
readonly path: string;
|
||||||
readonly file: JavaScriptArtifactFile | null;
|
readonly file: JavaScriptArtifactFile;
|
||||||
readonly node: ApplicationNode;
|
readonly node: ApplicationNode;
|
||||||
readonly limitations: readonly string[];
|
|
||||||
readonly resolutionStatus?: string;
|
|
||||||
readonly resolution?: ArtifactPathResolution;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Project imports, workers, roles, endpoints, storage, and source-map links. */
|
/** Project imports, workers, roles, endpoints, storage, and source-map links. */
|
||||||
@@ -94,7 +90,7 @@ const addReference = (
|
|||||||
const resolved =
|
const resolved =
|
||||||
input.value.specifier === null
|
input.value.specifier === null
|
||||||
? null
|
? null
|
||||||
: resolveReference(context, input.file.path, input.value, input.coverage);
|
: resolveReference(context, input.file.path, input.value);
|
||||||
if (input.value.kind === "worker" || input.value.kind === "service-worker") {
|
if (input.value.kind === "worker" || input.value.kind === "service-worker") {
|
||||||
const worker = context.accumulator.addNode({
|
const worker = context.accumulator.addNode({
|
||||||
kind: input.value.kind === "worker" ? "worker" : "service-worker",
|
kind: input.value.kind === "worker" ? "worker" : "service-worker",
|
||||||
@@ -130,7 +126,7 @@ const addReference = (
|
|||||||
relation: "loads",
|
relation: "loads",
|
||||||
properties: { kind: input.value.kind },
|
properties: { kind: input.value.kind },
|
||||||
});
|
});
|
||||||
if (resolved !== null && resolved.path !== null)
|
if (resolved !== null)
|
||||||
addStaticInferenceEdge(context, {
|
addStaticInferenceEdge(context, {
|
||||||
source: worker,
|
source: worker,
|
||||||
target: resolved.node,
|
target: resolved.node,
|
||||||
@@ -139,7 +135,6 @@ const addReference = (
|
|||||||
coverage: input.coverage,
|
coverage: input.coverage,
|
||||||
relation: "maps_to",
|
relation: "maps_to",
|
||||||
properties: { resolved_path: resolved.path },
|
properties: { resolved_path: resolved.path },
|
||||||
limitations: resolved.limitations,
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -159,25 +154,13 @@ const addReference = (
|
|||||||
file: input.file,
|
file: input.file,
|
||||||
range: input.value.location,
|
range: input.value.location,
|
||||||
coverage: input.coverage,
|
coverage: input.coverage,
|
||||||
relation: resolved?.file?.kind === "native-addon" ? "loads" : "imports",
|
relation: resolved?.file.kind === "native-addon" ? "loads" : "imports",
|
||||||
properties: {
|
properties: {
|
||||||
kind: input.value.kind,
|
kind: input.value.kind,
|
||||||
specifier: input.value.specifier,
|
specifier: input.value.specifier,
|
||||||
expression: input.value.expression,
|
expression: input.value.expression,
|
||||||
resolution_mode:
|
|
||||||
input.value.kind === "static-import" ||
|
|
||||||
input.value.kind === "dynamic-import" ||
|
|
||||||
input.value.kind === "require"
|
|
||||||
? moduleResolutionModeForJavaScriptReference(
|
|
||||||
input.file.path,
|
|
||||||
input.value.kind,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
resolved_path: resolved?.path ?? null,
|
resolved_path: resolved?.path ?? null,
|
||||||
resolution_status: resolved?.resolutionStatus ?? null,
|
|
||||||
...artifactPathResolutionProperties(resolved?.resolution),
|
|
||||||
},
|
},
|
||||||
...(resolved === null ? {} : { limitations: resolved.limitations }),
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -390,7 +373,6 @@ const resolveReference = (
|
|||||||
context: JavaScriptArtifactGraphContext,
|
context: JavaScriptArtifactGraphContext,
|
||||||
sourcePath: string,
|
sourcePath: string,
|
||||||
reference: StaticReference,
|
reference: StaticReference,
|
||||||
coverage: JavaScriptArtifactGraphCoverage,
|
|
||||||
): ResolvedReference | null => {
|
): ResolvedReference | null => {
|
||||||
const specifier = reference.specifier;
|
const specifier = reference.specifier;
|
||||||
if (specifier === null) return null;
|
if (specifier === null) return null;
|
||||||
@@ -410,70 +392,30 @@ const resolveReference = (
|
|||||||
const file = context.filesByPath.get(sourcePath);
|
const file = context.filesByPath.get(sourcePath);
|
||||||
return file === undefined
|
return file === undefined
|
||||||
? null
|
? null
|
||||||
: {
|
: { path: `${sourcePath}#module:${specifier}`, file, node: module };
|
||||||
path: `${sourcePath}#module:${specifier}`,
|
|
||||||
file,
|
|
||||||
node: module,
|
|
||||||
limitations: [],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
// Worker scripts are URLs relative to the script, not module specifiers.
|
// Worker scripts are URLs relative to the script, not module specifiers.
|
||||||
const resolution = isWorker
|
const path = isWorker
|
||||||
? resolveArtifactPathByContext({
|
? resolveArtifactPathByContext({
|
||||||
declaredPath: specifier,
|
declaredPath: specifier,
|
||||||
sourcePath,
|
sourcePath,
|
||||||
context: "url-reference",
|
context: "url-reference",
|
||||||
files: context.filesByPath,
|
files: context.filesByPath,
|
||||||
})
|
}).resolved_path
|
||||||
: resolveArtifactPathByContext({
|
: resolveArtifactPath(
|
||||||
declaredPath: specifier,
|
specifier,
|
||||||
sourcePath,
|
sourcePath,
|
||||||
context: "module-specifier",
|
context.filesByPath,
|
||||||
files: context.filesByPath,
|
reference.kind === "require" ||
|
||||||
...("require" === reference.kind ||
|
reference.kind === "static-import" ||
|
||||||
"static-import" === reference.kind ||
|
reference.kind === "dynamic-import"
|
||||||
"dynamic-import" === reference.kind
|
? moduleKindForJavaScriptReference(sourcePath, reference.kind)
|
||||||
? {
|
: undefined,
|
||||||
moduleKind: moduleResolutionModeForJavaScriptReference(
|
);
|
||||||
sourcePath,
|
if (path === null) return null;
|
||||||
reference.kind,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
});
|
|
||||||
const path = resolution.resolved_path;
|
|
||||||
if (path === null) {
|
|
||||||
if (isWorker) return null;
|
|
||||||
const source = context.filesByPath.get(sourcePath);
|
|
||||||
return source === undefined
|
|
||||||
? null
|
|
||||||
: {
|
|
||||||
path: null,
|
|
||||||
file: null,
|
|
||||||
node: unresolvedReferenceNode(
|
|
||||||
context,
|
|
||||||
source,
|
|
||||||
reference,
|
|
||||||
coverage,
|
|
||||||
resolution,
|
|
||||||
),
|
|
||||||
limitations: resolution.limitations,
|
|
||||||
resolutionStatus: resolution.resolution_status,
|
|
||||||
resolution,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const file = context.filesByPath.get(path);
|
const file = context.filesByPath.get(path);
|
||||||
const node = context.fileNodes.get(path);
|
const node = context.fileNodes.get(path);
|
||||||
return file === undefined || node === undefined
|
return file === undefined || node === undefined ? null : { path, file, node };
|
||||||
? null
|
|
||||||
: {
|
|
||||||
path,
|
|
||||||
file,
|
|
||||||
node,
|
|
||||||
limitations: resolution.limitations,
|
|
||||||
resolutionStatus: resolution.resolution_status,
|
|
||||||
resolution,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const resolveBundlerChunkReference = (
|
const resolveBundlerChunkReference = (
|
||||||
@@ -511,7 +453,7 @@ const resolveBundlerChunkReference = (
|
|||||||
const node = unique[0];
|
const node = unique[0];
|
||||||
return node === undefined
|
return node === undefined
|
||||||
? null
|
? null
|
||||||
: { path: `${sourcePath}#chunk:${key}`, file, node, limitations: [] };
|
: { path: `${sourcePath}#chunk:${key}`, file, node };
|
||||||
};
|
};
|
||||||
|
|
||||||
const unresolvedReferenceNode = (
|
const unresolvedReferenceNode = (
|
||||||
@@ -519,7 +461,6 @@ const unresolvedReferenceNode = (
|
|||||||
file: JavaScriptArtifactFile,
|
file: JavaScriptArtifactFile,
|
||||||
reference: StaticReference,
|
reference: StaticReference,
|
||||||
coverage: JavaScriptArtifactGraphCoverage,
|
coverage: JavaScriptArtifactGraphCoverage,
|
||||||
resolution?: ArtifactPathResolution,
|
|
||||||
): ApplicationNode =>
|
): ApplicationNode =>
|
||||||
context.accumulator.addNode({
|
context.accumulator.addNode({
|
||||||
kind: "javascript-module",
|
kind: "javascript-module",
|
||||||
@@ -536,10 +477,6 @@ const unresolvedReferenceNode = (
|
|||||||
specifier: reference.specifier,
|
specifier: reference.specifier,
|
||||||
expression: reference.expression,
|
expression: reference.expression,
|
||||||
resolution: "unresolved",
|
resolution: "unresolved",
|
||||||
...(resolution === undefined
|
|
||||||
? {}
|
|
||||||
: { resolution_status: resolution.resolution_status }),
|
|
||||||
...artifactPathResolutionProperties(resolution),
|
|
||||||
},
|
},
|
||||||
evidence: staticInferenceEvidence({
|
evidence: staticInferenceEvidence({
|
||||||
sha256: file.sha256,
|
sha256: file.sha256,
|
||||||
@@ -550,7 +487,6 @@ const unresolvedReferenceNode = (
|
|||||||
confidence: "low",
|
confidence: "low",
|
||||||
limitations: [
|
limitations: [
|
||||||
"The static reference could not be resolved within the inventoried artifact.",
|
"The static reference could not be resolved within the inventoried artifact.",
|
||||||
...(resolution?.limitations ?? []),
|
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1890,42 +1890,23 @@ describe("TypeScript NodeNext emitted-extension resolution", () => {
|
|||||||
).toMatchObject({ resolution_status: "resolved", resolved_path: target });
|
).toMatchObject({ resolution_status: "resolved", resolved_path: target });
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
describe("TypeScript declaration fallback ownership", () => {
|
|
||||||
const container = "container";
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
["./dep.js", "src/dep.d.ts"],
|
["./dep.js", "src/dep.d.ts"],
|
||||||
["./cfg.mjs", "src/cfg.d.mts"],
|
["./cfg.mjs", "src/cfg.d.mts"],
|
||||||
["./legacy.cjs", "src/legacy.d.cts"],
|
["./legacy.cjs", "src/legacy.d.cts"],
|
||||||
] as const)(
|
] as const)(
|
||||||
"retains %s as compile-time evidence without inventing a runtime target",
|
"resolves %s to a declaration counterpart",
|
||||||
(specifier, target) => {
|
(specifier, target) => {
|
||||||
const files = fileMap([
|
const files = fileMap([
|
||||||
file("src/main.ts", container),
|
file("src/main.ts", container),
|
||||||
file(target, container, "export const value = 1;"),
|
file(target, container, "export const value = 1;"),
|
||||||
]);
|
]);
|
||||||
for (const moduleKind of ["import", "require"] as const) {
|
|
||||||
expect(
|
expect(
|
||||||
resolve({
|
resolve({
|
||||||
declaredPath: specifier,
|
declaredPath: specifier,
|
||||||
sourcePath: "src/main.ts",
|
sourcePath: "src/main.ts",
|
||||||
context: "module-specifier",
|
context: "module-specifier",
|
||||||
moduleKind,
|
|
||||||
files,
|
|
||||||
}),
|
|
||||||
).toMatchObject({
|
|
||||||
resolution_status: "unavailable",
|
|
||||||
resolved_path: null,
|
|
||||||
candidate_path: target,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect(
|
|
||||||
resolve({
|
|
||||||
declaredPath: "./" + target.slice(4),
|
|
||||||
sourcePath: "src/main.ts",
|
|
||||||
context: "module-specifier",
|
|
||||||
moduleKind: "import",
|
moduleKind: "import",
|
||||||
files,
|
files,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -19,13 +19,7 @@ import {
|
|||||||
classifyPackageImportTargetString,
|
classifyPackageImportTargetString,
|
||||||
lookupExactPackageImport,
|
lookupExactPackageImport,
|
||||||
} from "../../domain/javascript/javascriptPackageImportAliases.js";
|
} from "../../domain/javascript/javascriptPackageImportAliases.js";
|
||||||
import {
|
import { typescriptEmittedSourceCandidates } from "../TypeScriptEmittedSourceCandidates.js";
|
||||||
typescriptEmittedSourceCandidates,
|
|
||||||
type TypeScriptEmittedSourceCandidate,
|
|
||||||
} from "../TypeScriptEmittedSourceCandidates.js";
|
|
||||||
import { isRelativeJavaScriptModuleSpecifier } from "../../domain/javascript/javascriptModuleSpecifier.js";
|
|
||||||
import type { JavaScriptModuleResolutionMode } from "../../domain/javascript/javascriptModuleResolutionMode.js";
|
|
||||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
|
||||||
|
|
||||||
type ArtifactPathResolutionContext =
|
type ArtifactPathResolutionContext =
|
||||||
| "package-entrypoint"
|
| "package-entrypoint"
|
||||||
@@ -44,16 +38,6 @@ interface ArtifactPathResolutionBase {
|
|||||||
readonly declared_path: string;
|
readonly declared_path: string;
|
||||||
readonly resolution_context: ArtifactPathResolutionContext;
|
readonly resolution_context: ArtifactPathResolutionContext;
|
||||||
readonly limitations: readonly string[];
|
readonly limitations: readonly string[];
|
||||||
readonly conditional_resolutions?: readonly ConditionalModuleResolution[];
|
|
||||||
readonly candidate_path?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ConditionalModuleResolution {
|
|
||||||
readonly mode: "import" | "require";
|
|
||||||
readonly resolution_status: UnresolvedArtifactPathStatus | "resolved";
|
|
||||||
readonly resolved_path: string | null;
|
|
||||||
readonly candidate_path?: string;
|
|
||||||
readonly limitations: readonly string[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Explicit outcome of artifact-confined path resolution. */
|
/** Explicit outcome of artifact-confined path resolution. */
|
||||||
@@ -77,13 +61,26 @@ export interface ResolveArtifactPathInput {
|
|||||||
readonly files: ReadonlyMap<string, JavaScriptArtifactFile>;
|
readonly files: ReadonlyMap<string, JavaScriptArtifactFile>;
|
||||||
readonly htmlBaseHref?: string | null;
|
readonly htmlBaseHref?: string | null;
|
||||||
/** Import/require semantics; runtime resource paths omit this provenance. */
|
/** Import/require semantics; runtime resource paths omit this provenance. */
|
||||||
readonly moduleKind?: JavaScriptModuleResolutionMode;
|
readonly moduleKind?: "import" | "require";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Loader selected by a source-level JavaScript module reference. */
|
||||||
|
export const moduleKindForJavaScriptReference = (
|
||||||
|
sourcePath: string,
|
||||||
|
referenceKind: "static-import" | "dynamic-import" | "require",
|
||||||
|
resolutionMode?: "import" | "require",
|
||||||
|
): "import" | "require" =>
|
||||||
|
resolutionMode ??
|
||||||
|
(referenceKind === "require" ||
|
||||||
|
(referenceKind === "static-import" &&
|
||||||
|
posix.extname(sourcePath).toLowerCase() === ".cts")
|
||||||
|
? "require"
|
||||||
|
: "import");
|
||||||
|
|
||||||
/** Preserve an explicitly retained loader mode on graph relationships. */
|
/** Preserve an explicitly retained loader mode on graph relationships. */
|
||||||
export const moduleResolutionModeProperties = (
|
export const moduleResolutionModeProperties = (
|
||||||
mode: JavaScriptModuleResolutionMode | undefined,
|
mode: "import" | "require" | undefined,
|
||||||
): Readonly<Record<string, JavaScriptModuleResolutionMode>> =>
|
): Readonly<Record<string, "import" | "require">> =>
|
||||||
mode === undefined ? {} : { resolution_mode: mode };
|
mode === undefined ? {} : { resolution_mode: mode };
|
||||||
|
|
||||||
const EXTENSIONS = [
|
const EXTENSIONS = [
|
||||||
@@ -112,116 +109,43 @@ interface PackageFileTarget {
|
|||||||
readonly url: URL;
|
readonly url: URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CandidateResolution = {
|
type CandidateResolution =
|
||||||
|
| {
|
||||||
|
readonly resolvedPath: string;
|
||||||
|
readonly status: "resolved";
|
||||||
readonly limitations: readonly string[];
|
readonly limitations: readonly string[];
|
||||||
readonly candidatePath?: string;
|
}
|
||||||
readonly conditionalResolutions?: readonly ConditionalModuleResolution[];
|
|
||||||
} & (
|
|
||||||
| { readonly resolvedPath: string; readonly status: "resolved" }
|
|
||||||
| {
|
| {
|
||||||
readonly resolvedPath: null;
|
readonly resolvedPath: null;
|
||||||
readonly status: UnresolvedArtifactPathStatus;
|
readonly status: UnresolvedArtifactPathStatus;
|
||||||
|
readonly limitations: readonly string[];
|
||||||
/** A truthy package main failed, so Node must not try ancestor packages. */
|
/** A truthy package main failed, so Node must not try ancestor packages. */
|
||||||
readonly stopsAncestorLookup?: true;
|
readonly stopsAncestorLookup?: true;
|
||||||
}
|
};
|
||||||
);
|
|
||||||
|
|
||||||
/** Resolve one declaration while preserving its original input identity. */
|
/** Resolve one declaration while preserving its original input identity. */
|
||||||
export const resolveArtifactPathByContext = (
|
export const resolveArtifactPathByContext = (
|
||||||
input: ResolveArtifactPathInput,
|
input: ResolveArtifactPathInput,
|
||||||
): ArtifactPathResolution => {
|
): ArtifactPathResolution => {
|
||||||
const resolution = resolvePath(input);
|
const resolution = resolvePath(input);
|
||||||
const facts = {
|
|
||||||
declared_path: input.declaredPath,
|
|
||||||
resolution_context: input.context,
|
|
||||||
limitations: resolution.limitations,
|
|
||||||
...(resolution.candidatePath === undefined
|
|
||||||
? {}
|
|
||||||
: { candidate_path: resolution.candidatePath }),
|
|
||||||
...(resolution.conditionalResolutions === undefined
|
|
||||||
? {}
|
|
||||||
: { conditional_resolutions: resolution.conditionalResolutions }),
|
|
||||||
};
|
|
||||||
return resolution.status === "resolved"
|
return resolution.status === "resolved"
|
||||||
? {
|
? {
|
||||||
...facts,
|
declared_path: input.declaredPath,
|
||||||
|
resolution_context: input.context,
|
||||||
resolved_path: resolution.resolvedPath,
|
resolved_path: resolution.resolvedPath,
|
||||||
resolution_status: resolution.status,
|
resolution_status: resolution.status,
|
||||||
|
limitations: resolution.limitations,
|
||||||
}
|
}
|
||||||
: { ...facts, resolved_path: null, resolution_status: resolution.status };
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Project retained conditional identities without flattening them into display text. */
|
|
||||||
export const artifactPathResolutionProperties = (
|
|
||||||
resolution: ArtifactPathResolution | undefined,
|
|
||||||
): Readonly<Record<string, JsonValue>> => ({
|
|
||||||
...(resolution?.candidate_path === undefined
|
|
||||||
? {}
|
|
||||||
: { candidate_path: resolution.candidate_path }),
|
|
||||||
...(resolution?.conditional_resolutions === undefined
|
|
||||||
? {}
|
|
||||||
: {
|
: {
|
||||||
conditional_resolutions: resolution.conditional_resolutions.map(
|
declared_path: input.declaredPath,
|
||||||
(branch) => ({
|
resolution_context: input.context,
|
||||||
mode: branch.mode,
|
resolved_path: null,
|
||||||
resolution_status: branch.resolution_status,
|
resolution_status: resolution.status,
|
||||||
resolved_path: branch.resolved_path,
|
limitations: resolution.limitations,
|
||||||
limitations: [...branch.limitations],
|
};
|
||||||
...(branch.candidate_path === undefined
|
};
|
||||||
? {}
|
|
||||||
: { candidate_path: branch.candidate_path }),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const conditionalResolution = (
|
|
||||||
mode: "import" | "require",
|
|
||||||
result: CandidateResolution,
|
|
||||||
): ConditionalModuleResolution => ({
|
|
||||||
mode,
|
|
||||||
resolution_status: result.status,
|
|
||||||
resolved_path: result.resolvedPath,
|
|
||||||
limitations: result.limitations,
|
|
||||||
...(result.candidatePath === undefined
|
|
||||||
? {}
|
|
||||||
: { candidate_path: result.candidatePath }),
|
|
||||||
});
|
|
||||||
|
|
||||||
const resolvePath = (input: ResolveArtifactPathInput): CandidateResolution => {
|
const resolvePath = (input: ResolveArtifactPathInput): CandidateResolution => {
|
||||||
if (input.moduleKind === "compiler-dependent") {
|
|
||||||
const imported = resolvePath({ ...input, moduleKind: "import" });
|
|
||||||
const required = resolvePath({ ...input, moduleKind: "require" });
|
|
||||||
const sameOutcome =
|
|
||||||
imported.status === required.status &&
|
|
||||||
imported.resolvedPath === required.resolvedPath &&
|
|
||||||
imported.candidatePath === required.candidatePath;
|
|
||||||
const limitation =
|
|
||||||
"Static TypeScript loader mode is compiler-dependent without retained compiler options. " +
|
|
||||||
(sameOutcome
|
|
||||||
? "Node import and require resolution agree on this outcome."
|
|
||||||
: "Node import and require resolution disagree; neither branch is an established target.");
|
|
||||||
return sameOutcome
|
|
||||||
? {
|
|
||||||
...imported,
|
|
||||||
limitations: [
|
|
||||||
...new Set([
|
|
||||||
...imported.limitations,
|
|
||||||
...required.limitations,
|
|
||||||
limitation,
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
resolvedPath: null,
|
|
||||||
status: "unavailable",
|
|
||||||
limitations: [limitation],
|
|
||||||
conditionalResolutions: [
|
|
||||||
conditionalResolution("import", imported),
|
|
||||||
conditionalResolution("require", required),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// Package import keys are literal lookup identities, not artifact paths.
|
// Package import keys are literal lookup identities, not artifact paths.
|
||||||
// The selected target is admitted separately by resolveExportTarget.
|
// The selected target is admitted separately by resolveExportTarget.
|
||||||
if (
|
if (
|
||||||
@@ -242,7 +166,7 @@ const resolvePath = (input: ResolveArtifactPathInput): CandidateResolution => {
|
|||||||
);
|
);
|
||||||
const isModuleUrlPath =
|
const isModuleUrlPath =
|
||||||
input.context === "module-specifier" &&
|
input.context === "module-specifier" &&
|
||||||
(isRelativeJavaScriptModuleSpecifier(input.declaredPath) ||
|
(input.declaredPath.startsWith(".") ||
|
||||||
input.declaredPath.startsWith("/") ||
|
input.declaredPath.startsWith("/") ||
|
||||||
fileUrlPath(input.declaredPath) !== undefined);
|
fileUrlPath(input.declaredPath) !== undefined);
|
||||||
const emittedSourceCandidates =
|
const emittedSourceCandidates =
|
||||||
@@ -251,47 +175,12 @@ const resolvePath = (input: ResolveArtifactPathInput): CandidateResolution => {
|
|||||||
: [];
|
: [];
|
||||||
if (isModuleUrlPath && input.moduleKind === "import")
|
if (isModuleUrlPath && input.moduleKind === "import")
|
||||||
return (
|
return (
|
||||||
resolveRuntimeSourceCandidates(
|
resolveFileCandidates(input, [confined, ...emittedSourceCandidates]) ??
|
||||||
input,
|
notFoundCandidate()
|
||||||
confined,
|
|
||||||
emittedSourceCandidates,
|
|
||||||
) ?? notFoundCandidate()
|
|
||||||
);
|
);
|
||||||
return resolveCandidate(input, confined, new Set(), emittedSourceCandidates);
|
return resolveCandidate(input, confined, new Set(), emittedSourceCandidates);
|
||||||
};
|
};
|
||||||
|
|
||||||
const resolveRuntimeSourceCandidates = (
|
|
||||||
input: ResolveArtifactPathInput,
|
|
||||||
exactPath: string,
|
|
||||||
sourceCandidates: readonly TypeScriptEmittedSourceCandidate[],
|
|
||||||
): CandidateResolution | null => {
|
|
||||||
const source = input.files.get(input.sourcePath);
|
|
||||||
const exactCandidate: TypeScriptEmittedSourceCandidate = {
|
|
||||||
path: exactPath,
|
|
||||||
kind: "implementation",
|
|
||||||
};
|
|
||||||
for (const candidate of [exactCandidate, ...sourceCandidates]) {
|
|
||||||
const target = input.files.get(candidate.path);
|
|
||||||
if (
|
|
||||||
target === undefined ||
|
|
||||||
(source !== undefined &&
|
|
||||||
target.container_sha256 !== source.container_sha256)
|
|
||||||
)
|
|
||||||
continue;
|
|
||||||
return candidate.kind === "declaration"
|
|
||||||
? {
|
|
||||||
resolvedPath: null,
|
|
||||||
status: "unavailable",
|
|
||||||
candidatePath: candidate.path,
|
|
||||||
limitations: [
|
|
||||||
"Only a TypeScript declaration fallback was found; it does not establish the requested runtime module.",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
: { resolvedPath: candidate.path, status: "resolved", limitations: [] };
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const rejectDeclaration = (declared: string): CandidateResolution | null => {
|
const rejectDeclaration = (declared: string): CandidateResolution | null => {
|
||||||
if (declared.length === 0)
|
if (declared.length === 0)
|
||||||
return unresolvedCandidate("rejected", ["The declared path is empty."]);
|
return unresolvedCandidate("rejected", ["The declared path is empty."]);
|
||||||
@@ -340,10 +229,7 @@ const contextualCandidate = (
|
|||||||
return unresolvedCandidate("external", [
|
return unresolvedCandidate("external", [
|
||||||
"URL and Node builtin schemes are outside static artifact module resolution.",
|
"URL and Node builtin schemes are outside static artifact module resolution.",
|
||||||
]);
|
]);
|
||||||
if (
|
if (!declared.startsWith(".") && !declared.startsWith("/"))
|
||||||
!isRelativeJavaScriptModuleSpecifier(declared) &&
|
|
||||||
!declared.startsWith("/")
|
|
||||||
)
|
|
||||||
return bareModuleCandidate(input);
|
return bareModuleCandidate(input);
|
||||||
if (input.moduleKind !== "require") {
|
if (input.moduleKind !== "require") {
|
||||||
const decoded = decodeModuleUrlPath(stripQueryAndFragment(declared));
|
const decoded = decodeModuleUrlPath(stripQueryAndFragment(declared));
|
||||||
@@ -389,10 +275,7 @@ const contextualCandidate = (
|
|||||||
"URL",
|
"URL",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const candidate = relativeCandidate(input.sourcePath, declared);
|
return relativeCandidate(input.sourcePath, declared);
|
||||||
return context === "module-specifier" && input.moduleKind === "import"
|
|
||||||
? exactUrlPathCandidate(declared, candidate, "module URL")
|
|
||||||
: candidate;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const decodeModuleUrlPath = (
|
const decodeModuleUrlPath = (
|
||||||
@@ -427,12 +310,9 @@ const bareModuleCandidate = (
|
|||||||
return unresolvedCandidate("external", [
|
return unresolvedCandidate("external", [
|
||||||
"The bare specifier is a Node builtin or invalid package name.",
|
"The bare specifier is a Node builtin or invalid package name.",
|
||||||
]);
|
]);
|
||||||
if (
|
if (input.moduleKind === "import" && request.packageName.includes("%"))
|
||||||
input.moduleKind === "import" &&
|
|
||||||
(request.packageName.startsWith(".") || request.packageName.includes("%"))
|
|
||||||
)
|
|
||||||
return unresolvedCandidate("rejected", [
|
return unresolvedCandidate("rejected", [
|
||||||
"ES module package names cannot start with a dot or contain percent signs.",
|
"Percent signs are not admitted in ES module package names.",
|
||||||
]);
|
]);
|
||||||
const self = packageSelfCandidate(input, request);
|
const self = packageSelfCandidate(input, request);
|
||||||
if (self !== null) return self;
|
if (self !== null) return self;
|
||||||
@@ -855,7 +735,7 @@ const htmlCandidate = (
|
|||||||
const exactUrlPathCandidate = (
|
const exactUrlPathCandidate = (
|
||||||
declared: string,
|
declared: string,
|
||||||
candidate: string,
|
candidate: string,
|
||||||
kind: "HTML" | "URL" | "module URL",
|
kind: "HTML" | "URL",
|
||||||
): string | CandidateResolution => {
|
): string | CandidateResolution => {
|
||||||
if (!urlPathIsDirectory(declared)) return candidate;
|
if (!urlPathIsDirectory(declared)) return candidate;
|
||||||
const confined = confineCandidate(candidate);
|
const confined = confineCandidate(candidate);
|
||||||
@@ -959,10 +839,12 @@ const resolveCandidate = (
|
|||||||
input: ResolveArtifactPathInput,
|
input: ResolveArtifactPathInput,
|
||||||
candidate: string,
|
candidate: string,
|
||||||
packageChain: ReadonlySet<string>,
|
packageChain: ReadonlySet<string>,
|
||||||
emittedSourceCandidates: readonly TypeScriptEmittedSourceCandidate[] = [],
|
emittedSourceCandidates: readonly string[] = [],
|
||||||
): CandidateResolution =>
|
): CandidateResolution =>
|
||||||
resolveFileCandidates(input, fileCandidates(candidate, input.moduleKind)) ??
|
resolveFileCandidates(input, [
|
||||||
resolveRuntimeSourceCandidates(input, candidate, emittedSourceCandidates) ??
|
...fileCandidates(candidate, input.moduleKind),
|
||||||
|
...emittedSourceCandidates,
|
||||||
|
]) ??
|
||||||
resolveDirectory(
|
resolveDirectory(
|
||||||
input,
|
input,
|
||||||
candidate,
|
candidate,
|
||||||
@@ -1048,26 +930,11 @@ const resolveFileCandidates = (
|
|||||||
(source === undefined ||
|
(source === undefined ||
|
||||||
target.container_sha256 === source.container_sha256)
|
target.container_sha256 === source.container_sha256)
|
||||||
)
|
)
|
||||||
return isRuntimeDeclarationPath(input, path)
|
return { resolvedPath: path, status: "resolved", limitations: [] };
|
||||||
? {
|
|
||||||
resolvedPath: null,
|
|
||||||
status: "unavailable",
|
|
||||||
candidatePath: path,
|
|
||||||
limitations: [
|
|
||||||
`The TypeScript declaration ${path} is compile-time evidence and cannot identify a runtime module implementation.`,
|
|
||||||
],
|
|
||||||
}
|
|
||||||
: { resolvedPath: path, status: "resolved", limitations: [] };
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const isRuntimeDeclarationPath = (
|
|
||||||
input: ResolveArtifactPathInput,
|
|
||||||
path: string,
|
|
||||||
): boolean =>
|
|
||||||
input.moduleKind !== undefined && /\.d\.(?:ts|mts|cts)$/iu.test(path);
|
|
||||||
|
|
||||||
const NODE_MODULE_EXTENSIONS = [".js", ".json", ".node"] as const;
|
const NODE_MODULE_EXTENSIONS = [".js", ".json", ".node"] as const;
|
||||||
|
|
||||||
const fileCandidates = (
|
const fileCandidates = (
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import type {
|
|||||||
JavaScriptModuleOrigin,
|
JavaScriptModuleOrigin,
|
||||||
JavaScriptSemanticModuleLink,
|
JavaScriptSemanticModuleLink,
|
||||||
} from "../../domain/javascript/javascriptSemanticIr.js";
|
} from "../../domain/javascript/javascriptSemanticIr.js";
|
||||||
import { moduleResolutionModeForJavaScriptReference } from "../../domain/javascript/javascriptModuleResolutionMode.js";
|
|
||||||
import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js";
|
import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js";
|
||||||
import {
|
import {
|
||||||
addAstContainsEdge,
|
addAstContainsEdge,
|
||||||
@@ -31,7 +30,7 @@ import {
|
|||||||
staticInferenceEvidence,
|
staticInferenceEvidence,
|
||||||
} from "./JavaScriptArtifactGraphEvidence.js";
|
} from "./JavaScriptArtifactGraphEvidence.js";
|
||||||
import {
|
import {
|
||||||
artifactPathResolutionProperties,
|
moduleKindForJavaScriptReference,
|
||||||
moduleResolutionModeProperties,
|
moduleResolutionModeProperties,
|
||||||
resolveArtifactPathByContext,
|
resolveArtifactPathByContext,
|
||||||
type ArtifactPathResolution,
|
type ArtifactPathResolution,
|
||||||
@@ -55,7 +54,6 @@ interface RelationshipInput {
|
|||||||
type ResolvedModuleTarget = {
|
type ResolvedModuleTarget = {
|
||||||
readonly node: ApplicationNode;
|
readonly node: ApplicationNode;
|
||||||
readonly limitations: readonly string[];
|
readonly limitations: readonly string[];
|
||||||
readonly resolution?: ArtifactPathResolution;
|
|
||||||
} & (
|
} & (
|
||||||
| {
|
| {
|
||||||
readonly path: string;
|
readonly path: string;
|
||||||
@@ -83,13 +81,8 @@ export const addJavaScriptSourceModules = (
|
|||||||
if (asset === undefined || semantic === null || program === undefined)
|
if (asset === undefined || semantic === null || program === undefined)
|
||||||
continue;
|
continue;
|
||||||
const exports = semantic.ir.moduleLinks
|
const exports = semantic.ir.moduleLinks
|
||||||
.flatMap(({ exportedName, kind }) =>
|
.flatMap(({ exportedName }) =>
|
||||||
exportedName === null || kind === "type-import" ? [] : [exportedName],
|
exportedName === null ? [] : [exportedName],
|
||||||
)
|
|
||||||
.sort(compareUnicodeCodePoints);
|
|
||||||
const typeExports = semantic.ir.moduleLinks
|
|
||||||
.flatMap(({ exportedName, kind }) =>
|
|
||||||
exportedName === null || kind !== "type-import" ? [] : [exportedName],
|
|
||||||
)
|
)
|
||||||
.sort(compareUnicodeCodePoints);
|
.sort(compareUnicodeCodePoints);
|
||||||
const retainedExports = [...new Set(exports)];
|
const retainedExports = [...new Set(exports)];
|
||||||
@@ -112,12 +105,8 @@ export const addJavaScriptSourceModules = (
|
|||||||
import_relationships: semantic.ir.moduleLinks.filter(
|
import_relationships: semantic.ir.moduleLinks.filter(
|
||||||
({ kind }) => kind === "import" || kind === "require",
|
({ kind }) => kind === "import" || kind === "require",
|
||||||
).length,
|
).length,
|
||||||
type_relationships: semantic.ir.moduleLinks.filter(
|
|
||||||
({ kind }) => kind === "type-import",
|
|
||||||
).length,
|
|
||||||
export_relationships: exports.length,
|
export_relationships: exports.length,
|
||||||
export_names: retainedExports,
|
export_names: retainedExports,
|
||||||
type_export_names: [...new Set(typeExports)],
|
|
||||||
omitted_export_names: 0,
|
omitted_export_names: 0,
|
||||||
},
|
},
|
||||||
evidence: astObservationEvidence({
|
evidence: astObservationEvidence({
|
||||||
@@ -163,7 +152,6 @@ export function* addJavaScriptModuleRelationshipsSteps(
|
|||||||
for (const link of semantic.ir.moduleLinks) {
|
for (const link of semantic.ir.moduleLinks) {
|
||||||
// One module can export thousands of bindings, each with return shapes.
|
// One module can export thousands of bindings, each with return shapes.
|
||||||
yield;
|
yield;
|
||||||
if (link.kind === "type-import") continue;
|
|
||||||
const input = { context, file, semantic, source, link };
|
const input = { context, file, semantic, source, link };
|
||||||
if (isExportLink(link)) addExportRelationship(input, omissions);
|
if (isExportLink(link)) addExportRelationship(input, omissions);
|
||||||
else if (link.specifier !== null)
|
else if (link.specifier !== null)
|
||||||
@@ -289,7 +277,7 @@ const resolveModuleTarget = (
|
|||||||
sourcePath: input.file.path,
|
sourcePath: input.file.path,
|
||||||
context: "module-specifier",
|
context: "module-specifier",
|
||||||
files: input.context.filesByPath,
|
files: input.context.filesByPath,
|
||||||
moduleKind: moduleResolutionModeForJavaScriptReference(
|
moduleKind: moduleKindForJavaScriptReference(
|
||||||
input.file.path,
|
input.file.path,
|
||||||
input.link.kind === "require" || input.link.kind === "commonjs-export"
|
input.link.kind === "require" || input.link.kind === "commonjs-export"
|
||||||
? "require"
|
? "require"
|
||||||
@@ -299,12 +287,15 @@ const resolveModuleTarget = (
|
|||||||
});
|
});
|
||||||
if (resolution.resolution_status !== "resolved")
|
if (resolution.resolution_status !== "resolved")
|
||||||
return {
|
return {
|
||||||
node: unresolvedModuleNode(input, specifier, resolution),
|
node: unresolvedModuleNode(
|
||||||
|
input,
|
||||||
|
specifier,
|
||||||
|
resolution.resolution_status,
|
||||||
|
),
|
||||||
path: null,
|
path: null,
|
||||||
file: null,
|
file: null,
|
||||||
status: resolution.resolution_status,
|
status: resolution.resolution_status,
|
||||||
limitations: resolution.limitations,
|
limitations: resolution.limitations,
|
||||||
resolution,
|
|
||||||
};
|
};
|
||||||
const path = resolution.resolved_path;
|
const path = resolution.resolved_path;
|
||||||
const file = input.context.filesByPath.get(path);
|
const file = input.context.filesByPath.get(path);
|
||||||
@@ -321,24 +312,20 @@ const resolveModuleTarget = (
|
|||||||
file,
|
file,
|
||||||
status: "resolved",
|
status: "resolved",
|
||||||
limitations: resolution.limitations,
|
limitations: resolution.limitations,
|
||||||
resolution,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const unresolvedModuleNode = (
|
const unresolvedModuleNode = (
|
||||||
input: RelationshipInput,
|
input: RelationshipInput,
|
||||||
specifier: string,
|
specifier: string,
|
||||||
resolution: Extract<
|
status: Exclude<ResolvedModuleTarget["status"], "resolved">,
|
||||||
ArtifactPathResolution,
|
|
||||||
{ resolution_status: Exclude<ResolvedModuleTarget["status"], "resolved"> }
|
|
||||||
>,
|
|
||||||
): ApplicationNode =>
|
): ApplicationNode =>
|
||||||
input.context.accumulator.addNode({
|
input.context.accumulator.addNode({
|
||||||
kind: "javascript-module",
|
kind: "javascript-module",
|
||||||
identity: artifactLocalIdentity(
|
identity: artifactLocalIdentity(
|
||||||
input.file.sha256,
|
input.file.sha256,
|
||||||
"unresolved-semantic-module",
|
"unresolved-semantic-module",
|
||||||
`${resolution.resolution_status}:${specifier}`,
|
`${status}:${specifier}`,
|
||||||
),
|
),
|
||||||
observations: [
|
observations: [
|
||||||
{
|
{
|
||||||
@@ -346,8 +333,7 @@ const unresolvedModuleNode = (
|
|||||||
properties: {
|
properties: {
|
||||||
semantic_role: "module-reference",
|
semantic_role: "module-reference",
|
||||||
declared_specifier: specifier,
|
declared_specifier: specifier,
|
||||||
resolution_status: resolution.resolution_status,
|
resolution_status: status,
|
||||||
...artifactPathResolutionProperties(resolution),
|
|
||||||
},
|
},
|
||||||
evidence: staticInferenceEvidence({
|
evidence: staticInferenceEvidence({
|
||||||
sha256: input.file.sha256,
|
sha256: input.file.sha256,
|
||||||
@@ -368,9 +354,6 @@ const moduleOriginForExport = (
|
|||||||
): JavaScriptModuleOrigin | null => {
|
): JavaScriptModuleOrigin | null => {
|
||||||
if (link.specifier !== null)
|
if (link.specifier !== null)
|
||||||
return {
|
return {
|
||||||
...(link.resolutionMode === undefined
|
|
||||||
? {}
|
|
||||||
: { resolutionMode: link.resolutionMode }),
|
|
||||||
specifier: link.specifier,
|
specifier: link.specifier,
|
||||||
importedPath: link.importedName === null ? [] : [link.importedName],
|
importedPath: link.importedName === null ? [] : [link.importedName],
|
||||||
};
|
};
|
||||||
@@ -400,7 +383,6 @@ const relationshipProperties = (
|
|||||||
exported_name: link.exportedName,
|
exported_name: link.exportedName,
|
||||||
resolved_path: target?.path ?? null,
|
resolved_path: target?.path ?? null,
|
||||||
resolution_status: target?.status ?? null,
|
resolution_status: target?.status ?? null,
|
||||||
...artifactPathResolutionProperties(target?.resolution),
|
|
||||||
target_file_kind: target?.file?.kind ?? null,
|
target_file_kind: target?.file?.kind ?? null,
|
||||||
target_json_status:
|
target_json_status:
|
||||||
target?.file?.kind === "json" || target?.file?.kind === "package-json"
|
target?.file?.kind === "json" || target?.file?.kind === "package-json"
|
||||||
@@ -449,7 +431,6 @@ const moduleFormat = (
|
|||||||
const extension = posix.extname(path).toLowerCase();
|
const extension = posix.extname(path).toLowerCase();
|
||||||
if (extension === ".mjs" || extension === ".mts") return "esm";
|
if (extension === ".mjs" || extension === ".mts") return "esm";
|
||||||
if (extension === ".cjs" || extension === ".cts") return "commonjs";
|
if (extension === ".cjs" || extension === ".cts") return "commonjs";
|
||||||
if (extension === ".ts" || extension === ".tsx") return "unknown";
|
|
||||||
const esm = ir.moduleLinks.some(({ kind }) =>
|
const esm = ir.moduleLinks.some(({ kind }) =>
|
||||||
["import", "export", "re-export"].includes(kind),
|
["import", "export", "re-export"].includes(kind),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
import {
|
|
||||||
inspectSignalDecodersInputSchema,
|
|
||||||
signalDecodersSchema,
|
|
||||||
type InspectSignalDecodersInput,
|
|
||||||
} from "../../domain/signals/signalDecoders.js";
|
|
||||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
|
||||||
import { isAbsolute } from "node:path";
|
import { isAbsolute } from "node:path";
|
||||||
import type {
|
import type {
|
||||||
AnalysisExecution,
|
AnalysisExecution,
|
||||||
@@ -30,10 +24,6 @@ export interface SignalRecordingPort {
|
|||||||
input: DecodeSignalRecordingInput,
|
input: DecodeSignalRecordingInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
): Promise<Result<AnalysisExecution, AnalysisError>>;
|
): Promise<Result<AnalysisExecution, AnalysisError>>;
|
||||||
inspectDecoders(
|
|
||||||
input: InspectSignalDecodersInput,
|
|
||||||
options?: ExecutionOptions,
|
|
||||||
): Promise<Result<AnalysisExecution, AnalysisError>>;
|
|
||||||
close(): Promise<void>;
|
close(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,58 +74,14 @@ export class SignalRecordingService {
|
|||||||
"Decoder returned malformed data or changed the selected recording identity/options.",
|
"Decoder returned malformed data or changed the selected recording identity/options.",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return this.#evidence(operation, input.data, execution, options);
|
const evidence = createEvidence(execution.subject, execution.provider, {
|
||||||
}
|
|
||||||
async inspectDecoders(
|
|
||||||
raw: unknown,
|
|
||||||
options?: ExecutionOptions,
|
|
||||||
): Promise<Result<Evidence, AnalysisError>> {
|
|
||||||
const operation = "inspect_signal_decoders";
|
|
||||||
if (options?.signal?.aborted)
|
|
||||||
return err(new AnalysisCancelledError(operation));
|
|
||||||
const input = inspectSignalDecodersInputSchema.safeParse(raw);
|
|
||||||
if (!input.success)
|
|
||||||
return err(
|
|
||||||
analysisInputErrorFromIssues(operation, input.error.issues, raw, {
|
|
||||||
cause: input.error,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const decoded = await this.provider.inspectDecoders(input.data, options);
|
|
||||||
if (!decoded.ok) return decoded;
|
|
||||||
const execution = decoded.value;
|
|
||||||
const report = signalDecodersSchema.safeParse(execution.result);
|
|
||||||
if (
|
|
||||||
!report.success ||
|
|
||||||
JSON.stringify(report.data.selection) !== JSON.stringify(input.data) ||
|
|
||||||
execution.subject?.path !== report.data.tool.path ||
|
|
||||||
execution.subject.sha256 !== report.data.tool.sha256
|
|
||||||
)
|
|
||||||
return err(
|
|
||||||
new AnalysisOutputError(
|
|
||||||
operation,
|
operation,
|
||||||
"Decoder discovery returned malformed data or changed the selected installation/options.",
|
parameters: input.data,
|
||||||
),
|
result: report.data,
|
||||||
);
|
|
||||||
return this.#evidence(operation, input.data, execution, options);
|
|
||||||
}
|
|
||||||
#evidence(
|
|
||||||
operation: string,
|
|
||||||
parameters: Readonly<Record<string, JsonValue>>,
|
|
||||||
execution: AnalysisExecution,
|
|
||||||
options?: ExecutionOptions,
|
|
||||||
): Result<Evidence, AnalysisError> {
|
|
||||||
const evidence = createEvidence(
|
|
||||||
execution.subject ?? undefined,
|
|
||||||
execution.provider,
|
|
||||||
{
|
|
||||||
operation,
|
|
||||||
parameters,
|
|
||||||
result: execution.result,
|
|
||||||
confidence: "observed",
|
confidence: "observed",
|
||||||
locations: execution.locations,
|
locations: execution.locations,
|
||||||
limitations: execution.limitations,
|
limitations: execution.limitations,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
return options?.signal?.aborted
|
return options?.signal?.aborted
|
||||||
? err(
|
? err(
|
||||||
new AnalysisCancelledError(operation, {
|
new AnalysisCancelledError(operation, {
|
||||||
|
|||||||
@@ -57,10 +57,6 @@ export class ArtifactResourceScope {
|
|||||||
#draining: Promise<void> | undefined;
|
#draining: Promise<void> | undefined;
|
||||||
#closed = false;
|
#closed = false;
|
||||||
|
|
||||||
get hasPending(): boolean {
|
|
||||||
return this.#pending.size > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Admit a resource operation while the scope remains open. */
|
/** Admit a resource operation while the scope remains open. */
|
||||||
async run<T>(operation: () => Promise<T>): Promise<T> {
|
async run<T>(operation: () => Promise<T>): Promise<T> {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import {
|
|||||||
type NativeCommandRunner,
|
type NativeCommandRunner,
|
||||||
} from "../native/CommandRunner.js";
|
} from "../native/CommandRunner.js";
|
||||||
import {
|
import {
|
||||||
|
lipoSubtypeBits,
|
||||||
parseLipoArchitectures,
|
parseLipoArchitectures,
|
||||||
type LipoArchitecture,
|
type LipoArchitecture,
|
||||||
} from "../native/parsers/lipo.js";
|
} from "../native/parsers/lipo.js";
|
||||||
import type { MachoSlice } from "../domain/apple/dylibResolution.js";
|
import type { MachoSlice } from "../domain/apple/dylibResolution.js";
|
||||||
import { machoCpuSubtypeBase } from "../domain/apple/machoCpuIdentity.js";
|
|
||||||
import { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js";
|
import { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js";
|
||||||
import { readMachoImage, type ReadAt } from "./apple/MachoLoadCommandReader.js";
|
import { readMachoImage, type ReadAt } from "./apple/MachoLoadCommandReader.js";
|
||||||
import {
|
import {
|
||||||
@@ -81,9 +81,7 @@ export class MachOSliceArtifactReader implements ArtifactReader {
|
|||||||
if (!captured.ok)
|
if (!captured.ok)
|
||||||
throw new ArtifactReaderFailure(
|
throw new ArtifactReaderFailure(
|
||||||
captured.error.reason === "cancelled" ? "cancelled" : "unavailable",
|
captured.error.reason === "cancelled" ? "cancelled" : "unavailable",
|
||||||
captured.error.detail === null
|
"lipo could not enumerate universal Mach-O slices",
|
||||||
? "lipo could not enumerate universal Mach-O slices"
|
|
||||||
: `lipo could not enumerate universal Mach-O slices: ${captured.error.detail}`,
|
|
||||||
{
|
{
|
||||||
cause: captured.error,
|
cause: captured.error,
|
||||||
...(captured.error.cleanupFailure === null &&
|
...(captured.error.cleanupFailure === null &&
|
||||||
@@ -471,10 +469,8 @@ const lipoSubtypeMatches = (
|
|||||||
): boolean => {
|
): boolean => {
|
||||||
if (reported.cpu_subtype_code !== null)
|
if (reported.cpu_subtype_code !== null)
|
||||||
return reported.cpu_subtype_code === observedCpuSubtype;
|
return reported.cpu_subtype_code === observedCpuSubtype;
|
||||||
return (
|
const bits = lipoSubtypeBits(reported.cpu_subtype);
|
||||||
reported.cpu_subtype_base === null ||
|
return bits === null || bits === (observedCpuSubtype & 0x00ffffff);
|
||||||
reported.cpu_subtype_base === machoCpuSubtypeBase(observedCpuSubtype)
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -280,11 +280,9 @@ export class SafeOutputTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Sync the owned output tree and prevent further writes through this instance. */
|
/** Sync the owned output tree and prevent further writes through this instance. */
|
||||||
async commit(signal?: AbortSignal): Promise<void> {
|
async commit(): Promise<void> {
|
||||||
this.#assertWritable();
|
this.#assertWritable();
|
||||||
abortIfNeeded(signal);
|
|
||||||
await this.#assertOwnedDirectories();
|
await this.#assertOwnedDirectories();
|
||||||
abortIfNeeded(signal);
|
|
||||||
// Windows has no directory fsync; file contents are already synced in write().
|
// Windows has no directory fsync; file contents are already synced in write().
|
||||||
if (this.platform === "win32") {
|
if (this.platform === "win32") {
|
||||||
this.#published = true;
|
this.#published = true;
|
||||||
@@ -317,7 +315,6 @@ export class SafeOutputTree {
|
|||||||
);
|
);
|
||||||
await output.handle.sync();
|
await output.handle.sync();
|
||||||
await parent.handle.sync();
|
await parent.handle.sync();
|
||||||
abortIfNeeded(signal);
|
|
||||||
this.#published = true;
|
this.#published = true;
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
sync = { kind: "failed", cause };
|
sync = { kind: "failed", cause };
|
||||||
@@ -339,27 +336,24 @@ export class SafeOutputTree {
|
|||||||
closeFailure,
|
closeFailure,
|
||||||
this.#outputRoot,
|
this.#outputRoot,
|
||||||
);
|
);
|
||||||
if (sync.kind === "failed") {
|
if (sync.kind === "failed")
|
||||||
const primary = isCancellationFailure(sync.cause)
|
throw ArtifactReaderFailure.withCleanup(
|
||||||
? sync.cause
|
new ArtifactReaderFailure(
|
||||||
: new ArtifactReaderFailure(
|
|
||||||
"path",
|
"path",
|
||||||
"Could not durably sync extraction output",
|
"Could not durably sync extraction output",
|
||||||
{ cause: sync.cause },
|
{ cause: sync.cause },
|
||||||
|
),
|
||||||
|
cleanup,
|
||||||
);
|
);
|
||||||
throw ArtifactReaderFailure.withCleanup(primary, cleanup);
|
|
||||||
}
|
|
||||||
throw ArtifactReaderFailure.withCleanup(closeFailure, cleanup);
|
throw ArtifactReaderFailure.withCleanup(closeFailure, cleanup);
|
||||||
}
|
}
|
||||||
if (sync.kind === "failed") {
|
if (sync.kind === "failed")
|
||||||
if (isCancellationFailure(sync.cause)) throw sync.cause;
|
|
||||||
throw new ArtifactReaderFailure(
|
throw new ArtifactReaderFailure(
|
||||||
"path",
|
"path",
|
||||||
"Could not durably sync extraction output",
|
"Could not durably sync extraction output",
|
||||||
{ cause: sync.cause },
|
{ cause: sync.cause },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** Remove only this operation's unsealed tree and verify absence. */
|
/** Remove only this operation's unsealed tree and verify absence. */
|
||||||
async rollback(): Promise<SafeOutputCleanup> {
|
async rollback(): Promise<SafeOutputCleanup> {
|
||||||
@@ -596,11 +590,6 @@ const abortIfNeeded = (signal?: AbortSignal): void => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isCancellationFailure = (
|
|
||||||
cause: unknown,
|
|
||||||
): cause is ArtifactReaderFailure =>
|
|
||||||
cause instanceof ArtifactReaderFailure && cause.reason === "cancelled";
|
|
||||||
|
|
||||||
const isAlreadyExists = (cause: unknown): boolean =>
|
const isAlreadyExists = (cause: unknown): boolean =>
|
||||||
cause instanceof Error && "code" in cause && cause.code === "EEXIST";
|
cause instanceof Error && "code" in cause && cause.code === "EEXIST";
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import { DirectoryArtifactReader } from "../DirectoryArtifactReader.js";
|
|||||||
import { SafeOutputTree } from "../SafeOutputTree.js";
|
import { SafeOutputTree } from "../SafeOutputTree.js";
|
||||||
import { SafeOutputTreeCreationFailure } from "../SafeOutputTreeCreationFailure.js";
|
import { SafeOutputTreeCreationFailure } from "../SafeOutputTreeCreationFailure.js";
|
||||||
import { ZipArtifactReader } from "../ZipArtifactReader.js";
|
import { ZipArtifactReader } from "../ZipArtifactReader.js";
|
||||||
import { isZipPackageFormat } from "../../domain/zipPackageFormat.js";
|
|
||||||
import { MachOSliceArtifactReader } from "../MachOSliceArtifactReader.js";
|
import { MachOSliceArtifactReader } from "../MachOSliceArtifactReader.js";
|
||||||
import {
|
import {
|
||||||
artifactExtractionResultSchema,
|
artifactExtractionResultSchema,
|
||||||
@@ -249,7 +248,7 @@ const materializeSelection = async ({
|
|||||||
compareUnicodeCodePoints(left.relative_path, right.relative_path),
|
compareUnicodeCodePoints(left.relative_path, right.relative_path),
|
||||||
);
|
);
|
||||||
completed = createExtractionResult(input, inventory, selected, extracted);
|
completed = createExtractionResult(input, inventory, selected, extracted);
|
||||||
await output.commit(signal);
|
await output.commit();
|
||||||
return completed;
|
return completed;
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
const cleanupFailures = await releaseExtractionOwners(
|
const cleanupFailures = await releaseExtractionOwners(
|
||||||
@@ -401,6 +400,13 @@ interface ExtractionInventory {
|
|||||||
readonly integrityContradictions: readonly IntegrityContradiction[];
|
readonly integrityContradictions: readonly IntegrityContradiction[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ZIP_FORMATS = ["ipa", "apk", "msix", "appx", "zip"] as const;
|
||||||
|
|
||||||
|
const isZipFormat = (
|
||||||
|
format: BinaryTarget["format"],
|
||||||
|
): format is (typeof ZIP_FORMATS)[number] =>
|
||||||
|
(ZIP_FORMATS as readonly string[]).includes(format);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refuse a format without an extraction reader before inventory work starts.
|
* Refuse a format without an extraction reader before inventory work starts.
|
||||||
* The target kind, not the host, is unsupported by extraction. The error keeps
|
* The target kind, not the host, is unsupported by extraction. The error keeps
|
||||||
@@ -416,7 +422,7 @@ const requireExtractableFormat = async (
|
|||||||
!directory &&
|
!directory &&
|
||||||
format !== "asar" &&
|
format !== "asar" &&
|
||||||
!isMachOFormat(format) &&
|
!isMachOFormat(format) &&
|
||||||
!isZipPackageFormat(format)
|
!isZipFormat(format)
|
||||||
)
|
)
|
||||||
throw new AnalysisUnsupportedTargetError(
|
throw new AnalysisUnsupportedTargetError(
|
||||||
"extract_artifact",
|
"extract_artifact",
|
||||||
@@ -437,7 +443,7 @@ const createReader = async (
|
|||||||
if (await requireExtractableFormat(path, input))
|
if (await requireExtractableFormat(path, input))
|
||||||
return new DirectoryArtifactReader(path);
|
return new DirectoryArtifactReader(path);
|
||||||
if (format === "asar") return new AsarArtifactReader(path);
|
if (format === "asar") return new AsarArtifactReader(path);
|
||||||
if (isZipPackageFormat(format)) return new ZipArtifactReader(path, format);
|
if (isZipFormat(format)) return new ZipArtifactReader(path, format);
|
||||||
return new MachOSliceArtifactReader(path, input.environment);
|
return new MachOSliceArtifactReader(path, input.environment);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -38,13 +38,6 @@ const afterValidation = async <T>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const assertReadActive = (signal: AbortSignal | undefined): void => {
|
|
||||||
if (signal?.aborted)
|
|
||||||
throw new ArtifactReaderFailure("cancelled", "Artifact read cancelled", {
|
|
||||||
cause: signal.reason,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Read one bounded regular file and reject replacement or in-place changes. */
|
/** Read one bounded regular file and reject replacement or in-place changes. */
|
||||||
export const readStableArtifact = async (
|
export const readStableArtifact = async (
|
||||||
path: string,
|
path: string,
|
||||||
@@ -53,7 +46,7 @@ export const readStableArtifact = async (
|
|||||||
fileSystem: StableArtifactFileSystem = FILE_SYSTEM,
|
fileSystem: StableArtifactFileSystem = FILE_SYSTEM,
|
||||||
resourceScope?: ArtifactResourceScope,
|
resourceScope?: ArtifactResourceScope,
|
||||||
): Promise<{ readonly bytes: Buffer; readonly sha256: string }> => {
|
): Promise<{ readonly bytes: Buffer; readonly sha256: string }> => {
|
||||||
assertReadActive(signal);
|
signal?.throwIfAborted();
|
||||||
const before = await fileSystem.lstat(path);
|
const before = await fileSystem.lstat(path);
|
||||||
if (!before.isFile() || before.isSymbolicLink())
|
if (!before.isFile() || before.isSymbolicLink())
|
||||||
throw new ArtifactReaderFailure(
|
throw new ArtifactReaderFailure(
|
||||||
@@ -91,7 +84,7 @@ export const readStableArtifact = async (
|
|||||||
autoClose: false,
|
autoClose: false,
|
||||||
highWaterMark: 65536,
|
highWaterMark: 65536,
|
||||||
})) {
|
})) {
|
||||||
assertReadActive(signal);
|
signal?.throwIfAborted();
|
||||||
const value: unknown = chunk;
|
const value: unknown = chunk;
|
||||||
if (!Buffer.isBuffer(value))
|
if (!Buffer.isBuffer(value))
|
||||||
throw new ArtifactReaderFailure(
|
throw new ArtifactReaderFailure(
|
||||||
@@ -127,7 +120,6 @@ export const readStableArtifact = async (
|
|||||||
"integrity",
|
"integrity",
|
||||||
`Artifact changed during read: ${path}`,
|
`Artifact changed during read: ${path}`,
|
||||||
);
|
);
|
||||||
assertReadActive(signal);
|
|
||||||
const bytes = Buffer.concat(chunks, count);
|
const bytes = Buffer.concat(chunks, count);
|
||||||
return { bytes, sha256: createHash("sha256").update(bytes).digest("hex") };
|
return { bytes, sha256: createHash("sha256").update(bytes).digest("hex") };
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export const browserScenarioCaptureData = (input: {
|
|||||||
network_content: input.scenario.capture.network,
|
network_content: input.scenario.capture.network,
|
||||||
event_families: [...new Set(input.scenario.capture.events)].sort(),
|
event_families: [...new Set(input.scenario.capture.events)].sort(),
|
||||||
},
|
},
|
||||||
duration_ms: Math.max(0, Math.round(performance.now() - input.startedAt)),
|
duration_ms: Date.now() - input.startedAt,
|
||||||
steps: [...input.steps],
|
steps: [...input.steps],
|
||||||
events,
|
events,
|
||||||
limitations: [
|
limitations: [
|
||||||
|
|||||||
@@ -303,7 +303,6 @@ describe("PlaywrightBrowserScenarioProvider", () => {
|
|||||||
});
|
});
|
||||||
expect(result.value.limitations).toContain(session.eventGaps[0]);
|
expect(result.value.limitations).toContain(session.eventGaps[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an initial state and every step beyond the former action ceiling", async () => {
|
it("returns an initial state and every step beyond the former action ceiling", async () => {
|
||||||
const session = new FakeSession("launch");
|
const session = new FakeSession("launch");
|
||||||
const provider = new PlaywrightBrowserScenarioProvider(() =>
|
const provider = new PlaywrightBrowserScenarioProvider(() =>
|
||||||
@@ -377,35 +376,6 @@ describe("PlaywrightBrowserScenarioProvider", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("PlaywrightBrowserScenarioProvider timing", () => {
|
|
||||||
it("keeps capture elapsed values valid across a backward wall-clock jump", async () => {
|
|
||||||
let wallClock = 10_000;
|
|
||||||
vi.spyOn(Date, "now").mockImplementation(() => wallClock);
|
|
||||||
const session = new FakeSession("launch");
|
|
||||||
session.onPerform = () => {
|
|
||||||
wallClock = 1;
|
|
||||||
};
|
|
||||||
const provider = new PlaywrightBrowserScenarioProvider(() =>
|
|
||||||
Promise.resolve(session),
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await provider.captureScenario(scenario());
|
|
||||||
if (!result.ok) throw result.error;
|
|
||||||
expect(wallClock).toBe(1);
|
|
||||||
expect(Number.isInteger(result.value.duration_ms)).toBe(true);
|
|
||||||
expect(result.value.duration_ms).toBeGreaterThanOrEqual(0);
|
|
||||||
expect(
|
|
||||||
result.value.steps.every(
|
|
||||||
({ elapsed_ms }) => Number.isInteger(elapsed_ms) && elapsed_ms >= 0,
|
|
||||||
),
|
|
||||||
).toBe(true);
|
|
||||||
} finally {
|
|
||||||
vi.restoreAllMocks();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("PlaywrightBrowserScenarioProvider comparison coverage", () => {
|
describe("PlaywrightBrowserScenarioProvider comparison coverage", () => {
|
||||||
it("keeps quiet captures with different event families from comparing unchanged", async () => {
|
it("keeps quiet captures with different event families from comparing unchanged", async () => {
|
||||||
const capture = async (events: readonly BrowserScenarioEventFamily[]) => {
|
const capture = async (events: readonly BrowserScenarioEventFamily[]) => {
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ const executeStep = async (input: {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
const actionStartedAt = performance.now();
|
const actionStartedAt = Date.now();
|
||||||
session.setStep(stepIndex);
|
session.setStep(stepIndex);
|
||||||
const requestCancelled = (): boolean => signal?.aborted === true;
|
const requestCancelled = (): boolean => signal?.aborted === true;
|
||||||
let outcome: BrowserScenarioStepOutcome = {
|
let outcome: BrowserScenarioStepOutcome = {
|
||||||
@@ -200,7 +200,7 @@ const executeStep = async (input: {
|
|||||||
stepId: action.step_id,
|
stepId: action.step_id,
|
||||||
action: action.action,
|
action: action.action,
|
||||||
...outcome,
|
...outcome,
|
||||||
elapsedMs: Math.max(0, Math.round(performance.now() - actionStartedAt)),
|
elapsedMs: Date.now() - actionStartedAt,
|
||||||
beforeUrl,
|
beforeUrl,
|
||||||
afterUrl: session.sanitizeUrl(session.currentUrl()),
|
afterUrl: session.sanitizeUrl(session.currentUrl()),
|
||||||
eventStart,
|
eventStart,
|
||||||
@@ -233,7 +233,7 @@ const runScenario = async (
|
|||||||
): Promise<BrowserScenarioCapture> => {
|
): Promise<BrowserScenarioCapture> => {
|
||||||
if (options.signal?.aborted === true)
|
if (options.signal?.aborted === true)
|
||||||
throw new BrowserObservationError(OPERATION, "cancelled");
|
throw new BrowserObservationError(OPERATION, "cancelled");
|
||||||
const startedAt = performance.now();
|
const startedAt = Date.now();
|
||||||
const session = await openSession(scenario, {
|
const session = await openSession(scenario, {
|
||||||
...(options.signal === undefined ? {} : { signal: options.signal }),
|
...(options.signal === undefined ? {} : { signal: options.signal }),
|
||||||
retainCleanup,
|
retainCleanup,
|
||||||
@@ -250,7 +250,7 @@ const runScenario = async (
|
|||||||
await initialStep({
|
await initialStep({
|
||||||
session,
|
session,
|
||||||
scenario,
|
scenario,
|
||||||
elapsedMs: Math.max(0, Math.round(performance.now() - startedAt)),
|
elapsedMs: Date.now() - startedAt,
|
||||||
signal: options.signal,
|
signal: options.signal,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export const runElectronActions = async (
|
|||||||
): Promise<ElectronActions> => {
|
): Promise<ElectronActions> => {
|
||||||
const actions: ElectronActions = [];
|
const actions: ElectronActions = [];
|
||||||
for (const action of input.actions) {
|
for (const action of input.actions) {
|
||||||
const actionStartedAt = performance.now();
|
const actionStartedAt = Date.now();
|
||||||
const windowIndex = actionWindowIndex(action);
|
const windowIndex = actionWindowIndex(action);
|
||||||
let selectedWindow: Page | undefined;
|
let selectedWindow: Page | undefined;
|
||||||
try {
|
try {
|
||||||
@@ -107,10 +107,7 @@ export const runElectronActions = async (
|
|||||||
target:
|
target:
|
||||||
selectedWindow === undefined ? null : `window:${String(windowIndex)}`,
|
selectedWindow === undefined ? null : `window:${String(windowIndex)}`,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
elapsed_ms: Math.max(
|
elapsed_ms: Date.now() - actionStartedAt,
|
||||||
0,
|
|
||||||
Math.round(performance.now() - actionStartedAt),
|
|
||||||
),
|
|
||||||
error: null,
|
error: null,
|
||||||
});
|
});
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
@@ -121,10 +118,7 @@ export const runElectronActions = async (
|
|||||||
target:
|
target:
|
||||||
selectedWindow === undefined ? null : `window:${String(windowIndex)}`,
|
selectedWindow === undefined ? null : `window:${String(windowIndex)}`,
|
||||||
status: options.signal?.aborted ? "cancelled" : "failed",
|
status: options.signal?.aborted ? "cancelled" : "failed",
|
||||||
elapsed_ms: Math.max(
|
elapsed_ms: Date.now() - actionStartedAt,
|
||||||
0,
|
|
||||||
Math.round(performance.now() - actionStartedAt),
|
|
||||||
),
|
|
||||||
error: safeActionErrorMessage(cause),
|
error: safeActionErrorMessage(cause),
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -372,7 +366,7 @@ export const runWithExecutionLimits = async <Value>(
|
|||||||
new Promise<never>((_, reject) => {
|
new Promise<never>((_, reject) => {
|
||||||
timer = setTimeout(
|
timer = setTimeout(
|
||||||
() => reject(new BrowserObservationError(OPERATION, "timeout")),
|
() => reject(new BrowserObservationError(OPERATION, "timeout")),
|
||||||
Math.max(1, deadline - performance.now()),
|
Math.max(1, deadline - Date.now()),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
|||||||
if (options.signal?.aborted === true)
|
if (options.signal?.aborted === true)
|
||||||
throw new BrowserObservationError(OPERATION, "cancelled");
|
throw new BrowserObservationError(OPERATION, "cancelled");
|
||||||
await prepareProcessOwnershipInspection(options.signal);
|
await prepareProcessOwnershipInspection(options.signal);
|
||||||
const startupDeadline = performance.now() + STARTUP_TIMEOUT_MS;
|
const startupDeadline = Date.now() + STARTUP_TIMEOUT_MS;
|
||||||
paths = {
|
paths = {
|
||||||
executable: input.executable_path,
|
executable: input.executable_path,
|
||||||
application: input.application_path,
|
application: input.application_path,
|
||||||
@@ -101,7 +101,7 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
|||||||
cwd: paths.root,
|
cwd: paths.root,
|
||||||
env: safeElectronEnvironment(this.environment, runId),
|
env: safeElectronEnvironment(this.environment, runId),
|
||||||
args: ["-r", hookPath, paths.application, ...input.args],
|
args: ["-r", hookPath, paths.application, ...input.args],
|
||||||
timeout: Math.max(1, startupDeadline - performance.now()),
|
timeout: Math.max(1, startupDeadline - Date.now()),
|
||||||
});
|
});
|
||||||
const leaderPid = application.process().pid;
|
const leaderPid = application.process().pid;
|
||||||
if (
|
if (
|
||||||
@@ -128,7 +128,7 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
|||||||
const state = await runWithExecutionLimits(
|
const state = await runWithExecutionLimits(
|
||||||
readApplicationState(application),
|
readApplicationState(application),
|
||||||
undefined,
|
undefined,
|
||||||
options.signal?.aborted ? performance.now() + 5_000 : undefined,
|
options.signal?.aborted ? Date.now() + 5_000 : undefined,
|
||||||
);
|
);
|
||||||
capture = projectElectronActiveCapture(paths, actions, state);
|
capture = projectElectronActiveCapture(paths, actions, state);
|
||||||
outcome = options.signal?.aborted
|
outcome = options.signal?.aborted
|
||||||
@@ -187,7 +187,7 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
|||||||
await runWithExecutionLimits(
|
await runWithExecutionLimits(
|
||||||
application.close(),
|
application.close(),
|
||||||
undefined,
|
undefined,
|
||||||
performance.now() + 5_000,
|
Date.now() + 5_000,
|
||||||
);
|
);
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
closeError = cause;
|
closeError = cause;
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import {
|
|||||||
} from "../domain/analysisErrorCore.js";
|
} from "../domain/analysisErrorCore.js";
|
||||||
|
|
||||||
describe("withPlaywrightExecutionBoundary", () => {
|
describe("withPlaywrightExecutionBoundary", () => {
|
||||||
afterEach(() => {
|
afterEach(() => vi.useRealTimers());
|
||||||
vi.useRealTimers();
|
|
||||||
vi.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects work that exceeds its absolute remaining duration", async () => {
|
it("rejects work that exceeds its absolute remaining duration", async () => {
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
@@ -34,20 +31,4 @@ describe("withPlaywrightExecutionBoundary", () => {
|
|||||||
controller.abort();
|
controller.abort();
|
||||||
await expect(result).rejects.toBeInstanceOf(AnalysisCancelledError);
|
await expect(result).rejects.toBeInstanceOf(AnalysisCancelledError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps its timeout stable across a wall-clock jump", async () => {
|
|
||||||
vi.spyOn(Date, "now")
|
|
||||||
.mockReturnValueOnce(1_000)
|
|
||||||
.mockReturnValue(10_000_000);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
withPlaywrightExecutionBoundary(
|
|
||||||
() =>
|
|
||||||
new Promise<string>((resolve) =>
|
|
||||||
setTimeout(() => resolve("done"), 5),
|
|
||||||
),
|
|
||||||
1_000,
|
|
||||||
),
|
|
||||||
).resolves.toBe("done");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ export const withPlaywrightExecutionBoundary = <Value>(
|
|||||||
let settled = false;
|
let settled = false;
|
||||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||||
const deadline =
|
const deadline =
|
||||||
timeoutMs === undefined ? undefined : performance.now() + timeoutMs;
|
timeoutMs === undefined ? undefined : Date.now() + timeoutMs;
|
||||||
const scheduleTimeout = (): void => {
|
const scheduleTimeout = (): void => {
|
||||||
if (deadline === undefined) return;
|
if (deadline === undefined) return;
|
||||||
const remaining = deadline - performance.now();
|
const remaining = deadline - Date.now();
|
||||||
if (remaining <= 0) {
|
if (remaining <= 0) {
|
||||||
fail(new AnalysisTimeoutError(OPERATION, timeoutMs ?? 0));
|
fail(new AnalysisTimeoutError(OPERATION, timeoutMs ?? 0));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export class PlaywrightScenarioSession implements BrowserScenarioSessionPort {
|
|||||||
const secrets = BrowserScenarioSecrets.resolve(scenario, environment);
|
const secrets = BrowserScenarioSecrets.resolve(scenario, environment);
|
||||||
if (secrets === undefined)
|
if (secrets === undefined)
|
||||||
throw new BrowserObservationError(OPERATION, "secret_unavailable");
|
throw new BrowserObservationError(OPERATION, "secret_unavailable");
|
||||||
const startedAt = performance.now();
|
const startedAt = Date.now();
|
||||||
const opening = openPlaywrightScenarioBrowser(scenario, environment, {
|
const opening = openPlaywrightScenarioBrowser(scenario, environment, {
|
||||||
signal: options.signal,
|
signal: options.signal,
|
||||||
...(options.retainCleanup === undefined
|
...(options.retainCleanup === undefined
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export const fetchWebSourceMaps = async (
|
|||||||
signal?.addEventListener("abort", abortFromCaller, { once: true });
|
signal?.addEventListener("abort", abortFromCaller, { once: true });
|
||||||
const operationSignal = operationController.signal;
|
const operationSignal = operationController.signal;
|
||||||
const deadlineAt =
|
const deadlineAt =
|
||||||
performance.now() + (host.timeoutMs ?? SOURCE_MAP_FETCH_TIMEOUT_MS);
|
Date.now() + (host.timeoutMs ?? SOURCE_MAP_FETCH_TIMEOUT_MS);
|
||||||
const budget = {
|
const budget = {
|
||||||
retainedBytes: 0,
|
retainedBytes: 0,
|
||||||
deadlineAt,
|
deadlineAt,
|
||||||
@@ -110,7 +110,7 @@ export const fetchWebSourceMaps = async (
|
|||||||
}
|
}
|
||||||
const expandedBytesBeforeItem = budget.decodedRecords.expandedBytes;
|
const expandedBytesBeforeItem = budget.decodedRecords.expandedBytes;
|
||||||
budget.decodedRecords.expandedBytes += reservation;
|
budget.decodedRecords.expandedBytes += reservation;
|
||||||
if (operationSignal.aborted || performance.now() >= deadlineAt) {
|
if (operationSignal.aborted || Date.now() >= deadlineAt) {
|
||||||
items.push(
|
items.push(
|
||||||
emptySourceMapItem(
|
emptySourceMapItem(
|
||||||
request,
|
request,
|
||||||
@@ -789,7 +789,7 @@ const checkOperation = (
|
|||||||
): void => {
|
): void => {
|
||||||
if (callerSignal?.aborted === true) throw callerSignal.reason;
|
if (callerSignal?.aborted === true) throw callerSignal.reason;
|
||||||
if (operationSignal?.aborted === true) throw operationSignal.reason;
|
if (operationSignal?.aborted === true) throw operationSignal.reason;
|
||||||
if (performance.now() >= deadlineAt) throw new SourceMapDeadlineError();
|
if (Date.now() >= deadlineAt) throw new SourceMapDeadlineError();
|
||||||
};
|
};
|
||||||
|
|
||||||
const approvedUrl = (
|
const approvedUrl = (
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { lstat, realpath } from "node:fs/promises";
|
import { lstat, realpath } from "node:fs/promises";
|
||||||
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
||||||
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
|
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
|
||||||
import { ArtifactResourceScope } from "../../artifacts/ArtifactResourceScope.js";
|
|
||||||
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
||||||
import { normalizeArtifactPath } from "../../artifacts/ArtifactPaths.js";
|
import { normalizeArtifactPath } from "../../artifacts/ArtifactPaths.js";
|
||||||
import type { WebScriptArtifactPort } from "../../application/WebScriptArtifactPort.js";
|
import type { WebScriptArtifactPort } from "../../application/WebScriptArtifactPort.js";
|
||||||
@@ -20,36 +19,10 @@ import {
|
|||||||
|
|
||||||
/** Read one digest-verified captured source under the manifest's current location. */
|
/** Read one digest-verified captured source under the manifest's current location. */
|
||||||
export class LocalWebScriptArtifacts implements WebScriptArtifactPort {
|
export class LocalWebScriptArtifacts implements WebScriptArtifactPort {
|
||||||
constructor(
|
constructor(readonly operation: WebArtifactReadContext["operation"]) {}
|
||||||
readonly operation: WebArtifactReadContext["operation"],
|
|
||||||
readonly resources = new ArtifactResourceScope(),
|
|
||||||
) {}
|
|
||||||
|
|
||||||
close(): Promise<void> {
|
|
||||||
return this.resources.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Read the selected source; relocated exports retain their reported original root. */
|
/** Read the selected source; relocated exports retain their reported original root. */
|
||||||
async load(input: SelectedWebScriptInput, options?: ExecutionOptions) {
|
async load(input: SelectedWebScriptInput, options?: ExecutionOptions) {
|
||||||
try {
|
|
||||||
return await this.resources.run(() => this.#load(input, options));
|
|
||||||
} catch (cause: unknown) {
|
|
||||||
return err(
|
|
||||||
webArtifactReadError(
|
|
||||||
cause,
|
|
||||||
{
|
|
||||||
operation: this.operation,
|
|
||||||
field: ["manifest_path"],
|
|
||||||
targetPath: input.manifest_path,
|
|
||||||
callerSelected: true,
|
|
||||||
},
|
|
||||||
options?.signal,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async #load(input: SelectedWebScriptInput, options?: ExecutionOptions) {
|
|
||||||
let field: readonly (string | number)[] = ["manifest_path"];
|
let field: readonly (string | number)[] = ["manifest_path"];
|
||||||
let targetPath = input.manifest_path;
|
let targetPath = input.manifest_path;
|
||||||
let callerSelected = true;
|
let callerSelected = true;
|
||||||
@@ -58,7 +31,6 @@ export class LocalWebScriptArtifacts implements WebScriptArtifactPort {
|
|||||||
input.manifest_path,
|
input.manifest_path,
|
||||||
32 * 1024 * 1024,
|
32 * 1024 * 1024,
|
||||||
options?.signal,
|
options?.signal,
|
||||||
this.resources,
|
|
||||||
);
|
);
|
||||||
const manifest = webScriptExportManifestSchema.parse(manifestBytes.value);
|
const manifest = webScriptExportManifestSchema.parse(manifestBytes.value);
|
||||||
field = ["script_index"];
|
field = ["script_index"];
|
||||||
@@ -93,8 +65,6 @@ export class LocalWebScriptArtifacts implements WebScriptArtifactPort {
|
|||||||
sourcePath,
|
sourcePath,
|
||||||
16 * 1024 * 1024,
|
16 * 1024 * 1024,
|
||||||
options?.signal,
|
options?.signal,
|
||||||
undefined,
|
|
||||||
this.resources,
|
|
||||||
);
|
);
|
||||||
await assertContained(root, sourcePath);
|
await assertContained(root, sourcePath);
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ export const publishWebScripts = async (
|
|||||||
options.signal,
|
options.signal,
|
||||||
);
|
);
|
||||||
options.signal?.throwIfAborted();
|
options.signal?.throwIfAborted();
|
||||||
await tree.commit(options.signal);
|
await tree.commit();
|
||||||
return result;
|
return result;
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
if (cause instanceof SafeOutputTreeCreationFailure) tree = cause.tree;
|
if (cause instanceof SafeOutputTreeCreationFailure) tree = cause.tree;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
|
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
|
||||||
import type { ArtifactResourceScope } from "../../artifacts/ArtifactResourceScope.js";
|
|
||||||
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
||||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||||
import {
|
import {
|
||||||
@@ -10,8 +9,6 @@ import {
|
|||||||
} from "../../domain/analysisErrorCore.js";
|
} from "../../domain/analysisErrorCore.js";
|
||||||
import { ArtifactOperationError } from "../../domain/artifactOperationError.js";
|
import { ArtifactOperationError } from "../../domain/artifactOperationError.js";
|
||||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||||
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
|
||||||
import { analysisErrorWithCleanupFailure } from "../../domain/analysisErrorCleanup.js";
|
|
||||||
import { safeParseJson } from "../../domain/safeJson.js";
|
import { safeParseJson } from "../../domain/safeJson.js";
|
||||||
|
|
||||||
/** The selected artifact and input field owning a reader failure. */
|
/** The selected artifact and input field owning a reader failure. */
|
||||||
@@ -45,15 +42,8 @@ export const readWebArtifactJson = async (
|
|||||||
path: string,
|
path: string,
|
||||||
maximumBytes: number,
|
maximumBytes: number,
|
||||||
signal?: AbortSignal,
|
signal?: AbortSignal,
|
||||||
resourceScope?: ArtifactResourceScope,
|
|
||||||
) => {
|
) => {
|
||||||
const data = await readStableArtifact(
|
const data = await readStableArtifact(path, maximumBytes, signal);
|
||||||
path,
|
|
||||||
maximumBytes,
|
|
||||||
signal,
|
|
||||||
undefined,
|
|
||||||
resourceScope,
|
|
||||||
);
|
|
||||||
const value = safeParseJson(decodeWebArtifact(data.bytes));
|
const value = safeParseJson(decodeWebArtifact(data.bytes));
|
||||||
if (!value.ok) throw new WebArtifactFormatFailure(value.error);
|
if (!value.ok) throw new WebArtifactFormatFailure(value.error);
|
||||||
return { ...data, value: value.value };
|
return { ...data, value: value.value };
|
||||||
@@ -65,30 +55,8 @@ export const webArtifactReadError = (
|
|||||||
context: WebArtifactReadContext,
|
context: WebArtifactReadContext,
|
||||||
signal?: AbortSignal,
|
signal?: AbortSignal,
|
||||||
): AnalysisError => {
|
): AnalysisError => {
|
||||||
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined) {
|
|
||||||
const primary =
|
|
||||||
signal?.aborted === true
|
|
||||||
? new AnalysisCancelledError(context.operation, { cause })
|
|
||||||
: new ArtifactOperationError(
|
|
||||||
context.operation,
|
|
||||||
cause.reason,
|
|
||||||
cause.details,
|
|
||||||
cause.message,
|
|
||||||
{ cause },
|
|
||||||
);
|
|
||||||
return analysisErrorWithCleanupFailure(
|
|
||||||
primary,
|
|
||||||
new ProviderCleanupError(
|
|
||||||
"captured-web-artifacts",
|
|
||||||
cause.cleanup.resources,
|
|
||||||
{ reason: cause.cleanup.reason },
|
|
||||||
{ cause, operation: context.operation },
|
|
||||||
),
|
|
||||||
context.operation,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (signal?.aborted === true)
|
if (signal?.aborted === true)
|
||||||
return new AnalysisCancelledError(context.operation, { cause });
|
return new AnalysisCancelledError(context.operation);
|
||||||
const selection = context.callerSelected
|
const selection = context.callerSelected
|
||||||
? selectedFileError(cause, context)
|
? selectedFileError(cause, context)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type { WebSourceLocationArtifactPort } from "../../application/WebSourceLocationPorts.js";
|
import type { WebSourceLocationArtifactPort } from "../../application/WebSourceLocationPorts.js";
|
||||||
import type { WebScriptArtifactPort } from "../../application/WebScriptArtifactPort.js";
|
import type { WebScriptArtifactPort } from "../../application/WebScriptArtifactPort.js";
|
||||||
import type { ExecutionOptions } from "../../application/AnalysisProvider.js";
|
import type { ExecutionOptions } from "../../application/AnalysisProvider.js";
|
||||||
import { ArtifactResourceScope } from "../../artifacts/ArtifactResourceScope.js";
|
|
||||||
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
||||||
import {
|
import {
|
||||||
WEB_SOURCE_MAP_LIMITS,
|
WEB_SOURCE_MAP_LIMITS,
|
||||||
@@ -13,64 +12,14 @@ import { decodeWebArtifact, webArtifactReadError } from "./WebArtifactReads.js";
|
|||||||
|
|
||||||
/** Read one verified capture source and the caller-selected map, without fetching. */
|
/** Read one verified capture source and the caller-selected map, without fetching. */
|
||||||
export class LocalWebSourceLocationArtifacts implements WebSourceLocationArtifactPort {
|
export class LocalWebSourceLocationArtifacts implements WebSourceLocationArtifactPort {
|
||||||
readonly scripts: WebScriptArtifactPort;
|
|
||||||
readonly #resources: ArtifactResourceScope;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
scripts?: WebScriptArtifactPort,
|
readonly scripts: WebScriptArtifactPort = new LocalWebScriptArtifacts(
|
||||||
resources = scripts instanceof LocalWebScriptArtifacts
|
"trace_web_source_location",
|
||||||
? scripts.resources
|
),
|
||||||
: new ArtifactResourceScope(),
|
) {}
|
||||||
) {
|
|
||||||
this.#resources = resources;
|
|
||||||
this.scripts =
|
|
||||||
scripts ??
|
|
||||||
new LocalWebScriptArtifacts("trace_web_source_location", resources);
|
|
||||||
}
|
|
||||||
|
|
||||||
async close(): Promise<void> {
|
|
||||||
const closeScript =
|
|
||||||
this.scripts instanceof LocalWebScriptArtifacts &&
|
|
||||||
this.scripts.resources === this.#resources
|
|
||||||
? undefined
|
|
||||||
: this.scripts.close?.bind(this.scripts);
|
|
||||||
const results = await Promise.allSettled([
|
|
||||||
Promise.resolve().then(() => this.#resources.close()),
|
|
||||||
...(closeScript === undefined
|
|
||||||
? []
|
|
||||||
: [Promise.resolve().then(closeScript)]),
|
|
||||||
]);
|
|
||||||
const failures = results.flatMap((result) =>
|
|
||||||
result.status === "rejected" ? [result.reason] : [],
|
|
||||||
);
|
|
||||||
if (failures.length > 0)
|
|
||||||
throw new AggregateError(
|
|
||||||
failures,
|
|
||||||
"Web source-location artifact cleanup failed",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Preserve actual map identity separately from the selected deployment URL. */
|
/** Preserve actual map identity separately from the selected deployment URL. */
|
||||||
async load(input: WebSourceLocationInput, options?: ExecutionOptions) {
|
async load(input: WebSourceLocationInput, options?: ExecutionOptions) {
|
||||||
try {
|
|
||||||
return await this.#resources.run(() => this.#load(input, options));
|
|
||||||
} catch (cause: unknown) {
|
|
||||||
return err(
|
|
||||||
webArtifactReadError(
|
|
||||||
cause,
|
|
||||||
{
|
|
||||||
operation: "trace_web_source_location",
|
|
||||||
field: ["source_map", "path"],
|
|
||||||
targetPath: input.source_map.path,
|
|
||||||
callerSelected: true,
|
|
||||||
},
|
|
||||||
options?.signal,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async #load(input: WebSourceLocationInput, options?: ExecutionOptions) {
|
|
||||||
const loaded = await this.scripts.load(input, options);
|
const loaded = await this.scripts.load(input, options);
|
||||||
if (!loaded.ok) return loaded;
|
if (!loaded.ok) return loaded;
|
||||||
try {
|
try {
|
||||||
@@ -78,8 +27,6 @@ export class LocalWebSourceLocationArtifacts implements WebSourceLocationArtifac
|
|||||||
input.source_map.path,
|
input.source_map.path,
|
||||||
WEB_SOURCE_MAP_LIMITS.mapBytes,
|
WEB_SOURCE_MAP_LIMITS.mapBytes,
|
||||||
options?.signal,
|
options?.signal,
|
||||||
undefined,
|
|
||||||
this.#resources,
|
|
||||||
);
|
);
|
||||||
return ok({
|
return ok({
|
||||||
...loaded.value,
|
...loaded.value,
|
||||||
|
|||||||
@@ -162,19 +162,6 @@ it("rejects identical duplicate core fields before schema validation", () => {
|
|||||||
expect(() => decodeHarCapture(text, [])).toThrow("duplicate");
|
expect(() => decodeHarCapture(text, [])).toThrow("duplicate");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("names the violated HAR schema constraint without restating capture values", () => {
|
|
||||||
expect(() =>
|
|
||||||
decodeHarCapture(
|
|
||||||
JSON.stringify({
|
|
||||||
log: { creator: { name: "x", version: "1" }, entries: [] },
|
|
||||||
}),
|
|
||||||
[],
|
|
||||||
),
|
|
||||||
).toThrow(
|
|
||||||
"HAR schema validation failed: required (must have required property 'version').",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("preserves prototype-named producer members through the capture boundary", () => {
|
it("preserves prototype-named producer members through the capture boundary", () => {
|
||||||
const text = JSON.stringify(historicalHar()).replace(
|
const text = JSON.stringify(historicalHar()).replace(
|
||||||
'"cache":{}',
|
'"cache":{}',
|
||||||
|
|||||||
@@ -144,8 +144,7 @@ const projectHar = (
|
|||||||
(literal) =>
|
(literal) =>
|
||||||
item.includes(literal) ||
|
item.includes(literal) ||
|
||||||
contentBase64.includes(literal) ||
|
contentBase64.includes(literal) ||
|
||||||
sha256.includes(literal) ||
|
sha256.includes(literal),
|
||||||
String(bytes.length).includes(literal),
|
|
||||||
);
|
);
|
||||||
binary_fields.push(
|
binary_fields.push(
|
||||||
hidden
|
hidden
|
||||||
|
|||||||
@@ -23,13 +23,9 @@ export const createHarValidator = (): ((value: unknown) => void) => {
|
|||||||
allowMitmproxyAbsentPostData(value);
|
allowMitmproxyAbsentPostData(value);
|
||||||
if (!validate(value)) {
|
if (!validate(value)) {
|
||||||
const error = validate.errors?.[0];
|
const error = validate.errors?.[0];
|
||||||
// AJV messages name the violated constraint, such as the missing
|
|
||||||
// property, without restating any captured value.
|
|
||||||
throw new CaptureFormatError(
|
throw new CaptureFormatError(
|
||||||
"format",
|
"format",
|
||||||
error === undefined
|
`HAR schema validation failed: ${error?.keyword ?? "unknown constraint"}.`,
|
||||||
? "HAR schema validation failed: unknown constraint."
|
|
||||||
: `HAR schema validation failed: ${error.keyword} (${error.message ?? "no detail"}).`,
|
|
||||||
error?.instancePath ?? "",
|
error?.instancePath ?? "",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import { z } from "zod";
|
|||||||
import type { ExecutionOptions } from "../../application/AnalysisProvider.js";
|
import type { ExecutionOptions } from "../../application/AnalysisProvider.js";
|
||||||
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
||||||
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
|
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
|
||||||
import { ArtifactResourceScope } from "../../artifacts/ArtifactResourceScope.js";
|
|
||||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||||
import {
|
import {
|
||||||
AnalysisCapabilityUnavailableError,
|
AnalysisCapabilityUnavailableError,
|
||||||
@@ -27,7 +26,6 @@ import {
|
|||||||
} from "../../domain/analysisErrorCore.js";
|
} from "../../domain/analysisErrorCore.js";
|
||||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||||
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
||||||
import { analysisErrorWithCleanupFailure } from "../../domain/analysisErrorCleanup.js";
|
|
||||||
import { err, ok, type Result } from "../../domain/result.js";
|
import { err, ok, type Result } from "../../domain/result.js";
|
||||||
import {
|
import {
|
||||||
WEB_NETWORK_CAPTURE_LIMITS,
|
WEB_NETWORK_CAPTURE_LIMITS,
|
||||||
@@ -62,52 +60,18 @@ const replySchema = z.discriminatedUnion("ok", [
|
|||||||
|
|
||||||
/** One owned snapshot/process/root lifecycle for replaceable historical format decoders. */
|
/** One owned snapshot/process/root lifecycle for replaceable historical format decoders. */
|
||||||
export class HistoricalCaptureDecoder {
|
export class HistoricalCaptureDecoder {
|
||||||
readonly #resources: ArtifactResourceScope;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly adapters: readonly HistoricalCaptureFormatAdapter[],
|
readonly adapters: readonly HistoricalCaptureFormatAdapter[],
|
||||||
readonly environment: Readonly<NodeJS.ProcessEnv>,
|
readonly environment: Readonly<NodeJS.ProcessEnv>,
|
||||||
readonly createRuntime: () => Promise<
|
readonly createRuntime: () => Promise<
|
||||||
Pick<PrivateRuntimeRoot, "path" | "close">
|
Pick<PrivateRuntimeRoot, "path" | "close">
|
||||||
> = () => PrivateRuntimeRoot.create({ prefix: "rea-web-capture-" }),
|
> = () => PrivateRuntimeRoot.create({ prefix: "rea-web-capture-" }),
|
||||||
resources = new ArtifactResourceScope(),
|
) {}
|
||||||
) {
|
|
||||||
this.#resources = resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Retry retained readers and private roots at service shutdown. */
|
|
||||||
close(): Promise<void> {
|
|
||||||
return this.#resources.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Snapshot the selected artifact, decode it offline, and release private credentials and processes. */
|
/** Snapshot the selected artifact, decode it offline, and release private credentials and processes. */
|
||||||
async inspect(
|
async inspect(
|
||||||
input: InspectWebNetworkCaptureInput,
|
input: InspectWebNetworkCaptureInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
): Promise<Result<WebNetworkCapture, AnalysisError>> {
|
|
||||||
try {
|
|
||||||
return await this.#resources.run(() =>
|
|
||||||
this.inspectAdmitted(input, options),
|
|
||||||
);
|
|
||||||
} catch (cause: unknown) {
|
|
||||||
const error = historicalCaptureFailure(
|
|
||||||
input,
|
|
||||||
cause,
|
|
||||||
"capture-read",
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
return err(
|
|
||||||
redactExplicitFailure(
|
|
||||||
this.withReaderCleanup(error, cause),
|
|
||||||
input.sensitive_values,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async inspectAdmitted(
|
|
||||||
input: InspectWebNetworkCaptureInput,
|
|
||||||
options?: ExecutionOptions,
|
|
||||||
): Promise<Result<WebNetworkCapture, AnalysisError>> {
|
): Promise<Result<WebNetworkCapture, AnalysisError>> {
|
||||||
let runtime: Pick<PrivateRuntimeRoot, "path" | "close"> | undefined;
|
let runtime: Pick<PrivateRuntimeRoot, "path" | "close"> | undefined;
|
||||||
let result: Result<WebNetworkCapture, AnalysisError>;
|
let result: Result<WebNetworkCapture, AnalysisError>;
|
||||||
@@ -126,8 +90,6 @@ export class HistoricalCaptureDecoder {
|
|||||||
input.capture_path,
|
input.capture_path,
|
||||||
WEB_NETWORK_CAPTURE_LIMITS.inputBytes,
|
WEB_NETWORK_CAPTURE_LIMITS.inputBytes,
|
||||||
options?.signal,
|
options?.signal,
|
||||||
undefined,
|
|
||||||
this.#resources,
|
|
||||||
);
|
);
|
||||||
phase = "decoder";
|
phase = "decoder";
|
||||||
runtime = await this.createRuntime();
|
runtime = await this.createRuntime();
|
||||||
@@ -177,16 +139,9 @@ export class HistoricalCaptureDecoder {
|
|||||||
replyPath,
|
replyPath,
|
||||||
WEB_NETWORK_CAPTURE_LIMITS.outputBytes,
|
WEB_NETWORK_CAPTURE_LIMITS.outputBytes,
|
||||||
options?.signal,
|
options?.signal,
|
||||||
undefined,
|
|
||||||
this.#resources,
|
|
||||||
);
|
);
|
||||||
reply = replySchema.parse(JSON.parse(replyFile.bytes.toString("utf8")));
|
reply = replySchema.parse(JSON.parse(replyFile.bytes.toString("utf8")));
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
if (
|
|
||||||
cause instanceof ArtifactReaderFailure &&
|
|
||||||
cause.cleanup !== undefined
|
|
||||||
)
|
|
||||||
throw cause;
|
|
||||||
if (options?.signal?.aborted)
|
if (options?.signal?.aborted)
|
||||||
throw new AnalysisCancelledError(OPERATION);
|
throw new AnalysisCancelledError(OPERATION);
|
||||||
throw new AnalysisOutputError(
|
throw new AnalysisOutputError(
|
||||||
@@ -275,21 +230,17 @@ export class HistoricalCaptureDecoder {
|
|||||||
result = ok({ ...reply.value, ...common, format: input.format });
|
result = ok({ ...reply.value, ...common, format: input.format });
|
||||||
}
|
}
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
const error = historicalCaptureFailure(input, cause, phase, options);
|
|
||||||
result = err(
|
result = err(
|
||||||
redactExplicitFailure(
|
redactExplicitFailure(
|
||||||
this.withReaderCleanup(error, cause),
|
historicalCaptureFailure(input, cause, phase, options),
|
||||||
input.sensitive_values,
|
input.sensitive_values,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (runtime !== undefined) {
|
if (runtime !== undefined) {
|
||||||
const cleanup = await this.#resources.release({
|
try {
|
||||||
kind: "private-runtime-root",
|
await runtime.close();
|
||||||
resource: runtime.path,
|
} catch (cause: unknown) {
|
||||||
root: runtime,
|
|
||||||
});
|
|
||||||
if (cleanup.kind === "failed") {
|
|
||||||
return err(
|
return err(
|
||||||
redactExplicitFailure(
|
redactExplicitFailure(
|
||||||
new ProviderCleanupError(
|
new ProviderCleanupError(
|
||||||
@@ -300,12 +251,9 @@ export class HistoricalCaptureDecoder {
|
|||||||
previous_error: result.ok
|
previous_error: result.ok
|
||||||
? null
|
? null
|
||||||
: projectAnalysisError(result.error),
|
: projectAnalysisError(result.error),
|
||||||
reason:
|
reason: cause instanceof Error ? cause.message : String(cause),
|
||||||
cleanup.cause instanceof Error
|
|
||||||
? cleanup.cause.message
|
|
||||||
: String(cleanup.cause),
|
|
||||||
},
|
},
|
||||||
{ operation: OPERATION, cause: cleanup.cause },
|
{ operation: OPERATION },
|
||||||
),
|
),
|
||||||
input.sensitive_values,
|
input.sensitive_values,
|
||||||
),
|
),
|
||||||
@@ -316,34 +264,6 @@ export class HistoricalCaptureDecoder {
|
|||||||
? err(new AnalysisCancelledError(OPERATION))
|
? err(new AnalysisCancelledError(OPERATION))
|
||||||
: result;
|
: result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private withReaderCleanup(
|
|
||||||
primary: AnalysisError,
|
|
||||||
cause: unknown,
|
|
||||||
): AnalysisError {
|
|
||||||
if (
|
|
||||||
!(cause instanceof ArtifactReaderFailure) ||
|
|
||||||
cause.cleanup === undefined
|
|
||||||
)
|
|
||||||
return primary;
|
|
||||||
if (cause.reason === "unavailable")
|
|
||||||
return new ProviderCleanupError(
|
|
||||||
"web-network-capture",
|
|
||||||
cause.cleanup.resources,
|
|
||||||
{ reason: cause.cleanup.reason },
|
|
||||||
{ operation: OPERATION, cause },
|
|
||||||
);
|
|
||||||
const cleanup = new ProviderCleanupError(
|
|
||||||
"web-network-capture",
|
|
||||||
cause.cleanup.resources,
|
|
||||||
{
|
|
||||||
reason: cause.cleanup.reason,
|
|
||||||
previous_error: projectAnalysisError(primary),
|
|
||||||
},
|
|
||||||
{ operation: OPERATION, cause },
|
|
||||||
);
|
|
||||||
return analysisErrorWithCleanupFailure(primary, cleanup, OPERATION);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The Node capture decoder runs on this executable; only Node.js enforces its V8 heap flags. */
|
/** The Node capture decoder runs on this executable; only Node.js enforces its V8 heap flags. */
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import type {
|
|||||||
} from "../../application/WebModulePorts.js";
|
} from "../../application/WebModulePorts.js";
|
||||||
import type { WebScriptArtifactPort } from "../../application/WebScriptArtifactPort.js";
|
import type { WebScriptArtifactPort } from "../../application/WebScriptArtifactPort.js";
|
||||||
import type { ExecutionOptions } from "../../application/AnalysisProvider.js";
|
import type { ExecutionOptions } from "../../application/AnalysisProvider.js";
|
||||||
import { ArtifactResourceScope } from "../../artifacts/ArtifactResourceScope.js";
|
|
||||||
import { jsonObjectSchema } from "../../domain/jsonValue.js";
|
import { jsonObjectSchema } from "../../domain/jsonValue.js";
|
||||||
import { err, ok } from "../../domain/result.js";
|
import { err, ok } from "../../domain/result.js";
|
||||||
import type { WebModuleTraceInput } from "../../domain/webModuleTrace.js";
|
import type { WebModuleTraceInput } from "../../domain/webModuleTrace.js";
|
||||||
@@ -16,64 +15,14 @@ import {
|
|||||||
|
|
||||||
/** Add an explicitly selected import map to a verified captured-script source. */
|
/** Add an explicitly selected import map to a verified captured-script source. */
|
||||||
export class LocalWebModuleArtifacts implements WebModuleArtifactPort {
|
export class LocalWebModuleArtifacts implements WebModuleArtifactPort {
|
||||||
readonly scripts: WebScriptArtifactPort;
|
|
||||||
readonly #resources: ArtifactResourceScope;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
scripts?: WebScriptArtifactPort,
|
readonly scripts: WebScriptArtifactPort = new LocalWebScriptArtifacts(
|
||||||
resources = scripts instanceof LocalWebScriptArtifacts
|
"trace_web_module_imports",
|
||||||
? scripts.resources
|
),
|
||||||
: new ArtifactResourceScope(),
|
) {}
|
||||||
) {
|
|
||||||
this.#resources = resources;
|
|
||||||
this.scripts =
|
|
||||||
scripts ??
|
|
||||||
new LocalWebScriptArtifacts("trace_web_module_imports", resources);
|
|
||||||
}
|
|
||||||
|
|
||||||
async close(): Promise<void> {
|
|
||||||
const closeScript =
|
|
||||||
this.scripts instanceof LocalWebScriptArtifacts &&
|
|
||||||
this.scripts.resources === this.#resources
|
|
||||||
? undefined
|
|
||||||
: this.scripts.close?.bind(this.scripts);
|
|
||||||
const results = await Promise.allSettled([
|
|
||||||
Promise.resolve().then(() => this.#resources.close()),
|
|
||||||
...(closeScript === undefined
|
|
||||||
? []
|
|
||||||
: [Promise.resolve().then(closeScript)]),
|
|
||||||
]);
|
|
||||||
const failures = results.flatMap((result) =>
|
|
||||||
result.status === "rejected" ? [result.reason] : [],
|
|
||||||
);
|
|
||||||
if (failures.length > 0)
|
|
||||||
throw new AggregateError(failures, "Web module artifact cleanup failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Read selected source and optional map without website requests. */
|
/** Read selected source and optional map without website requests. */
|
||||||
async load(input: WebModuleTraceInput, options?: ExecutionOptions) {
|
async load(input: WebModuleTraceInput, options?: ExecutionOptions) {
|
||||||
try {
|
|
||||||
return await this.#resources.run(() => this.#load(input, options));
|
|
||||||
} catch (cause: unknown) {
|
|
||||||
return err(
|
|
||||||
webArtifactReadError(
|
|
||||||
cause,
|
|
||||||
{
|
|
||||||
operation: "trace_web_module_imports",
|
|
||||||
field:
|
|
||||||
input.import_map === undefined
|
|
||||||
? ["manifest_path"]
|
|
||||||
: ["import_map", "path"],
|
|
||||||
targetPath: input.import_map?.path ?? input.manifest_path,
|
|
||||||
callerSelected: input.import_map !== undefined,
|
|
||||||
},
|
|
||||||
options?.signal,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async #load(input: WebModuleTraceInput, options?: ExecutionOptions) {
|
|
||||||
const loaded = await this.scripts.load(input, options);
|
const loaded = await this.scripts.load(input, options);
|
||||||
if (!loaded.ok) return loaded;
|
if (!loaded.ok) return loaded;
|
||||||
if (input.import_map === undefined)
|
if (input.import_map === undefined)
|
||||||
@@ -84,7 +33,6 @@ export class LocalWebModuleArtifacts implements WebModuleArtifactPort {
|
|||||||
selected.path,
|
selected.path,
|
||||||
4 * 1024 * 1024,
|
4 * 1024 * 1024,
|
||||||
options?.signal,
|
options?.signal,
|
||||||
this.#resources,
|
|
||||||
);
|
);
|
||||||
const importMap: WebModuleArtifacts["importMap"] = {
|
const importMap: WebModuleArtifacts["importMap"] = {
|
||||||
file: {
|
file: {
|
||||||
|
|||||||
@@ -1,12 +1,3 @@
|
|||||||
import {
|
|
||||||
type InspectPacketFieldsInput,
|
|
||||||
packetFieldsCatalogSchema,
|
|
||||||
} from "../domain/captures/packetFields.js";
|
|
||||||
import {
|
|
||||||
parseFieldDiscovery,
|
|
||||||
FieldDiscoveryBudgetError,
|
|
||||||
FIELD_RECORD_BUDGET,
|
|
||||||
} from "./parseFieldDiscovery.js";
|
|
||||||
import {
|
import {
|
||||||
readLinuxResourceLimits,
|
readLinuxResourceLimits,
|
||||||
type LinuxResourceLimits,
|
type LinuxResourceLimits,
|
||||||
@@ -100,31 +91,17 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||||
return this.#resources.run(
|
return this.#resources.run(
|
||||||
() => this.#executeRequest(input, options),
|
() => this.#inspect(input, options),
|
||||||
options?.signal,
|
options?.signal,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
inspectFields(
|
|
||||||
input: InspectPacketFieldsInput,
|
|
||||||
options?: ExecutionOptions,
|
|
||||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
|
||||||
return this.#resources.run(
|
|
||||||
() => this.#executeRequest(input, options),
|
|
||||||
options?.signal,
|
|
||||||
"inspect_packet_fields",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
close(): Promise<void> {
|
close(): Promise<void> {
|
||||||
return this.#resources.close();
|
return this.#resources.close();
|
||||||
}
|
}
|
||||||
async #executeRequest(
|
async #inspect(
|
||||||
input: InspectPacketCaptureInput | InspectPacketFieldsInput,
|
input: InspectPacketCaptureInput,
|
||||||
options?: ExecutionOptions,
|
options?: ExecutionOptions,
|
||||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||||
const operation = "path" in input ? OPERATION : "inspect_packet_fields";
|
|
||||||
// TShark 4.6.9 emits a 22.3 MB glossary; keep capture output capped at 4 MiB.
|
|
||||||
const limits =
|
|
||||||
"path" in input ? LIMITS : { ...LIMITS, output_bytes: 32 * 1024 * 1024 };
|
|
||||||
let phase:
|
let phase:
|
||||||
| "configuration"
|
| "configuration"
|
||||||
| "artifact"
|
| "artifact"
|
||||||
@@ -132,12 +109,12 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
| "producer"
|
| "producer"
|
||||||
| "integrity" = "configuration";
|
| "integrity" = "configuration";
|
||||||
let capturedOutput: AnalysisCapturedOutput | undefined;
|
let capturedOutput: AnalysisCapturedOutput | undefined;
|
||||||
let resourcePath = "path" in input ? input.path : "TShark field glossary";
|
let resourcePath = input.path;
|
||||||
let effectiveLimits: LinuxResourceLimits | undefined;
|
let effectiveLimits: LinuxResourceLimits | undefined;
|
||||||
let root: ArtifactAnalysisRuntime | undefined;
|
let root: ArtifactAnalysisRuntime | undefined;
|
||||||
let result: Result<AnalysisExecution, AnalysisError>;
|
let result: Result<AnalysisExecution, AnalysisError>;
|
||||||
try {
|
try {
|
||||||
if (options?.signal?.aborted) throw new AnalysisCancelledError(operation);
|
if (options?.signal?.aborted) throw new AnalysisCancelledError(OPERATION);
|
||||||
await this.#resources.release();
|
await this.#resources.release();
|
||||||
if (this.platform !== "linux")
|
if (this.platform !== "linux")
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -164,7 +141,7 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
64 * 1024 * 1024,
|
64 * 1024 * 1024,
|
||||||
options?.signal,
|
options?.signal,
|
||||||
);
|
);
|
||||||
effectiveLimits = await this.#resources.readLimits(limits);
|
effectiveLimits = await this.#resources.readLimits(LIMITS);
|
||||||
const limitArguments = [
|
const limitArguments = [
|
||||||
`--as=${effectiveLimits.address_space_bytes}:${effectiveLimits.address_space_bytes}`,
|
`--as=${effectiveLimits.address_space_bytes}:${effectiveLimits.address_space_bytes}`,
|
||||||
`--fsize=${effectiveLimits.file_bytes}:${effectiveLimits.file_bytes}`,
|
`--fsize=${effectiveLimits.file_bytes}:${effectiveLimits.file_bytes}`,
|
||||||
@@ -175,7 +152,7 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
];
|
];
|
||||||
phase = "workspace";
|
phase = "workspace";
|
||||||
root = await this.createRuntime();
|
root = await this.createRuntime();
|
||||||
this.#resources.retain(root, undefined, operation);
|
this.#resources.retain(root, undefined);
|
||||||
const snapshotPath = join(root.path, "capture");
|
const snapshotPath = join(root.path, "capture");
|
||||||
const configurationPath = join(root.path, "configuration");
|
const configurationPath = join(root.path, "configuration");
|
||||||
await mkdir(configurationPath, { mode: 0o700 });
|
await mkdir(configurationPath, { mode: 0o700 });
|
||||||
@@ -193,8 +170,8 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
timeoutMs: limits.command_timeout_ms,
|
timeoutMs: LIMITS.command_timeout_ms,
|
||||||
diagnosticBytes: limits.output_bytes,
|
diagnosticBytes: LIMITS.output_bytes,
|
||||||
acceptNonZeroExit: true,
|
acceptNonZeroExit: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -223,24 +200,24 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
);
|
);
|
||||||
if (currentLimiter.sha256 !== limiterIdentity.sha256)
|
if (currentLimiter.sha256 !== limiterIdentity.sha256)
|
||||||
throw new AnalysisArtifactChangedError(
|
throw new AnalysisArtifactChangedError(
|
||||||
operation,
|
OPERATION,
|
||||||
limiter,
|
limiter,
|
||||||
"Configured resource limiter changed during analysis.",
|
"Configured resource limiter changed during analysis.",
|
||||||
{ capturedOutput },
|
{ capturedOutput },
|
||||||
);
|
);
|
||||||
if (current.sha256 !== tool.sha256)
|
if (current.sha256 !== tool.sha256)
|
||||||
throw new AnalysisArtifactChangedError(
|
throw new AnalysisArtifactChangedError(
|
||||||
operation,
|
OPERATION,
|
||||||
command,
|
command,
|
||||||
"Configured TShark executable changed during analysis.",
|
"Configured TShark executable changed during analysis.",
|
||||||
{ capturedOutput },
|
{ capturedOutput },
|
||||||
);
|
);
|
||||||
phase = previousPhase;
|
phase = previousPhase;
|
||||||
resourcePath = "path" in input ? input.path : command;
|
resourcePath = input.path;
|
||||||
if (output.exitCode !== 0)
|
if (output.exitCode !== 0)
|
||||||
throw new ProviderAdapterError(
|
throw new ProviderAdapterError(
|
||||||
TSHARK_PROVIDER_IDENTITY.id,
|
TSHARK_PROVIDER_IDENTITY.id,
|
||||||
operation,
|
OPERATION,
|
||||||
{
|
{
|
||||||
diagnostics: {
|
diagnostics: {
|
||||||
exit_code: output.exitCode ?? null,
|
exit_code: output.exitCode ?? null,
|
||||||
@@ -261,51 +238,6 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
throw new Error(
|
throw new Error(
|
||||||
"Expected TShark 4.x; inspect the selected installation.",
|
"Expected TShark 4.x; inspect the selected installation.",
|
||||||
);
|
);
|
||||||
const metadata = (args: readonly string[], diagnostics: string) => ({
|
|
||||||
diagnostics,
|
|
||||||
tool: {
|
|
||||||
configured_path: configured,
|
|
||||||
path: command,
|
|
||||||
sha256: tool.sha256,
|
|
||||||
version_banner: version.stdout.text,
|
|
||||||
version_diagnostics: version.stderr.text,
|
|
||||||
arguments: [...args],
|
|
||||||
},
|
|
||||||
resource_limiter: {
|
|
||||||
configured_path: configuredLimiter,
|
|
||||||
path: limiter,
|
|
||||||
sha256: limiterIdentity.sha256,
|
|
||||||
arguments: limitArguments,
|
|
||||||
},
|
|
||||||
limits: { ...limits, ...effectiveLimits },
|
|
||||||
hardware_acquisition: "not-performed" as const,
|
|
||||||
});
|
|
||||||
if (!("path" in input)) {
|
|
||||||
phase = "producer";
|
|
||||||
const args = ["-G", "fields"];
|
|
||||||
const output = await execute(args);
|
|
||||||
const report = packetFieldsCatalogSchema.parse({
|
|
||||||
selection: input,
|
|
||||||
...parseFieldDiscovery(output.stdout.text, input),
|
|
||||||
...metadata(args, output.stderr.text),
|
|
||||||
limits: {
|
|
||||||
...limits,
|
|
||||||
...effectiveLimits,
|
|
||||||
record_budget_bytes: FIELD_RECORD_BUDGET,
|
|
||||||
},
|
|
||||||
configuration: "private-empty-personal-profile",
|
|
||||||
});
|
|
||||||
result = ok(
|
|
||||||
createAnalysisExecution(report, TSHARK_PROVIDER_IDENTITY, {
|
|
||||||
subject: { path: command, sha256: tool.sha256, format: "file" },
|
|
||||||
limitations: [
|
|
||||||
"Protocol and field registrations describe the selected installation, not traffic observed in a capture. Duplicate abbreviations remain distinct producer records with source line numbers.",
|
|
||||||
"Each request probes again without caching. The private empty personal profile does not fingerprint or isolate installed libraries, global configuration or plugins; they remain trusted.",
|
|
||||||
"No capture file, interface or device is opened. Resource ceilings do not constitute an OS sandbox. Glossary output is capped at 32 MiB and selected record representation at 8 MiB before expansion.",
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
phase = "artifact";
|
phase = "artifact";
|
||||||
const selected = await this.#resources.read(
|
const selected = await this.#resources.read(
|
||||||
input.path,
|
input.path,
|
||||||
@@ -330,13 +262,12 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
...(input.packet_limit === null
|
...(input.packet_limit === null
|
||||||
? []
|
? []
|
||||||
: ["-c", String(input.packet_limit)]),
|
: ["-c", String(input.packet_limit)]),
|
||||||
...(input.display_filter === null
|
...(input.display_filter === null ? [] : ["-Y", input.display_filter]),
|
||||||
? []
|
|
||||||
: ["-Y", input.display_filter]),
|
|
||||||
...input.decode_as.flatMap((value) => ["-d", value]),
|
...input.decode_as.flatMap((value) => ["-d", value]),
|
||||||
...[...new Set(["frame.number", ...input.fields])].flatMap(
|
...[...new Set(["frame.number", ...input.fields])].flatMap((field) => [
|
||||||
(field) => ["-e", field],
|
"-e",
|
||||||
),
|
field,
|
||||||
|
]),
|
||||||
];
|
];
|
||||||
const output = await execute(args);
|
const output = await execute(args);
|
||||||
phase = "integrity";
|
phase = "integrity";
|
||||||
@@ -346,13 +277,13 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
.sha256 !== selected.sha256
|
.sha256 !== selected.sha256
|
||||||
)
|
)
|
||||||
throw new AnalysisArtifactChangedError(
|
throw new AnalysisArtifactChangedError(
|
||||||
operation,
|
OPERATION,
|
||||||
snapshotPath,
|
snapshotPath,
|
||||||
"TShark changed the private capture copy.",
|
"TShark changed the private capture copy.",
|
||||||
capturedOutput === undefined ? {} : { capturedOutput },
|
capturedOutput === undefined ? {} : { capturedOutput },
|
||||||
);
|
);
|
||||||
phase = "producer";
|
phase = "producer";
|
||||||
resourcePath = "path" in input ? input.path : command;
|
resourcePath = input.path;
|
||||||
const matchingPackets = parsePacketOutput(
|
const matchingPackets = parsePacketOutput(
|
||||||
output.stdout.text,
|
output.stdout.text,
|
||||||
input.fields,
|
input.fields,
|
||||||
@@ -361,8 +292,7 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
const end =
|
const end =
|
||||||
input.match_limit === null
|
input.match_limit === null
|
||||||
? matchingPackets.length
|
? matchingPackets.length
|
||||||
: start +
|
: start + Math.min(input.match_limit, matchingPackets.length - start);
|
||||||
Math.min(input.match_limit, matchingPackets.length - start);
|
|
||||||
const packets = matchingPackets.slice(start, end);
|
const packets = matchingPackets.slice(start, end);
|
||||||
const report = packetCaptureSchema.parse({
|
const report = packetCaptureSchema.parse({
|
||||||
artifact: {
|
artifact: {
|
||||||
@@ -380,7 +310,23 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
read_scope:
|
read_scope:
|
||||||
input.packet_limit === null ? "to-eof" : "up-to-input-packet-limit",
|
input.packet_limit === null ? "to-eof" : "up-to-input-packet-limit",
|
||||||
configuration: "private-empty-personal-profile",
|
configuration: "private-empty-personal-profile",
|
||||||
...metadata(args, output.stderr.text),
|
diagnostics: output.stderr.text,
|
||||||
|
tool: {
|
||||||
|
configured_path: configured,
|
||||||
|
path: command,
|
||||||
|
sha256: tool.sha256,
|
||||||
|
version_banner: version.stdout.text,
|
||||||
|
version_diagnostics: version.stderr.text,
|
||||||
|
arguments: args,
|
||||||
|
},
|
||||||
|
resource_limiter: {
|
||||||
|
configured_path: configuredLimiter,
|
||||||
|
path: limiter,
|
||||||
|
sha256: limiterIdentity.sha256,
|
||||||
|
arguments: limitArguments,
|
||||||
|
},
|
||||||
|
limits: { ...LIMITS, ...effectiveLimits },
|
||||||
|
hardware_acquisition: "not-performed",
|
||||||
});
|
});
|
||||||
result = ok(
|
result = ok(
|
||||||
createAnalysisExecution(report, TSHARK_PROVIDER_IDENTITY, {
|
createAnalysisExecution(report, TSHARK_PROVIDER_IDENTITY, {
|
||||||
@@ -399,14 +345,13 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
if (
|
if (
|
||||||
root !== undefined &&
|
root !== undefined &&
|
||||||
cause instanceof OwnedCommandFailure &&
|
cause instanceof OwnedCommandFailure &&
|
||||||
cause.cleanupOwner !== undefined
|
cause.cleanupOwner !== undefined
|
||||||
)
|
)
|
||||||
this.#resources.retain(root, cause.cleanupOwner, operation);
|
this.#resources.retain(root, cause.cleanupOwner);
|
||||||
result = err(
|
result = err(
|
||||||
this.#failure(
|
this.#failure(
|
||||||
cause,
|
cause,
|
||||||
@@ -415,23 +360,18 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
root?.path ?? null,
|
root?.path ?? null,
|
||||||
effectiveLimits,
|
effectiveLimits,
|
||||||
capturedOutput,
|
capturedOutput,
|
||||||
operation,
|
|
||||||
limits,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return this.#resources.finish(
|
return this.#resources.finish(result, (execution) =>
|
||||||
result,
|
|
||||||
(execution) =>
|
|
||||||
createEvidence(execution.subject ?? undefined, execution.provider, {
|
createEvidence(execution.subject ?? undefined, execution.provider, {
|
||||||
operation,
|
operation: OPERATION,
|
||||||
parameters: input,
|
parameters: input,
|
||||||
result: execution.result,
|
result: execution.result,
|
||||||
confidence: "observed",
|
confidence: "observed",
|
||||||
locations: execution.locations,
|
locations: execution.locations,
|
||||||
limitations: execution.limitations,
|
limitations: execution.limitations,
|
||||||
}),
|
}),
|
||||||
operation,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#failure(
|
#failure(
|
||||||
@@ -446,11 +386,6 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
workspacePath: string | null,
|
workspacePath: string | null,
|
||||||
effectiveLimits: LinuxResourceLimits | undefined,
|
effectiveLimits: LinuxResourceLimits | undefined,
|
||||||
observedOutput: AnalysisCapturedOutput | undefined,
|
observedOutput: AnalysisCapturedOutput | undefined,
|
||||||
operation = OPERATION,
|
|
||||||
limits: {
|
|
||||||
readonly output_bytes: number;
|
|
||||||
readonly command_timeout_ms: number;
|
|
||||||
} = LIMITS,
|
|
||||||
): AnalysisError {
|
): AnalysisError {
|
||||||
if (cause instanceof AnalysisError) return cause;
|
if (cause instanceof AnalysisError) return cause;
|
||||||
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined)
|
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined)
|
||||||
@@ -458,34 +393,15 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
cause.cleanup,
|
cause.cleanup,
|
||||||
cause,
|
cause,
|
||||||
observedOutput,
|
observedOutput,
|
||||||
operation,
|
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
(cause instanceof Error && cause.name === "AbortError") ||
|
(cause instanceof Error && cause.name === "AbortError") ||
|
||||||
(cause instanceof ArtifactReaderFailure && cause.reason === "cancelled")
|
(cause instanceof ArtifactReaderFailure && cause.reason === "cancelled")
|
||||||
)
|
)
|
||||||
return new AnalysisCancelledError(operation, { cause });
|
return new AnalysisCancelledError(OPERATION, { cause });
|
||||||
if (cause instanceof FieldDiscoveryBudgetError)
|
|
||||||
return new AnalysisResourceConstraintError(
|
|
||||||
operation,
|
|
||||||
"memory",
|
|
||||||
cause.message,
|
|
||||||
{ record_budget_bytes: FIELD_RECORD_BUDGET },
|
|
||||||
{
|
|
||||||
cause,
|
|
||||||
...(observedOutput === undefined
|
|
||||||
? {}
|
|
||||||
: { capturedOutput: observedOutput }),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const reason = cause instanceof Error ? cause.message : String(cause);
|
const reason = cause instanceof Error ? cause.message : String(cause);
|
||||||
if (cause instanceof OwnedCommandFailure)
|
if (cause instanceof OwnedCommandFailure)
|
||||||
return this.#resources.commandFailure(
|
return this.#resources.commandFailure(cause, LIMITS, effectiveLimits);
|
||||||
cause,
|
|
||||||
limits,
|
|
||||||
effectiveLimits,
|
|
||||||
operation,
|
|
||||||
);
|
|
||||||
if (phase === "workspace") {
|
if (phase === "workspace") {
|
||||||
const code =
|
const code =
|
||||||
cause instanceof Error &&
|
cause instanceof Error &&
|
||||||
@@ -495,13 +411,13 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
: null;
|
: null;
|
||||||
if (code === "ENOSPC" || code === "EDQUOT" || code === "EFBIG")
|
if (code === "ENOSPC" || code === "EDQUOT" || code === "EFBIG")
|
||||||
return new AnalysisResourceConstraintError(
|
return new AnalysisResourceConstraintError(
|
||||||
operation,
|
OPERATION,
|
||||||
"file-size",
|
"file-size",
|
||||||
`Private analysis workspace failed (${code}): ${reason}`,
|
`Private analysis workspace failed (${code}): ${reason}`,
|
||||||
{ workspace_path: workspacePath, system_code: code },
|
{ workspace_path: workspacePath, system_code: code },
|
||||||
{ cause },
|
{ cause },
|
||||||
);
|
);
|
||||||
return new ProviderAdapterError(TSHARK_PROVIDER_IDENTITY.id, operation, {
|
return new ProviderAdapterError(TSHARK_PROVIDER_IDENTITY.id, OPERATION, {
|
||||||
cause,
|
cause,
|
||||||
userMessage: `Cannot prepare the private analysis workspace: ${reason}`,
|
userMessage: `Cannot prepare the private analysis workspace: ${reason}`,
|
||||||
diagnostics: {
|
diagnostics: {
|
||||||
@@ -524,12 +440,12 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
["limit", "integrity", "path"].includes(cause.reason)
|
["limit", "integrity", "path"].includes(cause.reason)
|
||||||
)
|
)
|
||||||
return new AnalysisArtifactChangedError(
|
return new AnalysisArtifactChangedError(
|
||||||
operation,
|
OPERATION,
|
||||||
path,
|
path,
|
||||||
`Post-run identity verification failed for ${path}: ${reason}`,
|
`Post-run identity verification failed for ${path}: ${reason}`,
|
||||||
detail,
|
detail,
|
||||||
);
|
);
|
||||||
return new ProviderAdapterError(TSHARK_PROVIDER_IDENTITY.id, operation, {
|
return new ProviderAdapterError(TSHARK_PROVIDER_IDENTITY.id, OPERATION, {
|
||||||
...detail,
|
...detail,
|
||||||
diagnostics: { stage: "integrity", resource_path: path, reason },
|
diagnostics: { stage: "integrity", resource_path: path, reason },
|
||||||
});
|
});
|
||||||
@@ -537,13 +453,10 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
if (phase === "configuration")
|
if (phase === "configuration")
|
||||||
return new AnalysisCapabilityUnavailableError(
|
return new AnalysisCapabilityUnavailableError(
|
||||||
TSHARK_PROVIDER_IDENTITY.id,
|
TSHARK_PROVIDER_IDENTITY.id,
|
||||||
operation,
|
OPERATION,
|
||||||
reason,
|
reason,
|
||||||
{
|
{
|
||||||
cause,
|
cause,
|
||||||
...(observedOutput === undefined
|
|
||||||
? {}
|
|
||||||
: { capturedOutput: observedOutput }),
|
|
||||||
userMessage: `${reason} On Linux, configure TShark 4.x through REA_TSHARK_COMMAND and util-linux prlimit through REA_TSHARK_PRLIMIT_COMMAND (default /usr/bin/prlimit).`,
|
userMessage: `${reason} On Linux, configure TShark 4.x through REA_TSHARK_COMMAND and util-linux prlimit through REA_TSHARK_PRLIMIT_COMMAND (default /usr/bin/prlimit).`,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -553,14 +466,14 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
cause.reason === "limit"
|
cause.reason === "limit"
|
||||||
)
|
)
|
||||||
return new AnalysisResourceConstraintError(
|
return new AnalysisResourceConstraintError(
|
||||||
operation,
|
OPERATION,
|
||||||
"file-size",
|
"file-size",
|
||||||
reason,
|
reason,
|
||||||
{ input_bytes: LIMITS.input_bytes },
|
{ input_bytes: LIMITS.input_bytes },
|
||||||
{ cause },
|
{ cause },
|
||||||
);
|
);
|
||||||
if (cause instanceof ArtifactReaderFailure && cause.reason === "integrity")
|
if (cause instanceof ArtifactReaderFailure && cause.reason === "integrity")
|
||||||
return new AnalysisArtifactChangedError(operation, path, reason, {
|
return new AnalysisArtifactChangedError(OPERATION, path, reason, {
|
||||||
cause,
|
cause,
|
||||||
});
|
});
|
||||||
if (
|
if (
|
||||||
@@ -569,18 +482,13 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
|||||||
"code" in cause &&
|
"code" in cause &&
|
||||||
(cause.code === "EACCES" || cause.code === "EPERM")
|
(cause.code === "EACCES" || cause.code === "EPERM")
|
||||||
)
|
)
|
||||||
return new AnalysisAccessDeniedError(operation, path, cause.code, {
|
return new AnalysisAccessDeniedError(OPERATION, path, cause.code, {
|
||||||
cause,
|
cause,
|
||||||
});
|
});
|
||||||
if (phase === "artifact")
|
if (phase === "artifact")
|
||||||
return new AnalysisInputError(operation, { cause }, [
|
return new AnalysisInputError(OPERATION, { cause }, [
|
||||||
{ path: ["path"], reason: "invalid_value", message: reason },
|
{ path: ["path"], reason: "invalid_value", message: reason },
|
||||||
]);
|
]);
|
||||||
return new AnalysisOutputError(operation, reason, {
|
return new AnalysisOutputError(OPERATION, reason, { cause });
|
||||||
cause,
|
|
||||||
...(observedOutput === undefined
|
|
||||||
? {}
|
|
||||||
: { capturedOutput: observedOutput }),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
import type {
|
|
||||||
InspectPacketFieldsInput,
|
|
||||||
PacketFieldRecord,
|
|
||||||
} from "../domain/captures/packetFields.js";
|
|
||||||
|
|
||||||
export class FieldDiscoveryBudgetError extends Error {}
|
|
||||||
export const FIELD_RECORD_BUDGET = 8 * 1024 * 1024;
|
|
||||||
|
|
||||||
/** TShark -G fields: P/name/abbreviation or F/name/abbreviation/type/parent/base/mask/blurb. */
|
|
||||||
export const parseFieldDiscovery = (
|
|
||||||
text: string,
|
|
||||||
input: InspectPacketFieldsInput,
|
|
||||||
) => {
|
|
||||||
const copy = (value: string) =>
|
|
||||||
Buffer.from(value, "utf16le").toString("utf16le");
|
|
||||||
const query = input.query.toLowerCase();
|
|
||||||
const records: PacketFieldRecord[] = [];
|
|
||||||
let examined = 0,
|
|
||||||
matching = 0,
|
|
||||||
sourceLine = 0,
|
|
||||||
budget = 0;
|
|
||||||
// Walk the bounded text once; allocate record objects only for the requested page.
|
|
||||||
for (let start = 0; start < text.length;) {
|
|
||||||
const end = text.indexOf("\n", start);
|
|
||||||
let line = text.slice(start, end < 0 ? text.length : end);
|
|
||||||
start = end < 0 ? text.length : end + 1;
|
|
||||||
sourceLine++;
|
|
||||||
if (line.endsWith("\r")) line = line.slice(0, -1);
|
|
||||||
const columns = line.split("\t", 9);
|
|
||||||
const [tag, name, abbreviation] = columns;
|
|
||||||
if (
|
|
||||||
!(
|
|
||||||
(tag === "P" && columns.length === 3) ||
|
|
||||||
(tag === "F" && columns.length === 8)
|
|
||||||
) ||
|
|
||||||
name === undefined ||
|
|
||||||
abbreviation === undefined ||
|
|
||||||
abbreviation === ""
|
|
||||||
)
|
|
||||||
throw new Error(
|
|
||||||
`Malformed TShark field glossary record at line ${sourceLine}`,
|
|
||||||
);
|
|
||||||
if ((input.kind === "protocols") !== (tag === "P")) continue;
|
|
||||||
examined++;
|
|
||||||
if (
|
|
||||||
input.protocol !== null &&
|
|
||||||
(tag === "P" ? abbreviation : columns[4]) !== input.protocol
|
|
||||||
)
|
|
||||||
continue;
|
|
||||||
if (
|
|
||||||
![name, abbreviation, ...(tag === "F" ? [columns[7] ?? ""] : [])].some(
|
|
||||||
(value) => value.toLowerCase().includes(query),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
continue;
|
|
||||||
matching++;
|
|
||||||
if (
|
|
||||||
matching <= input.offset ||
|
|
||||||
records.length >= (input.limit ?? Number.MAX_SAFE_INTEGER)
|
|
||||||
)
|
|
||||||
continue;
|
|
||||||
// Six bytes per source byte covers worst-case JSON escaping, plus record bookkeeping.
|
|
||||||
budget += Buffer.byteLength(line, "utf8") * 6 + 512;
|
|
||||||
if (budget > FIELD_RECORD_BUDGET)
|
|
||||||
throw new FieldDiscoveryBudgetError(
|
|
||||||
"Selected glossary records exceed the 8 MiB representation budget; narrow the query or page size",
|
|
||||||
);
|
|
||||||
// Detach retained fields from the much larger producer string.
|
|
||||||
records.push({
|
|
||||||
source_line: sourceLine,
|
|
||||||
kind: tag === "P" ? "protocol" : "field",
|
|
||||||
name: copy(name),
|
|
||||||
abbreviation: copy(abbreviation),
|
|
||||||
field_type: tag === "F" ? copy(columns[3] ?? "") : null,
|
|
||||||
parent_protocol: tag === "F" ? copy(columns[4] ?? "") : null,
|
|
||||||
display_base: tag === "F" ? copy(columns[5] ?? "") : null,
|
|
||||||
bitmask: tag === "F" ? copy(columns[6] ?? "") : null,
|
|
||||||
description: tag === "F" ? copy(columns[7] ?? "") : null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (sourceLine === 0)
|
|
||||||
throw new Error("TShark returned an empty field glossary");
|
|
||||||
return {
|
|
||||||
records,
|
|
||||||
output_window: {
|
|
||||||
examined,
|
|
||||||
matching,
|
|
||||||
returned: records.length,
|
|
||||||
has_more: Math.max(0, matching - input.offset) > records.length,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -62,17 +62,15 @@ export const registerApktoolCommands = (
|
|||||||
.describe(
|
.describe(
|
||||||
"Project strings from res/values-<locale> instead of the default",
|
"Project strings from res/values-<locale> instead of the default",
|
||||||
),
|
),
|
||||||
strings: z
|
"no-strings": z
|
||||||
.boolean()
|
.boolean()
|
||||||
.default(true)
|
.default(false)
|
||||||
.describe(
|
.describe("Skip projecting string resources"),
|
||||||
"Include string resources; use --no-strings to skip projecting them",
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
run: ({ args, options }) =>
|
run: ({ args, options }) =>
|
||||||
execute(CLI_COMMANDS.decodeAndroidResources, "decode_android_resources", {
|
execute(CLI_COMMANDS.decodeAndroidResources, "decode_android_resources", {
|
||||||
path: args.path,
|
path: args.path,
|
||||||
include_strings: options.strings,
|
include_strings: !options["no-strings"],
|
||||||
...(options.locale === undefined ? {} : { locale: options.locale }),
|
...(options.locale === undefined ? {} : { locale: options.locale }),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ import {
|
|||||||
} from "../composition/binaryDiagnostics.js";
|
} from "../composition/binaryDiagnostics.js";
|
||||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||||
import { logCliCommand } from "../cliLogging.js";
|
import { logCliCommand } from "../cliLogging.js";
|
||||||
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||||
import type { Logger } from "pino";
|
import type { Logger } from "pino";
|
||||||
import type { CliInstance } from "./types.js";
|
import type { CliInstance } from "./types.js";
|
||||||
import { withCommandCancellation } from "./commandCancellation.js";
|
import { withCommandCancellation } from "./commandCancellation.js";
|
||||||
import { inspectPeResourcesInputSchema } from "../domain/native/peResources.js";
|
import { inspectPeResourcesInputSchema } from "../domain/native/peResources.js";
|
||||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
||||||
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
||||||
|
|
||||||
/** Inspect operator-selected files through the same shared workflow as MCP. */
|
/** Inspect operator-selected files through the same shared workflow as MCP. */
|
||||||
export const registerBinaryDiagnosticsCommands = (
|
export const registerBinaryDiagnosticsCommands = (
|
||||||
@@ -20,6 +19,7 @@ export const registerBinaryDiagnosticsCommands = (
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
environment: Readonly<NodeJS.ProcessEnv>,
|
environment: Readonly<NodeJS.ProcessEnv>,
|
||||||
): void => {
|
): void => {
|
||||||
|
const pe = createPeResourcesService();
|
||||||
cli.command(CLI_COMMANDS.inspectPeResources, {
|
cli.command(CLI_COMMANDS.inspectPeResources, {
|
||||||
description:
|
description:
|
||||||
"Inspect PE resource identities, payload ranges, hashes and icon-group relationships",
|
"Inspect PE resource identities, payload ranges, hashes and icon-group relationships",
|
||||||
@@ -29,28 +29,19 @@ export const registerBinaryDiagnosticsCommands = (
|
|||||||
maxEntries: inspectPeResourcesInputSchema.shape.max_entries,
|
maxEntries: inspectPeResourcesInputSchema.shape.max_entries,
|
||||||
}),
|
}),
|
||||||
run: ({ args, options }) =>
|
run: ({ args, options }) =>
|
||||||
withCommandCancellation(async (signal) => {
|
withCommandCancellation((signal) =>
|
||||||
const pe = createPeResourcesService();
|
logCliCommand(logger, CLI_COMMANDS.inspectPeResources, async () => {
|
||||||
return await logCliCommand(
|
const result = await pe.inspect(
|
||||||
logger,
|
|
||||||
CLI_COMMANDS.inspectPeResources,
|
|
||||||
async () =>
|
|
||||||
finishAnalysisCommand(
|
|
||||||
() =>
|
|
||||||
pe.inspect(
|
|
||||||
{
|
{
|
||||||
path: resolve(args.path),
|
path: resolve(args.path),
|
||||||
max_file_bytes: options.maxFileBytes,
|
max_file_bytes: options.maxFileBytes,
|
||||||
max_entries: options.maxEntries,
|
max_entries: options.maxEntries,
|
||||||
},
|
},
|
||||||
{ signal },
|
{ signal },
|
||||||
),
|
|
||||||
pe,
|
|
||||||
"rea-pe-resources",
|
|
||||||
"inspect_pe_resources",
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
return result.ok ? result.value : projectAnalysisError(result.error);
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
const service = createBinaryLayoutService(environment);
|
const service = createBinaryLayoutService(environment);
|
||||||
cli.command(CLI_COMMANDS.inspectBinaryLayout, {
|
cli.command(CLI_COMMANDS.inspectBinaryLayout, {
|
||||||
|
|||||||
+31
-51
@@ -1,6 +1,8 @@
|
|||||||
import { inspectPacketFieldsInputSchema } from "../domain/captures/packetFields.js";
|
|
||||||
import { z } from "incur";
|
import { z } from "incur";
|
||||||
import type { PacketCaptureService } from "../application/captures/PacketCaptureService.js";
|
import type { PacketCaptureService } from "../application/captures/PacketCaptureService.js";
|
||||||
|
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||||
|
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
||||||
|
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { createPacketCaptureService } from "../composition/captures.js";
|
import { createPacketCaptureService } from "../composition/captures.js";
|
||||||
import {
|
import {
|
||||||
@@ -10,60 +12,19 @@ import {
|
|||||||
} from "../domain/captures/packetCapture.js";
|
} from "../domain/captures/packetCapture.js";
|
||||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||||
import { logCliCommand } from "../cliLogging.js";
|
import { logCliCommand } from "../cliLogging.js";
|
||||||
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||||
import type { Logger } from "pino";
|
import type { Logger } from "pino";
|
||||||
import type { CliInstance } from "./types.js";
|
import type { CliInstance } from "./types.js";
|
||||||
import { withCommandCancellation } from "./commandCancellation.js";
|
import { withCommandCancellation } from "./commandCancellation.js";
|
||||||
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
||||||
export const registerCaptureCommands = (
|
export const registerCaptureCommands = (
|
||||||
cli: CliInstance,
|
cli: CliInstance,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
environment: Readonly<NodeJS.ProcessEnv>,
|
environment: Readonly<NodeJS.ProcessEnv>,
|
||||||
service: Pick<
|
service: Pick<
|
||||||
PacketCaptureService,
|
PacketCaptureService,
|
||||||
"inspect" | "inspectFields" | "close"
|
"inspect" | "close"
|
||||||
> = createPacketCaptureService(environment),
|
> = createPacketCaptureService(environment),
|
||||||
): void => {
|
): void => {
|
||||||
cli.command(CLI_COMMANDS.inspectPacketFields, {
|
|
||||||
description: "Search installed TShark protocol and field definitions",
|
|
||||||
options: z
|
|
||||||
.object({
|
|
||||||
...inspectPacketFieldsInputSchema.shape,
|
|
||||||
limit: z
|
|
||||||
.number()
|
|
||||||
.int()
|
|
||||||
.positive()
|
|
||||||
.max(Number.MAX_SAFE_INTEGER)
|
|
||||||
.optional()
|
|
||||||
.describe("Maximum matching records to return; defaults to 50"),
|
|
||||||
all: z
|
|
||||||
.boolean()
|
|
||||||
.default(false)
|
|
||||||
.describe("Return all remaining matches within resource limits"),
|
|
||||||
})
|
|
||||||
.superRefine((options, context) => {
|
|
||||||
if (options.all && options.limit !== undefined)
|
|
||||||
context.addIssue({
|
|
||||||
code: "custom",
|
|
||||||
path: ["all"],
|
|
||||||
message: "all and limit are mutually exclusive",
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
run: ({ options: { all, ...options } }) =>
|
|
||||||
withCommandCancellation((signal) =>
|
|
||||||
logCliCommand(logger, CLI_COMMANDS.inspectPacketFields, async () =>
|
|
||||||
finishAnalysisCommand(
|
|
||||||
() =>
|
|
||||||
service.inspectFields(
|
|
||||||
{ ...options, ...(all ? { limit: null } : {}) },
|
|
||||||
{ signal },
|
|
||||||
),
|
|
||||||
service,
|
|
||||||
"tshark-capture",
|
|
||||||
"inspect_packet_fields",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
});
|
|
||||||
cli.command(CLI_COMMANDS.inspectPacketCapture, {
|
cli.command(CLI_COMMANDS.inspectPacketCapture, {
|
||||||
description:
|
description:
|
||||||
"Inspect an existing packet capture with caller-supplied TShark",
|
"Inspect an existing packet capture with caller-supplied TShark",
|
||||||
@@ -99,20 +60,39 @@ export const registerCaptureCommands = (
|
|||||||
run: ({ args, options: { all_matches, ...options } }) =>
|
run: ({ args, options: { all_matches, ...options } }) =>
|
||||||
withCommandCancellation((signal) =>
|
withCommandCancellation((signal) =>
|
||||||
logCliCommand(logger, CLI_COMMANDS.inspectPacketCapture, async () => {
|
logCliCommand(logger, CLI_COMMANDS.inspectPacketCapture, async () => {
|
||||||
return finishAnalysisCommand(
|
const result = await service.inspect(
|
||||||
() =>
|
|
||||||
service.inspect(
|
|
||||||
{
|
{
|
||||||
...options,
|
...options,
|
||||||
...(all_matches ? { match_limit: null } : {}),
|
...(all_matches ? { match_limit: null } : {}),
|
||||||
path: resolve(args.path),
|
path: resolve(args.path),
|
||||||
},
|
},
|
||||||
{ signal },
|
{ signal },
|
||||||
),
|
|
||||||
service,
|
|
||||||
"tshark-capture",
|
|
||||||
"inspect_packet_capture",
|
|
||||||
);
|
);
|
||||||
|
// A one-shot command must retry retained cleanup before discarding its owner.
|
||||||
|
try {
|
||||||
|
await service.close();
|
||||||
|
} catch (cause) {
|
||||||
|
const cleanup =
|
||||||
|
cause instanceof AnalysisError
|
||||||
|
? cause
|
||||||
|
: new ProviderCleanupError(
|
||||||
|
"tshark-capture",
|
||||||
|
[],
|
||||||
|
{ reason: String(cause) },
|
||||||
|
{ cause, operation: "inspect_packet_capture" },
|
||||||
|
);
|
||||||
|
if (result.ok) cleanup.retainPartialObservation(result.value);
|
||||||
|
return projectAnalysisError(
|
||||||
|
result.ok
|
||||||
|
? cleanup
|
||||||
|
: analysisErrorWithCleanupFailure(
|
||||||
|
result.error,
|
||||||
|
cleanup,
|
||||||
|
"inspect_packet_capture",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return result.ok ? result.value : projectAnalysisError(result.error);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
import { ArtifactReaderFailure } from "../artifacts/ArtifactReader.js";
|
|
||||||
import {
|
|
||||||
AnalysisError,
|
|
||||||
type AnalysisPartialObservation,
|
|
||||||
} from "../domain/analysisErrorBase.js";
|
|
||||||
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
|
||||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
||||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
|
||||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
|
||||||
import type { Result } from "../domain/result.js";
|
|
||||||
|
|
||||||
/** Finish a one-shot CLI operation without discarding its primary result on close failure. */
|
|
||||||
export const finishAnalysisCommand = async <
|
|
||||||
Value extends AnalysisPartialObservation,
|
|
||||||
>(
|
|
||||||
run: () => Promise<Result<Value, AnalysisError>>,
|
|
||||||
service: { close(): Promise<void> },
|
|
||||||
providerId: string,
|
|
||||||
canonicalOperation: string,
|
|
||||||
fallbackResource?: string,
|
|
||||||
): Promise<Value | ReturnType<typeof projectAnalysisError>> => {
|
|
||||||
let result: Result<Value, AnalysisError>;
|
|
||||||
try {
|
|
||||||
result = await run();
|
|
||||||
} catch (cause) {
|
|
||||||
result = {
|
|
||||||
ok: false,
|
|
||||||
error:
|
|
||||||
cause instanceof AnalysisError
|
|
||||||
? cause
|
|
||||||
: new ProviderAdapterError(providerId, canonicalOperation, { cause }),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await service.close();
|
|
||||||
} catch (cause) {
|
|
||||||
let cleanup: AnalysisError;
|
|
||||||
if (cause instanceof AnalysisError) cleanup = cause;
|
|
||||||
else {
|
|
||||||
const observation =
|
|
||||||
cause instanceof ArtifactReaderFailure
|
|
||||||
? ArtifactReaderFailure.cleanupObservation(
|
|
||||||
cause,
|
|
||||||
fallbackResource ?? `${canonicalOperation} resources`,
|
|
||||||
)
|
|
||||||
: {
|
|
||||||
reason: cause instanceof Error ? cause.message : String(cause),
|
|
||||||
resources: [],
|
|
||||||
};
|
|
||||||
cleanup = new ProviderCleanupError(
|
|
||||||
providerId,
|
|
||||||
observation.resources,
|
|
||||||
{ reason: observation.reason },
|
|
||||||
{ cause, operation: canonicalOperation },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (result.ok) cleanup.retainPartialObservation(result.value);
|
|
||||||
return projectAnalysisError(
|
|
||||||
result.ok
|
|
||||||
? cleanup
|
|
||||||
: analysisErrorWithCleanupFailure(
|
|
||||||
result.error,
|
|
||||||
cleanup,
|
|
||||||
canonicalOperation,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return result.ok ? result.value : projectAnalysisError(result.error);
|
|
||||||
};
|
|
||||||
+9
-13
@@ -3,13 +3,14 @@ import { resolve } from "node:path";
|
|||||||
import { createGoBinaryService } from "../composition/go.js";
|
import { createGoBinaryService } from "../composition/go.js";
|
||||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||||
import { logCliCommand } from "../cliLogging.js";
|
import { logCliCommand } from "../cliLogging.js";
|
||||||
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||||
import type { Logger } from "pino";
|
import type { Logger } from "pino";
|
||||||
import type { CliInstance } from "./types.js";
|
import type { CliInstance } from "./types.js";
|
||||||
import { withCommandCancellation } from "./commandCancellation.js";
|
import { withCommandCancellation } from "./commandCancellation.js";
|
||||||
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
||||||
|
|
||||||
/** Resolve caller paths and inspect static build metadata through the shared workflow. */
|
/** Resolve caller paths and inspect static build metadata through the shared workflow. */
|
||||||
export const registerGoCommands = (cli: CliInstance, logger: Logger): void => {
|
export const registerGoCommands = (cli: CliInstance, logger: Logger): void => {
|
||||||
|
const service = createGoBinaryService();
|
||||||
cli.command(CLI_COMMANDS.inspectGoBinary, {
|
cli.command(CLI_COMMANDS.inspectGoBinary, {
|
||||||
description:
|
description:
|
||||||
"Inspect embedded Go compiler, modules and build settings without target execution",
|
"Inspect embedded Go compiler, modules and build settings without target execution",
|
||||||
@@ -17,19 +18,14 @@ export const registerGoCommands = (cli: CliInstance, logger: Logger): void => {
|
|||||||
path: z.string().describe("Local ELF, PE or thin Mach-O image"),
|
path: z.string().describe("Local ELF, PE or thin Mach-O image"),
|
||||||
}),
|
}),
|
||||||
run: ({ args }) =>
|
run: ({ args }) =>
|
||||||
withCommandCancellation(async (signal) => {
|
withCommandCancellation((signal) =>
|
||||||
const service = createGoBinaryService();
|
logCliCommand(logger, CLI_COMMANDS.inspectGoBinary, async () => {
|
||||||
return await logCliCommand(
|
const result = await service.inspect(
|
||||||
logger,
|
{ path: resolve(args.path) },
|
||||||
CLI_COMMANDS.inspectGoBinary,
|
{ signal },
|
||||||
async () =>
|
|
||||||
finishAnalysisCommand(
|
|
||||||
() => service.inspect({ path: resolve(args.path) }, { signal }),
|
|
||||||
service,
|
|
||||||
"go-build-info",
|
|
||||||
"inspect_go_binary",
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
return result.ok ? result.value : projectAnalysisError(result.error);
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
+31
-53
@@ -1,6 +1,8 @@
|
|||||||
import { inspectSignalDecodersInputSchema } from "../domain/signals/signalDecoders.js";
|
|
||||||
import { z } from "incur";
|
import { z } from "incur";
|
||||||
import type { SignalRecordingService } from "../application/signals/SignalRecordingService.js";
|
import type { SignalRecordingService } from "../application/signals/SignalRecordingService.js";
|
||||||
|
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||||
|
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
||||||
|
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { createSignalRecordingService } from "../composition/signals.js";
|
import { createSignalRecordingService } from "../composition/signals.js";
|
||||||
import {
|
import {
|
||||||
@@ -10,62 +12,19 @@ import {
|
|||||||
} from "../domain/signals/signalRecording.js";
|
} from "../domain/signals/signalRecording.js";
|
||||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||||
import { logCliCommand } from "../cliLogging.js";
|
import { logCliCommand } from "../cliLogging.js";
|
||||||
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||||
import type { Logger } from "pino";
|
import type { Logger } from "pino";
|
||||||
import type { CliInstance } from "./types.js";
|
import type { CliInstance } from "./types.js";
|
||||||
import { withCommandCancellation } from "./commandCancellation.js";
|
import { withCommandCancellation } from "./commandCancellation.js";
|
||||||
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
||||||
export const registerSignalCommands = (
|
export const registerSignalCommands = (
|
||||||
cli: CliInstance,
|
cli: CliInstance,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
environment: Readonly<NodeJS.ProcessEnv>,
|
environment: Readonly<NodeJS.ProcessEnv>,
|
||||||
service: Pick<
|
service: Pick<
|
||||||
SignalRecordingService,
|
SignalRecordingService,
|
||||||
"decode" | "inspectDecoders" | "close"
|
"decode" | "close"
|
||||||
> = createSignalRecordingService(environment),
|
> = createSignalRecordingService(environment),
|
||||||
): void => {
|
): void => {
|
||||||
cli.command(CLI_COMMANDS.inspectSignalDecoders, {
|
|
||||||
description: "Search installed sigrok decoders or selected decoder help",
|
|
||||||
options: z
|
|
||||||
.object({
|
|
||||||
...inspectSignalDecodersInputSchema.shape,
|
|
||||||
limit: z
|
|
||||||
.number()
|
|
||||||
.int()
|
|
||||||
.positive()
|
|
||||||
.max(Number.MAX_SAFE_INTEGER)
|
|
||||||
.optional()
|
|
||||||
.describe(
|
|
||||||
"Maximum matching decoders or help lines to return; defaults to 50",
|
|
||||||
),
|
|
||||||
all: z
|
|
||||||
.boolean()
|
|
||||||
.default(false)
|
|
||||||
.describe("Return all remaining matches"),
|
|
||||||
})
|
|
||||||
.superRefine((options, context) => {
|
|
||||||
if (options.all && options.limit !== undefined)
|
|
||||||
context.addIssue({
|
|
||||||
code: "custom",
|
|
||||||
path: ["all"],
|
|
||||||
message: "all and limit are mutually exclusive",
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
run: ({ options: { all, ...options } }) =>
|
|
||||||
withCommandCancellation((signal) =>
|
|
||||||
logCliCommand(logger, CLI_COMMANDS.inspectSignalDecoders, async () =>
|
|
||||||
finishAnalysisCommand(
|
|
||||||
() =>
|
|
||||||
service.inspectDecoders(
|
|
||||||
{ ...options, ...(all ? { limit: null } : {}) },
|
|
||||||
{ signal },
|
|
||||||
),
|
|
||||||
service,
|
|
||||||
"sigrok-recording",
|
|
||||||
"inspect_signal_decoders",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
});
|
|
||||||
cli.command(CLI_COMMANDS.decodeSignalRecording, {
|
cli.command(CLI_COMMANDS.decodeSignalRecording, {
|
||||||
description:
|
description:
|
||||||
"Decode an existing signal recording with caller-supplied sigrok",
|
"Decode an existing signal recording with caller-supplied sigrok",
|
||||||
@@ -101,20 +60,39 @@ export const registerSignalCommands = (
|
|||||||
run: ({ args, options: { all_lines, ...options } }) =>
|
run: ({ args, options: { all_lines, ...options } }) =>
|
||||||
withCommandCancellation((signal) =>
|
withCommandCancellation((signal) =>
|
||||||
logCliCommand(logger, CLI_COMMANDS.decodeSignalRecording, async () => {
|
logCliCommand(logger, CLI_COMMANDS.decodeSignalRecording, async () => {
|
||||||
return finishAnalysisCommand(
|
const result = await service.decode(
|
||||||
() =>
|
|
||||||
service.decode(
|
|
||||||
{
|
{
|
||||||
...options,
|
...options,
|
||||||
...(all_lines ? { line_limit: null } : {}),
|
...(all_lines ? { line_limit: null } : {}),
|
||||||
path: resolve(args.path),
|
path: resolve(args.path),
|
||||||
},
|
},
|
||||||
{ signal },
|
{ signal },
|
||||||
),
|
|
||||||
service,
|
|
||||||
"sigrok-recording",
|
|
||||||
"decode_signal_recording",
|
|
||||||
);
|
);
|
||||||
|
// A one-shot command must retry retained cleanup before discarding its owner.
|
||||||
|
try {
|
||||||
|
await service.close();
|
||||||
|
} catch (cause) {
|
||||||
|
const cleanup =
|
||||||
|
cause instanceof AnalysisError
|
||||||
|
? cause
|
||||||
|
: new ProviderCleanupError(
|
||||||
|
"sigrok-recording",
|
||||||
|
[],
|
||||||
|
{ reason: String(cause) },
|
||||||
|
{ cause, operation: "decode_signal_recording" },
|
||||||
|
);
|
||||||
|
if (result.ok) cleanup.retainPartialObservation(result.value);
|
||||||
|
return projectAnalysisError(
|
||||||
|
result.ok
|
||||||
|
? cleanup
|
||||||
|
: analysisErrorWithCleanupFailure(
|
||||||
|
result.error,
|
||||||
|
cleanup,
|
||||||
|
"decode_signal_recording",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return result.ok ? result.value : projectAnalysisError(result.error);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { WEB_NETWORK_CAPTURE_FORMATS } from "../domain/webNetworkCapture.js";
|
|||||||
import { createWebNetworkCaptureService } from "../composition/webNetworkCaptures.js";
|
import { createWebNetworkCaptureService } from "../composition/webNetworkCaptures.js";
|
||||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||||
import { logCliCommand } from "../cliLogging.js";
|
import { logCliCommand } from "../cliLogging.js";
|
||||||
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||||
import type { Logger } from "pino";
|
import type { Logger } from "pino";
|
||||||
import type { CliInstance } from "./types.js";
|
import type { CliInstance } from "./types.js";
|
||||||
import { withCommandCancellation } from "./commandCancellation.js";
|
import { withCommandCancellation } from "./commandCancellation.js";
|
||||||
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
||||||
|
|
||||||
/** Expose offline historical capture inspection with the same selection contract as MCP. */
|
/** Expose offline historical capture inspection with the same selection contract as MCP. */
|
||||||
export const registerWebNetworkCaptureCommands = (
|
export const registerWebNetworkCaptureCommands = (
|
||||||
@@ -42,9 +42,7 @@ export const registerWebNetworkCaptureCommands = (
|
|||||||
logger,
|
logger,
|
||||||
CLI_COMMANDS.inspectWebNetworkCapture,
|
CLI_COMMANDS.inspectWebNetworkCapture,
|
||||||
async () => {
|
async () => {
|
||||||
return finishAnalysisCommand(
|
const result = await service.inspect(
|
||||||
() =>
|
|
||||||
service.inspect(
|
|
||||||
{
|
{
|
||||||
capture_path: args.capturePath,
|
capture_path: args.capturePath,
|
||||||
format: args.format,
|
format: args.format,
|
||||||
@@ -54,12 +52,10 @@ export const registerWebNetworkCaptureCommands = (
|
|||||||
: { record_ordinals: options.record }),
|
: { record_ordinals: options.record }),
|
||||||
},
|
},
|
||||||
{ signal },
|
{ signal },
|
||||||
),
|
|
||||||
service,
|
|
||||||
"web-network-capture",
|
|
||||||
"inspect_web_network_capture",
|
|
||||||
"Web network capture resources",
|
|
||||||
);
|
);
|
||||||
|
return result.ok
|
||||||
|
? result.value
|
||||||
|
: projectAnalysisError(result.error);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/** Canonical names used by every one-shot CLI command registration. */
|
/** Canonical names used by every one-shot CLI command registration. */
|
||||||
export const CLI_COMMANDS = Object.freeze({
|
export const CLI_COMMANDS = Object.freeze({
|
||||||
inspectPacketFields: "inspect-packet-fields",
|
|
||||||
inspectPacketCapture: "inspect-packet-capture",
|
inspectPacketCapture: "inspect-packet-capture",
|
||||||
inspectSignalDecoders: "inspect-signal-decoders",
|
|
||||||
decodeSignalRecording: "decode-signal-recording",
|
decodeSignalRecording: "decode-signal-recording",
|
||||||
inspectWasmArtifact: "inspect-wasm-artifact",
|
inspectWasmArtifact: "inspect-wasm-artifact",
|
||||||
inspectSqliteDatabase: "inspect-sqlite-database",
|
inspectSqliteDatabase: "inspect-sqlite-database",
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user