Compare commits
12 Commits
e5173c78fe
...
v1.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 9202ccddb9 | |||
| f40d4add91 | |||
| 16bb12face | |||
| f18e2428dc | |||
| 3b64e784a1 | |||
| 3744d229a2 | |||
| 9bbe1fb7f1 | |||
| b7a66f6cc4 | |||
| c8efdb53d3 | |||
| ab4b252b08 | |||
| e9028e08a4 | |||
| 332884f887 |
14
README.md
14
README.md
@@ -27,19 +27,19 @@ go run ./cmd/seriatim merge \
|
|||||||
- Configuration reference: [docs/config.md](docs/config.md)
|
- Configuration reference: [docs/config.md](docs/config.md)
|
||||||
- Operations guide: [docs/operations.md](docs/operations.md)
|
- Operations guide: [docs/operations.md](docs/operations.md)
|
||||||
- Troubleshooting: [docs/troubleshooting.md](docs/troubleshooting.md)
|
- Troubleshooting: [docs/troubleshooting.md](docs/troubleshooting.md)
|
||||||
- Integrations:
|
- Integration references:
|
||||||
- [docs/integrations/whisperx-json.md](docs/integrations/whisperx-json.md)
|
- [docs/integrations/whisperx-json.md](docs/integrations/whisperx-json.md)
|
||||||
- [docs/integrations/output-schemas.md](docs/integrations/output-schemas.md)
|
- [docs/integrations/output-schemas.md](docs/integrations/output-schemas.md)
|
||||||
- Development architecture policy: [docs/policy/architecture.md](docs/policy/architecture.md)
|
- Development policies:
|
||||||
- Contributor workflow: [docs/policy/development.md](docs/policy/development.md)
|
- [docs/policy/architecture.md](docs/policy/architecture.md)
|
||||||
- Documentation policy: [docs/policy/documentation.md](docs/policy/documentation.md)
|
- [docs/policy/development.md](docs/policy/development.md)
|
||||||
- Internal implementation docs:
|
- [docs/policy/documentation.md](docs/policy/documentation.md)
|
||||||
|
- Internal implementation references:
|
||||||
- [docs/internal/pipeline.md](docs/internal/pipeline.md)
|
- [docs/internal/pipeline.md](docs/internal/pipeline.md)
|
||||||
- [docs/internal/artifacts.md](docs/internal/artifacts.md)
|
- [docs/internal/artifacts.md](docs/internal/artifacts.md)
|
||||||
- [docs/internal/modules.md](docs/internal/modules.md)
|
- [docs/internal/modules.md](docs/internal/modules.md)
|
||||||
- Public JSON schemas:
|
- Public JSON schema files:
|
||||||
- [schema/minimal-output.schema.json](schema/minimal-output.schema.json)
|
- [schema/minimal-output.schema.json](schema/minimal-output.schema.json)
|
||||||
- [schema/intermediate-output.schema.json](schema/intermediate-output.schema.json)
|
- [schema/intermediate-output.schema.json](schema/intermediate-output.schema.json)
|
||||||
- [schema/full-output.schema.json](schema/full-output.schema.json)
|
- [schema/full-output.schema.json](schema/full-output.schema.json)
|
||||||
- Synthetic examples: [examples/README.md](examples/README.md)
|
- Synthetic examples: [examples/README.md](examples/README.md)
|
||||||
- Documentation roadmap: [docs/roadmap/documentation.md](docs/roadmap/documentation.md)
|
|
||||||
|
|||||||
@@ -179,4 +179,3 @@ go run ./cmd/seriatim normalize \
|
|||||||
- [../schema/minimal-output.schema.json](../schema/minimal-output.schema.json)
|
- [../schema/minimal-output.schema.json](../schema/minimal-output.schema.json)
|
||||||
- [../schema/intermediate-output.schema.json](../schema/intermediate-output.schema.json)
|
- [../schema/intermediate-output.schema.json](../schema/intermediate-output.schema.json)
|
||||||
- [../schema/full-output.schema.json](../schema/full-output.schema.json)
|
- [../schema/full-output.schema.json](../schema/full-output.schema.json)
|
||||||
- Documentation roadmap: [roadmap/documentation.md](roadmap/documentation.md)
|
|
||||||
|
|||||||
@@ -165,4 +165,3 @@ All commands:
|
|||||||
- [../schema/minimal-output.schema.json](../schema/minimal-output.schema.json)
|
- [../schema/minimal-output.schema.json](../schema/minimal-output.schema.json)
|
||||||
- [../schema/intermediate-output.schema.json](../schema/intermediate-output.schema.json)
|
- [../schema/intermediate-output.schema.json](../schema/intermediate-output.schema.json)
|
||||||
- [../schema/full-output.schema.json](../schema/full-output.schema.json)
|
- [../schema/full-output.schema.json](../schema/full-output.schema.json)
|
||||||
- Documentation roadmap: [roadmap/documentation.md](roadmap/documentation.md)
|
|
||||||
|
|||||||
@@ -51,29 +51,43 @@ Unknown/empty selection falls back to intermediate conversion.
|
|||||||
|
|
||||||
## Trim internals
|
## Trim internals
|
||||||
|
|
||||||
`internal/trim` is artifact-level projection, not merge reprocessing.
|
`internal/trim` handles artifact-level projection and does not execute merge
|
||||||
|
pipeline modules.
|
||||||
|
|
||||||
Core flow:
|
Run layer (`run.go`):
|
||||||
|
|
||||||
1. Parse selector (`internal/trim/selector.go`).
|
1. Parse selector from validated config.
|
||||||
2. Parse input artifact and detect schema (`ParseArtifactJSON`).
|
2. Read and parse input artifact JSON.
|
||||||
3. Apply keep/remove projection with sequential ID renumbering.
|
3. Apply trim projection through schema-aware artifact handling.
|
||||||
4. Recompute overlap groups only for full-schema artifacts.
|
4. Resolve output schema (preserve input schema unless overridden).
|
||||||
5. Optionally convert output schema when supported.
|
5. Validate output artifact.
|
||||||
6. Validate output artifact before write.
|
6. Write output JSON.
|
||||||
|
7. Optionally write report JSON with `trim-audit`.
|
||||||
|
|
||||||
Schema-conversion limits:
|
Apply layer (`apply.go`):
|
||||||
|
|
||||||
- full -> intermediate/minimal supported.
|
- one shared projection policy for selector mode, input ID validation, selected
|
||||||
- intermediate -> minimal supported.
|
ID existence checks, keep/remove filtering, removed IDs, and old-to-new ID
|
||||||
- minimal -> intermediate supported.
|
mappings
|
||||||
- intermediate/minimal -> full is rejected.
|
- schema-specific segment reconstruction for full/intermediate/minimal outputs
|
||||||
|
- overlap-group recomputation only for full-schema outputs
|
||||||
|
|
||||||
|
Artifact layer (`artifact.go`):
|
||||||
|
|
||||||
|
- schema detection for full/intermediate/minimal artifacts
|
||||||
|
- schema-preserving trim application
|
||||||
|
- supported schema conversions:
|
||||||
|
- full -> intermediate/minimal
|
||||||
|
- intermediate -> minimal
|
||||||
|
- minimal -> intermediate
|
||||||
|
- rejected conversion:
|
||||||
|
- intermediate/minimal -> full
|
||||||
|
|
||||||
Trim invariants:
|
Trim invariants:
|
||||||
|
|
||||||
- selected IDs must exist in input.
|
- selected IDs must exist in input.
|
||||||
- input IDs must be positive, unique, sequential.
|
- input IDs must be positive, unique, sequential.
|
||||||
- retained order follows input transcript order.
|
- retained segment order follows input transcript order.
|
||||||
- output IDs are reassigned to `1..N`.
|
- output IDs are reassigned to `1..N`.
|
||||||
|
|
||||||
## Normalize internals
|
## Normalize internals
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ Output writer:
|
|||||||
- `autocorrect`: applies YAML replacement rules when configured.
|
- `autocorrect`: applies YAML replacement rules when configured.
|
||||||
- `assign-ids`: assigns final sequential IDs.
|
- `assign-ids`: assigns final sequential IDs.
|
||||||
- `validate-output`: validates selected public artifact shape.
|
- `validate-output`: validates selected public artifact shape.
|
||||||
- `json`: writes artifact JSON to `cfg.OutputFile`.
|
- `json`: writes artifact JSON to `cfg.OutputFile` through shared deterministic
|
||||||
|
JSON file writing.
|
||||||
|
|
||||||
Filesystem side effects are limited to:
|
Filesystem side effects are limited to:
|
||||||
|
|
||||||
|
|||||||
@@ -1,591 +0,0 @@
|
|||||||
# Pre-1.0 Code Quality And Deduplication Audit
|
|
||||||
|
|
||||||
## Executive Summary
|
|
||||||
|
|
||||||
seriatim's current codebase is in good shape for a limited pre-1.0 cleanup pass. The main command paths are explicit, tests cover the public CLI and important transformation behavior, and the implemented architecture mostly matches the policy in `docs/policy/architecture.md`: merge uses a registry-driven pipeline, while trim and normalize operate at the artifact level.
|
|
||||||
|
|
||||||
The top three refactoring targets before 1.0 are:
|
|
||||||
|
|
||||||
1. Centralize public output schema names, schema validation selection, and artifact schema switching.
|
|
||||||
2. Reduce duplicated trim projection logic across full, intermediate, and minimal artifacts.
|
|
||||||
3. Move trim command orchestration out of `internal/cli` so CLI code remains a thin adapter like merge and normalize.
|
|
||||||
|
|
||||||
No major architectural risk appears to block 1.0. The best next step is a series of small, behavior-preserving refactors protected by the existing CLI, trim, normalize, artifact, schema, and pipeline tests.
|
|
||||||
|
|
||||||
## Repository Map Reviewed
|
|
||||||
|
|
||||||
Reviewed documentation and policy:
|
|
||||||
|
|
||||||
- `README.md`
|
|
||||||
- `docs/cli.md`
|
|
||||||
- `docs/config.md`
|
|
||||||
- `docs/operations.md`
|
|
||||||
- `docs/troubleshooting.md`
|
|
||||||
- `docs/policy/architecture.md`
|
|
||||||
- `docs/policy/development.md`
|
|
||||||
- `docs/internal/pipeline.md`
|
|
||||||
- `docs/internal/artifacts.md`
|
|
||||||
- `docs/internal/modules.md`
|
|
||||||
- `docs/integrations/output-schemas.md`
|
|
||||||
- `docs/integrations/whisperx-json.md`
|
|
||||||
- `docs/roadmap/documentation.md`
|
|
||||||
|
|
||||||
Reviewed implementation areas:
|
|
||||||
|
|
||||||
- `cmd/seriatim`: root process error handling.
|
|
||||||
- `internal/cli`: Cobra command setup and command-level tests for `merge`, `trim`, and `normalize`.
|
|
||||||
- `internal/config`: validated config construction, defaults, environment variables, path validation, and config tests.
|
|
||||||
- `internal/pipeline`: registry resolution, stage ordering, preprocessing state validation, and pipeline execution.
|
|
||||||
- `internal/builtin`: built-in input, preprocess, merge, postprocess, and output modules.
|
|
||||||
- `internal/artifact`: conversion from merged model to public output artifacts.
|
|
||||||
- `internal/trim`: selector parsing, artifact parsing/conversion, trimming, and trim tests.
|
|
||||||
- `internal/normalize`: artifact-level parsing, repair, building, reporting, and normalize tests.
|
|
||||||
- `internal/report`: report model and JSON writer.
|
|
||||||
- `internal/overlap`, `internal/coalesce`, `internal/danglers`, `internal/backchannel`, `internal/filler`, `internal/autocorrect`, `internal/speaker`: implemented modules and module-specific tests.
|
|
||||||
- `schema`: public Go schema types, embedded JSON Schemas, semantic validation, and schema tests.
|
|
||||||
- `examples` and `samples`: checked layout and role, not every sample payload line-by-line.
|
|
||||||
|
|
||||||
The reviewed execution paths were:
|
|
||||||
|
|
||||||
- `seriatim merge`: Cobra options, `config.NewMergeConfig`, `pipeline.Run`, built-in registry, output writer, optional report.
|
|
||||||
- `seriatim trim`: Cobra options, `config.NewTrimConfig`, artifact parsing, trim application, schema conversion, output writing, optional report.
|
|
||||||
- `seriatim normalize`: Cobra options, `config.NewNormalizeConfig`, `normalize.Run`, artifact parsing/building, output writing, optional report.
|
|
||||||
|
|
||||||
No `internal/app`, `internal/stage`, `internal/modules`, `internal/validators`, `internal/adapters`, `internal/storage`, `internal/manifest`, `pkg`, or top-level `tests` directories exist in the current layout. Equivalent responsibilities are implemented in the packages listed above.
|
|
||||||
|
|
||||||
## High-Confidence Deduplication Opportunities
|
|
||||||
|
|
||||||
### Centralize Output Schema Names And Schema Selection
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/config`
|
|
||||||
- `internal/trim`
|
|
||||||
- `internal/artifact`
|
|
||||||
- `internal/normalize`
|
|
||||||
- `schema`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- `internal/config` defines `seriatim-minimal`, `seriatim-intermediate`, and `seriatim-full` as output schema constants and validates CLI/config values.
|
|
||||||
- `internal/trim/artifact.go` defines another set of constants with the same string values.
|
|
||||||
- `internal/artifact`, `internal/normalize`, and `internal/trim` each switch over the same schema names to select conversion or validation behavior.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- Output schema names are part of the public interface. If a schema name, default, or validation error changes in one package but not another, `merge`, `trim`, and `normalize` can drift.
|
|
||||||
- The current duplication is small but central enough that future schema changes would require edits in several packages.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Keep one canonical set of public schema names, preferably outside command-specific config construction.
|
|
||||||
- Expose narrow helpers for schema validation and display text where needed.
|
|
||||||
- Preserve the current semantic difference that `merge` and `normalize` resolve `SERIATIM_OUTPUT_SCHEMA` and default to intermediate, while `trim` preserves the input artifact schema unless `--output-schema` is supplied.
|
|
||||||
- Do not build a broad schema registry unless a new implemented schema makes the switch statements materially harder to maintain.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- `internal/config` tests for schema defaults, env precedence, invalid values, and trim override behavior.
|
|
||||||
- `internal/cli` tests for merge, trim, and normalize schema flags.
|
|
||||||
- `internal/artifact`, `internal/trim`, `internal/normalize`, and `schema` tests for selected shape validation.
|
|
||||||
|
|
||||||
Risk level: Low to medium. Public behavior must stay byte-compatible where tests assert shapes and diagnostics.
|
|
||||||
|
|
||||||
### Reduce Duplicated Trim Projection Logic Across Artifact Shapes
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/trim/apply.go`
|
|
||||||
- `internal/trim/apply_test.go`
|
|
||||||
- `internal/cli/trim_test.go`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- `Apply`, `ApplyIntermediate`, and `ApplyMinimal` each validate mode, reject empty selectors, collect input IDs, validate sequential IDs, verify selected IDs exist, apply keep/remove policy, renumber retained segments from 1, build old-to-new mappings, collect removed IDs, and enforce `AllowEmpty`.
|
|
||||||
- Only the segment shape and full-schema overlap group recomputation differ.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- Trim is user-facing artifact surgery. Drift in ID validation, empty-output handling, or keep/remove behavior across schemas would produce confusing public differences.
|
|
||||||
- The duplicated loops make future fixes to selector behavior or ID policy likely to require changes in three places.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Extract a small projection helper that operates on ordered segment IDs and returns retained indexes, old-to-new ID mapping, removed IDs, and empty-output validation.
|
|
||||||
- Keep schema-specific reconstruction local to each artifact shape.
|
|
||||||
- Keep full-schema overlap recomputation separate; it is a real semantic difference and should remain obvious.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- Existing `internal/trim/apply_test.go` coverage for keep/remove, renumbering, sequential ID validation, empty output, schema preservation, and overlap recomputation.
|
|
||||||
- Existing `internal/cli/trim_test.go` coverage for end-to-end artifact behavior and report audit fields.
|
|
||||||
- Add one table test that asserts the same selector policy across all three schemas.
|
|
||||||
|
|
||||||
Risk level: Medium. The refactor touches public trim behavior, but the duplicated policy is well covered.
|
|
||||||
|
|
||||||
### Move Trim Orchestration Out Of The CLI Adapter
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/cli/trim.go`
|
|
||||||
- `internal/trim`
|
|
||||||
- `internal/config`
|
|
||||||
- `internal/report`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- `merge` parses flags, builds config, and delegates to `pipeline.Run`.
|
|
||||||
- `normalize` parses flags, builds config, and delegates to `normalize.Run`.
|
|
||||||
- `trim` parses flags and config, but also reads files, parses artifacts, applies domain logic, converts schemas, validates output, writes output JSON, builds audit payloads, and writes reports directly in `internal/cli`.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- This is the clearest boundary drift from the architecture policy. CLI should stay an adapter for flag parsing and command dispatch.
|
|
||||||
- Keeping trim orchestration in CLI makes it harder to test trim as an application service without Cobra and makes report/output behavior easier to diverge from normalize.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Add a `trim.Run(ctx, cfg)` or similarly narrow artifact-level service in `internal/trim`.
|
|
||||||
- Move artifact reading, selector parsing, apply/convert/validate/write/report orchestration into that service.
|
|
||||||
- Leave Cobra flag definitions and `config.NewTrimConfig` calls in `internal/cli`.
|
|
||||||
- Keep trim audit fields stable unless tests and docs are intentionally updated.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- Keep existing `internal/cli/trim_test.go` end-to-end tests.
|
|
||||||
- Add direct `internal/trim` service tests for report generation and output schema conversion once the orchestration moves.
|
|
||||||
|
|
||||||
Risk level: Medium. It is mostly a move, but report event wording and error wrapping must remain stable.
|
|
||||||
|
|
||||||
### Centralize Pretty JSON File Writing
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/builtin/output.go`
|
|
||||||
- `internal/cli/trim.go`
|
|
||||||
- `internal/normalize/normalize.go`
|
|
||||||
- `internal/report/report.go`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- Several packages create a file with `os.Create`, use `json.NewEncoder`, set a two-space indent, encode a value, and defer close.
|
|
||||||
- Error wrapping differs by call site: normalize wraps encode errors, trim and merge output mostly return raw errors, and report writing returns raw encode errors.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- JSON artifacts and reports are core outputs. Formatting and write error semantics should not drift accidentally.
|
|
||||||
- Centralizing this low-level operation would simplify future changes such as consistent close error handling or atomic write policy, if such behavior is ever implemented.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Introduce a small internal helper for deterministic JSON file writing.
|
|
||||||
- Keep report construction in `internal/report`; only share the file-writing mechanics.
|
|
||||||
- Do not introduce atomic writes or temporary files as part of this cleanup unless that behavior is intentionally designed and documented.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- Existing CLI tests that read output JSON for all commands.
|
|
||||||
- Existing report tests through merge, trim, and normalize CLI paths.
|
|
||||||
- A small helper-level test can verify indentation and trailing newline if those become explicit guarantees.
|
|
||||||
|
|
||||||
Risk level: Low.
|
|
||||||
|
|
||||||
## Medium-Confidence Opportunities
|
|
||||||
|
|
||||||
### Simplify Artifact Schema Switching In `internal/trim`
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/trim/artifact.go`
|
|
||||||
- `internal/trim/artifact_test.go`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- `Artifact.Value`, `SegmentCount`, `Application`, `Version`, `ValidateArtifact`, `ApplyArtifact`, and `ConvertArtifact` all switch on the same schema discriminator and nil-check the same payload pointers.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- The wrapper works, but the repeated switch boilerplate makes it easier to miss one accessor when adding a field or changing error behavior.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- After centralizing schema names, consider small methods or private helpers that reduce repeated nil-check/access patterns.
|
|
||||||
- Avoid a generic visitor framework unless it directly removes the existing boilerplate without hiding schema-specific conversion rules.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- `internal/trim/artifact_test.go`
|
|
||||||
- `internal/cli/trim_test.go` schema conversion cases.
|
|
||||||
|
|
||||||
Risk level: Low to medium.
|
|
||||||
|
|
||||||
### Share Common Config Path Validation Helpers For Single-Input Commands
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/config/config.go`
|
|
||||||
- `internal/config/config_test.go`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- `NewTrimConfig` and `NewNormalizeConfig` both trim, clean, require, and stat a single `--input-file`.
|
|
||||||
- They also share `--output-file` and optional `--report-file` normalization behavior.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- Config validation is a public command contract. Even small drift in missing file errors, directory errors, or output path parent checks would be user-visible.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Add private helpers for required single input files and optional output/report paths.
|
|
||||||
- Keep merge's multi-input normalization separate because it deduplicates and sorts repeated `--input-file` values.
|
|
||||||
- Preserve the intentional output schema difference between trim and normalize.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- Existing `internal/config` tests for trim and normalize input/output/report errors.
|
|
||||||
- Existing CLI tests for report path failures.
|
|
||||||
|
|
||||||
Risk level: Low.
|
|
||||||
|
|
||||||
### Add Narrow CLI Flag Helper Functions
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/cli/merge.go`
|
|
||||||
- `internal/cli/trim.go`
|
|
||||||
- `internal/cli/normalize.go`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- `--input-file`, `--output-file`, `--report-file`, `--output-schema`, and `--output-modules` are defined in multiple commands with related help text and defaults.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- Flag names and help text are part of the user interface. Minor drift between commands can make docs and tests harder to keep accurate.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Add small flag registration helpers only for shared flags whose semantics are genuinely the same.
|
|
||||||
- Do not introduce a command factory; current command files are short and readable.
|
|
||||||
- Keep trim's `--output-schema` help/default distinct because omitted trim schema preserves the input artifact schema.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- Existing command recognition and behavior tests.
|
|
||||||
- Add help-output assertions only if the helper refactor changes how help text is generated.
|
|
||||||
|
|
||||||
Risk level: Low.
|
|
||||||
|
|
||||||
### Centralize Segment Provenance Reference Formatting Where Semantics Match
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/overlap`
|
|
||||||
- `internal/coalesce`
|
|
||||||
- `internal/danglers`
|
|
||||||
- `internal/model`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- Several modules construct or interpret provenance references such as `source#index`, `word-run:group:speaker:run`, `coalesce:n`, and `resolve-danglers:n`.
|
|
||||||
- `internal/overlap` and `internal/coalesce` both prefer `Source` plus `SourceSegmentIndex` and fall back to `SourceRef`.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- Provenance references appear in public full output and reports/tests rely on deterministic values. A formatting mismatch could affect downstream consumers.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Introduce a very small helper for the common `source#index` or "best available segment reference" behavior.
|
|
||||||
- Leave module-specific generated prefixes local unless another module needs to parse or construct them with the same semantics.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- `internal/overlap` resolve/detect tests.
|
|
||||||
- `internal/coalesce` tests.
|
|
||||||
- Merge CLI tests that assert `source_ref`, `derived_from`, and overlap group segment references.
|
|
||||||
|
|
||||||
Risk level: Medium. Public full-output provenance must remain stable.
|
|
||||||
|
|
||||||
### Share Category Tagging Mechanics Between Backchannel And Filler Carefully
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `internal/backchannel`
|
|
||||||
- `internal/filler`
|
|
||||||
- `internal/builtin`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- Backchannel and filler modules both normalize text by removing punctuation, collapse fields, reject empty text, enforce a maximum word count of three, enforce a max duration, match regex patterns, avoid duplicate categories, and append a category.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- The policies are similar enough that a bug fix to normalization or duplicate category handling may need to be applied twice.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Consider a tiny private shared helper for tag application mechanics if another tagger is added or if a bug is found in the common logic.
|
|
||||||
- Keep the category names, regex lists, and duration defaults in their current packages.
|
|
||||||
- Do not create a broad classifier framework before 1.0.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- `internal/backchannel/backchannel_test.go`
|
|
||||||
- `internal/filler/filler_test.go`
|
|
||||||
- Merge CLI tests that assert category tagging and report events.
|
|
||||||
|
|
||||||
Risk level: Low to medium.
|
|
||||||
|
|
||||||
### Reduce Repetition In Schema Semantic Validation
|
|
||||||
|
|
||||||
Affected files/packages:
|
|
||||||
|
|
||||||
- `schema/output.go`
|
|
||||||
- `schema/output_test.go`
|
|
||||||
|
|
||||||
Duplicated or near-duplicated behavior:
|
|
||||||
|
|
||||||
- Full, intermediate, and minimal semantic validators each enforce sequential segment IDs and non-decreasing timing.
|
|
||||||
- Full validation also checks overlap group timing, which is intentionally schema-specific.
|
|
||||||
|
|
||||||
Why it matters:
|
|
||||||
|
|
||||||
- Sequential IDs and timing are cross-schema public invariants. Drift in error wording or strictness would be confusing.
|
|
||||||
|
|
||||||
Recommended refactor:
|
|
||||||
|
|
||||||
- Consider a small helper that validates ordered ID/timing pairs for all segment shapes.
|
|
||||||
- Keep full overlap group validation separate.
|
|
||||||
|
|
||||||
Suggested tests:
|
|
||||||
|
|
||||||
- Existing schema validation tests for missing/non-sequential IDs and invalid timing.
|
|
||||||
- Add cross-schema semantic validation cases if helper extraction touches all three shapes.
|
|
||||||
|
|
||||||
Risk level: Low.
|
|
||||||
|
|
||||||
## Boundary And Responsibility Concerns
|
|
||||||
|
|
||||||
The main boundary concern is `internal/cli/trim.go`. It currently holds command parsing, artifact I/O, selector parsing, domain execution, schema conversion, output validation, output writing, report assembly, and audit sorting. That orchestration belongs in `internal/trim` under the current architecture because trim is an artifact-level application command, not CLI-specific behavior.
|
|
||||||
|
|
||||||
`internal/normalize` already provides a better pattern: the CLI builds `config.NormalizeConfig` and delegates to `normalize.Run`. `merge` follows the same boundary direction by delegating to `pipeline.Run`.
|
|
||||||
|
|
||||||
Other boundary observations:
|
|
||||||
|
|
||||||
- YAML loading for speaker maps and autocorrect rules lives in narrow packages and is called from built-in modules. This is acceptable for current behavior, although future refactors could split file loading from pure transformation if tests start needing adapter-free module execution.
|
|
||||||
- `schema` owns public schema structs, embedded JSON Schema validation, and semantic validation. That is an appropriate boundary. Avoid moving command defaults or CLI wording into `schema`.
|
|
||||||
- `internal/report` owns report data structures and report JSON writing. It should not grow command-specific audit policy, but it can reasonably share low-level deterministic JSON writing.
|
|
||||||
|
|
||||||
## Path, Key, And Naming Construction Review
|
|
||||||
|
|
||||||
seriatim currently uses local filesystem paths only. There are no remote keys, cache paths, manifests, lock files, daemon paths, object-store keys, or resume state paths in the inspected implementation.
|
|
||||||
|
|
||||||
Path validation is reasonably centralized in `internal/config`:
|
|
||||||
|
|
||||||
- `normalizeInputFiles` handles merge's repeated input files, duplicate detection, sorting, and file existence.
|
|
||||||
- `normalizeOutputPath` validates output/report parent directories.
|
|
||||||
- `requireFile` validates input files and YAML config files.
|
|
||||||
|
|
||||||
Cleanup opportunities:
|
|
||||||
|
|
||||||
- Add private config helpers for required single input paths and optional report paths to reduce repeated trim/normalize validation.
|
|
||||||
- Centralize deterministic JSON output file writing as described above.
|
|
||||||
- Consider a small provenance reference helper for `source#index` formatting and fallback behavior where `internal/overlap` and `internal/coalesce` already share semantics.
|
|
||||||
|
|
||||||
No remote key or generated workspace path cleanup is applicable.
|
|
||||||
|
|
||||||
## Resolution And Catalog Review
|
|
||||||
|
|
||||||
Module resolution is cleanly centralized for merge:
|
|
||||||
|
|
||||||
- `internal/builtin.NewRegistry` registers built-in input, preprocessing, postprocessing, merger, and output modules.
|
|
||||||
- `internal/pipeline.Registry` resolves names and returns user-facing unknown module errors.
|
|
||||||
- `pipeline.Run` validates preprocessing state transitions before execution.
|
|
||||||
|
|
||||||
Output module resolution differs by command:
|
|
||||||
|
|
||||||
- Merge resolves output modules through the pipeline registry.
|
|
||||||
- Normalize accepts only `json` through config validation.
|
|
||||||
- Trim does not expose output modules and always writes JSON.
|
|
||||||
|
|
||||||
Those differences appear intentional for current behavior. Do not force trim and normalize into the merge registry unless artifact-level commands gain actual pluggable output modules.
|
|
||||||
|
|
||||||
Schema resolution is less centralized:
|
|
||||||
|
|
||||||
- Config validates public schema names for CLI/config inputs.
|
|
||||||
- Artifact, normalize, and trim packages switch over the same schema values for output construction, parsing, conversion, and validation.
|
|
||||||
|
|
||||||
Recommended centralization is limited to schema names and narrow validation/selection helpers. Avoid a plugin or catalog abstraction that would imply unimplemented dynamic schemas.
|
|
||||||
|
|
||||||
## Config And Command-Loading Review
|
|
||||||
|
|
||||||
Config loading is explicit and mostly consistent:
|
|
||||||
|
|
||||||
- CLI commands parse flags into option structs.
|
|
||||||
- `internal/config` validates and normalizes runtime configs.
|
|
||||||
- Merge and normalize resolve `SERIATIM_OUTPUT_SCHEMA`; trim accepts an explicit schema override and otherwise preserves the input artifact schema.
|
|
||||||
- Merge sorts and deduplicates repeated input files; trim and normalize each require exactly one input file.
|
|
||||||
|
|
||||||
Likely intentional differences:
|
|
||||||
|
|
||||||
- Trim has `--keep`, `--remove`, and `--allow-empty`; merge and normalize do not.
|
|
||||||
- Merge exposes module lists and stage config; trim and normalize do not run the merge pipeline.
|
|
||||||
- Normalize validates output modules as only `json`; trim has no output module flag.
|
|
||||||
- `--output-schema` has a default in merge and normalize help, but trim's empty default is meaningful.
|
|
||||||
|
|
||||||
Likely cleanup opportunities:
|
|
||||||
|
|
||||||
- Share path/report validation helpers for single-input commands.
|
|
||||||
- Share flag registration for truly common flags after confirming help text stays stable.
|
|
||||||
- Add small config test builders to reduce repeated boilerplate in `internal/config/config_test.go`.
|
|
||||||
|
|
||||||
No duplicated secret handling was found; no secrets are currently implemented.
|
|
||||||
|
|
||||||
## State, Manifest, Or Progress Handling Review
|
|
||||||
|
|
||||||
No durable state, manifests, checkpoints, progress files, resume logic, force mode, dry-run mode, remote storage, or daemon state are implemented.
|
|
||||||
|
|
||||||
Reports are deterministic JSON event artifacts:
|
|
||||||
|
|
||||||
- Merge reports are finalized in `internal/pipeline`.
|
|
||||||
- Normalize reports are built in `internal/normalize`.
|
|
||||||
- Trim reports are currently built in `internal/cli`.
|
|
||||||
|
|
||||||
The only state/progress cleanup recommended before 1.0 is to align trim report construction with an `internal/trim` application service and to avoid adding manifest/resume abstractions unless a concrete implemented workflow requires them.
|
|
||||||
|
|
||||||
## Refactors To Avoid Before 1.0
|
|
||||||
|
|
||||||
Avoid these tempting refactors before 1.0:
|
|
||||||
|
|
||||||
- A generic workflow engine for merge, trim, and normalize. Their command semantics are different enough that a shared engine would obscure behavior.
|
|
||||||
- A broad plugin architecture. Current modules are built-in and registry-driven; dynamic plugins are not implemented.
|
|
||||||
- A sweeping CLI redesign or command factory. The current explicit Cobra setup is easy to audit.
|
|
||||||
- A generalized schema catalog that implies runtime-extensible schemas. Only the implemented minimal, intermediate, and full output schemas should be represented.
|
|
||||||
- A manifest, checkpoint, resume, or dry-run framework. No such state model exists today.
|
|
||||||
- Premature generics-heavy helpers for schema conversions. Keep helpers small and tied to duplicated policy, not shape similarity alone.
|
|
||||||
- Merging backchannel and filler into one classifier package unless the common mechanics are extracted narrowly and domain-specific rules remain obvious.
|
|
||||||
- Replacing all file I/O with an adapter layer. The current app is filesystem-only; introduce adapter seams only where they reduce tested duplication or clarify command boundaries.
|
|
||||||
|
|
||||||
## Recommended Implementation Sequence
|
|
||||||
|
|
||||||
1. Centralize schema names and output schema validation helpers.
|
|
||||||
- Goal: one canonical public schema name source and stable validation behavior.
|
|
||||||
- Files: `internal/config`, `internal/trim`, `internal/artifact`, `internal/normalize`, `schema` as needed.
|
|
||||||
- Tests: `go test ./internal/config ./internal/artifact ./internal/trim ./internal/normalize ./schema ./internal/cli`.
|
|
||||||
- Prompt size: one small implementation prompt.
|
|
||||||
|
|
||||||
2. Extract trim projection policy.
|
|
||||||
- Goal: one implementation of keep/remove selection, sequential ID validation, renumbering, old-to-new mapping, removed IDs, and allow-empty policy.
|
|
||||||
- Files: `internal/trim/apply.go`, `internal/trim/apply_test.go`.
|
|
||||||
- Tests: `go test ./internal/trim ./internal/cli`.
|
|
||||||
- Prompt size: one prompt.
|
|
||||||
|
|
||||||
3. Move trim orchestration into `internal/trim`.
|
|
||||||
- Goal: make trim CLI match the merge/normalize adapter boundary.
|
|
||||||
- Files: `internal/cli/trim.go`, new or updated `internal/trim` service file, trim tests.
|
|
||||||
- Tests: `go test ./internal/trim ./internal/cli`.
|
|
||||||
- Prompt size: one prompt.
|
|
||||||
|
|
||||||
4. Centralize deterministic JSON output writing.
|
|
||||||
- Goal: remove repeated `os.Create` plus indented JSON encoder boilerplate.
|
|
||||||
- Files: a small internal helper plus `internal/builtin/output.go`, `internal/normalize/normalize.go`, `internal/trim` or `internal/cli/trim.go`, `internal/report/report.go`.
|
|
||||||
- Tests: `go test ./internal/builtin ./internal/normalize ./internal/trim ./internal/report ./internal/cli`.
|
|
||||||
- Prompt size: one prompt.
|
|
||||||
|
|
||||||
5. Clean up config and CLI repetition.
|
|
||||||
- Goal: private helpers for single input path validation, optional report paths, and common flags where semantics match.
|
|
||||||
- Files: `internal/config/config.go`, `internal/config/config_test.go`, `internal/cli/*.go`.
|
|
||||||
- Tests: `go test ./internal/config ./internal/cli`.
|
|
||||||
- Prompt size: one prompt; split CLI helper work if help text assertions are added.
|
|
||||||
|
|
||||||
6. Review provenance and category helper extraction.
|
|
||||||
- Goal: centralize only shared mechanics that are easy to get wrong.
|
|
||||||
- Files: `internal/overlap`, `internal/coalesce`, maybe `internal/model`; `internal/backchannel`, `internal/filler`.
|
|
||||||
- Tests: `go test ./internal/overlap ./internal/coalesce ./internal/backchannel ./internal/filler ./internal/cli`.
|
|
||||||
- Prompt size: one or two prompts depending on whether provenance and category work are both pursued.
|
|
||||||
|
|
||||||
7. Test helper cleanup.
|
|
||||||
- Goal: reduce repeated config builders and CLI test fixtures without hiding test intent.
|
|
||||||
- Files: `internal/config/*_test.go`, `internal/cli/*_test.go`, selected module tests.
|
|
||||||
- Tests: affected package tests plus `go test ./...`.
|
|
||||||
- Prompt size: one prompt if scoped to config/CLI; otherwise split by package.
|
|
||||||
|
|
||||||
8. Dead-code and legacy terminology sweep.
|
|
||||||
- Goal: remove stale helpers or wording left after cleanup.
|
|
||||||
- Files: code and docs touched by the above stages.
|
|
||||||
- Tests: `go test ./...`; grep for stale schema or architecture terms.
|
|
||||||
- Prompt size: one prompt.
|
|
||||||
|
|
||||||
## Test Strategy
|
|
||||||
|
|
||||||
Before refactoring:
|
|
||||||
|
|
||||||
- Use existing tests as a behavior lock:
|
|
||||||
- `go test ./internal/config`
|
|
||||||
- `go test ./internal/trim`
|
|
||||||
- `go test ./internal/normalize`
|
|
||||||
- `go test ./internal/artifact`
|
|
||||||
- `go test ./schema`
|
|
||||||
- `go test ./internal/cli`
|
|
||||||
|
|
||||||
During schema cleanup:
|
|
||||||
|
|
||||||
- Preserve tests covering schema defaults, env precedence, invalid schema values, trim schema preservation, trim schema conversion, normalize selected schema, and merge output schemas.
|
|
||||||
- Add a small cross-command test only if centralization changes the public error text source.
|
|
||||||
|
|
||||||
During trim projection cleanup:
|
|
||||||
|
|
||||||
- Add or preserve tests that assert the same selector behavior for full, intermediate, and minimal inputs.
|
|
||||||
- Keep full-schema overlap group recomputation tests separate.
|
|
||||||
|
|
||||||
During trim orchestration move:
|
|
||||||
|
|
||||||
- Keep CLI end-to-end tests for trim output and reports.
|
|
||||||
- Add direct `internal/trim` service tests if report construction moves out of CLI.
|
|
||||||
|
|
||||||
During JSON writer cleanup:
|
|
||||||
|
|
||||||
- Preserve CLI tests that read generated JSON.
|
|
||||||
- If the helper claims deterministic formatting, add a focused helper test for indentation and newline behavior.
|
|
||||||
|
|
||||||
During provenance/category cleanup:
|
|
||||||
|
|
||||||
- Preserve module tests and merge CLI tests that assert `source_ref`, `derived_from`, overlap group segment refs, backchannel categories, filler categories, and report events.
|
|
||||||
|
|
||||||
Final validation for any cleanup sequence:
|
|
||||||
|
|
||||||
- `go test ./...`
|
|
||||||
- `go run ./cmd/seriatim --help`
|
|
||||||
- `go run ./cmd/seriatim merge --help`
|
|
||||||
- `go run ./cmd/seriatim trim --help`
|
|
||||||
- `go run ./cmd/seriatim normalize --help`
|
|
||||||
|
|
||||||
For this audit-only pass, the full test suite was intentionally not run because no code or example behavior changed.
|
|
||||||
|
|
||||||
## Appendix: Findings Not Worth Acting On
|
|
||||||
|
|
||||||
### Keep Merge Pipeline Registry Explicit
|
|
||||||
|
|
||||||
The registry resolution methods for input readers, preprocessors, postprocessors, output writers, and the merger look similar, but they produce stage-specific error messages and keep stage boundaries clear. A generic resolver would save little and could make errors less direct.
|
|
||||||
|
|
||||||
### Keep Merge, Trim, And Normalize As Separate Command Concepts
|
|
||||||
|
|
||||||
The commands share flags and file output behavior, but their domain semantics differ. Merge is a staged pipeline over raw inputs; trim and normalize operate on artifacts. A shared command runner would likely obscure those distinctions.
|
|
||||||
|
|
||||||
### Do Not Centralize All File Reads
|
|
||||||
|
|
||||||
`internal/builtin/input`, `internal/normalize/parse`, `internal/speaker`, `internal/autocorrect`, and trim orchestration read different file contracts and wrap errors differently. Centralizing all reads would not improve clarity today.
|
|
||||||
|
|
||||||
### Keep Schema-Specific Artifact Conversion Visible
|
|
||||||
|
|
||||||
Full, intermediate, and minimal outputs are intentionally different public contracts. Helpers can remove repeated accessors and schema names, but conversion code should remain easy to audit.
|
|
||||||
|
|
||||||
### Leave `samples/` Alone In Code Cleanup
|
|
||||||
|
|
||||||
`samples/` is a documentation/data hygiene question, not a code-quality refactor. The cleanup sequence should focus on maintained `examples/` and avoid destructive sample moves without a separate privacy and documentation pass.
|
|
||||||
|
|
||||||
### Avoid Test Fixture Over-Abstraction
|
|
||||||
|
|
||||||
There is repeated test setup in CLI and config tests, but much of it makes public behavior explicit at the call site. Add small builders where they reduce noise, but do not hide important command arguments behind opaque fixtures.
|
|
||||||
@@ -1,784 +0,0 @@
|
|||||||
# Pre-1.0 Cleanup Implementation Plan
|
|
||||||
|
|
||||||
## Purpose
|
|
||||||
|
|
||||||
This roadmap defines the staged cleanup work recommended by
|
|
||||||
`docs/roadmap/audit.md`. It is written for coding agents that will implement the
|
|
||||||
cleanup in order.
|
|
||||||
|
|
||||||
This is a roadmap document. It may describe planned refactors because it lives
|
|
||||||
under `docs/roadmap/`. Implementation agents must not document planned cleanup
|
|
||||||
as current behavior outside `docs/roadmap/`.
|
|
||||||
|
|
||||||
## Governing Policies
|
|
||||||
|
|
||||||
Follow these policy documents before implementing any stage:
|
|
||||||
|
|
||||||
- `docs/policy/architecture.md`
|
|
||||||
- `docs/policy/development.md`
|
|
||||||
- `docs/policy/documentation.md`
|
|
||||||
|
|
||||||
The cleanup must preserve these project rules:
|
|
||||||
|
|
||||||
- Keep CLI code thin: parse flags, build validated config, delegate.
|
|
||||||
- Keep config normalization and validation in `internal/config`.
|
|
||||||
- Keep public output contracts and validation in `schema`.
|
|
||||||
- Keep merge pipeline orchestration in `internal/pipeline`.
|
|
||||||
- Keep trim and normalize artifact-level; do not run merge modules from those
|
|
||||||
commands.
|
|
||||||
- Keep behavior deterministic and sequential.
|
|
||||||
- Prefer narrow helpers over broad frameworks.
|
|
||||||
- Do not add concurrency, dynamic plugins, durable state, manifests, remote
|
|
||||||
storage, or resume behavior.
|
|
||||||
|
|
||||||
## Global Implementation Rules
|
|
||||||
|
|
||||||
Each stage should be implemented as a small, behavior-preserving change.
|
|
||||||
|
|
||||||
For every stage:
|
|
||||||
|
|
||||||
- Start with `git status --short`.
|
|
||||||
- Read the files listed in that stage before editing.
|
|
||||||
- Do not modify unrelated files.
|
|
||||||
- Preserve public CLI flags, defaults, output schemas, JSON shapes, report event
|
|
||||||
ordering, report event text, and error messages unless the stage explicitly
|
|
||||||
says otherwise.
|
|
||||||
- Prefer private helpers unless a cross-package helper is genuinely needed.
|
|
||||||
- Do not introduce generic engines, plugin systems, broad adapter layers, or
|
|
||||||
generics-heavy abstractions.
|
|
||||||
- Run the stage-specific tests listed in the stage.
|
|
||||||
- Run `go test ./...` before considering the full cleanup sequence complete.
|
|
||||||
|
|
||||||
Documentation updates during cleanup should be minimal. If a refactor changes
|
|
||||||
implemented package boundaries that are described in `docs/internal/` or
|
|
||||||
`docs/policy/architecture.md`, update those docs in the same implementation
|
|
||||||
stage. Do not update user-facing docs if behavior did not change.
|
|
||||||
|
|
||||||
## Stage 1: Centralize Output Schema Names
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Make `schema` the canonical source for public output schema names and keep
|
|
||||||
command-specific default/precedence policy in `internal/config`.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Use the `schema` package as the canonical home for output schema name constants
|
|
||||||
because public output contracts already live there.
|
|
||||||
|
|
||||||
Add these exported string constants to `schema`:
|
|
||||||
|
|
||||||
- `OutputSchemaMinimal = "seriatim-minimal"`
|
|
||||||
- `OutputSchemaIntermediate = "seriatim-intermediate"`
|
|
||||||
- `OutputSchemaFull = "seriatim-full"`
|
|
||||||
|
|
||||||
Add narrow schema-name helpers in `schema`, not CLI-specific helpers:
|
|
||||||
|
|
||||||
- `ValidOutputSchemaName(value string) bool`
|
|
||||||
- `OutputSchemaNames() []string`
|
|
||||||
|
|
||||||
Do not put CLI flag names or default selection policy in `schema`.
|
|
||||||
|
|
||||||
Keep the `internal/config` constants as aliases for compatibility inside the
|
|
||||||
repository:
|
|
||||||
|
|
||||||
- `config.OutputSchemaMinimal = schema.OutputSchemaMinimal`
|
|
||||||
- `config.OutputSchemaIntermediate = schema.OutputSchemaIntermediate`
|
|
||||||
- `config.OutputSchemaFull = schema.OutputSchemaFull`
|
|
||||||
|
|
||||||
Remove the duplicate string constants from `internal/trim/artifact.go`; use the
|
|
||||||
canonical schema constants instead. A type alias or package-local aliases are
|
|
||||||
acceptable only if they point directly to the `schema` constants and do not
|
|
||||||
repeat string literals.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `schema/output.go`
|
|
||||||
- `schema/output_test.go`
|
|
||||||
- `internal/config/config.go`
|
|
||||||
- `internal/config/config_test.go`
|
|
||||||
- `internal/trim/artifact.go`
|
|
||||||
- `internal/trim/artifact_test.go`
|
|
||||||
- `internal/artifact/transcript.go`
|
|
||||||
- `internal/normalize/build.go`
|
|
||||||
- `internal/cli/*_test.go`
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Add canonical output schema constants and helpers to `schema/output.go`.
|
|
||||||
2. Update `internal/config` schema constants to alias `schema` constants.
|
|
||||||
3. Update config validation to use `schema.ValidOutputSchemaName` while keeping
|
|
||||||
the existing `--output-schema must be one of ...` error text.
|
|
||||||
4. Update `internal/trim` to stop repeating schema string constants.
|
|
||||||
5. Update affected tests only where they refer to moved constants.
|
|
||||||
6. Search for raw schema string literals outside tests and docs. Keep raw values
|
|
||||||
in docs and test fixtures where they are intentionally testing serialized
|
|
||||||
public JSON.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- There is one canonical set of output schema string constants in `schema`.
|
|
||||||
- `merge` and `normalize` still default to `seriatim-intermediate` and still
|
|
||||||
honor `SERIATIM_OUTPUT_SCHEMA`.
|
|
||||||
- `trim` still preserves the input artifact schema when `--output-schema` is
|
|
||||||
omitted.
|
|
||||||
- Invalid schema error text remains stable unless tests are intentionally
|
|
||||||
updated.
|
|
||||||
- No new schema registry or plugin-style abstraction exists.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./schema ./internal/config ./internal/artifact ./internal/trim ./internal/normalize ./internal/cli
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt.
|
|
||||||
|
|
||||||
## Stage 2: Extract Trim Projection Policy
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Use one implementation for trim selector policy, ID validation, retained-index
|
|
||||||
selection, ID renumbering metadata, removed IDs, and empty-output handling.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Add a private projection helper in `internal/trim/apply.go`. Do not introduce a
|
|
||||||
generic artifact framework.
|
|
||||||
|
|
||||||
Recommended shape:
|
|
||||||
|
|
||||||
```go
|
|
||||||
type projection struct {
|
|
||||||
retainedIndexes []int
|
|
||||||
oldToNewID map[int]int
|
|
||||||
removedIDs []int
|
|
||||||
}
|
|
||||||
|
|
||||||
func projectSegmentIDs(ids []int, opts Options) (projection, error)
|
|
||||||
```
|
|
||||||
|
|
||||||
The helper should:
|
|
||||||
|
|
||||||
- validate `Mode`;
|
|
||||||
- reject an empty selector;
|
|
||||||
- validate input IDs are positive, unique, and sequential from `1..n`;
|
|
||||||
- validate selected IDs exist;
|
|
||||||
- apply keep/remove semantics;
|
|
||||||
- return retained input indexes in original order;
|
|
||||||
- return deterministic old-to-new ID mappings;
|
|
||||||
- return removed input IDs in original order;
|
|
||||||
- enforce `AllowEmpty`.
|
|
||||||
|
|
||||||
Keep schema-specific segment reconstruction in `Apply`, `ApplyIntermediate`,
|
|
||||||
and `ApplyMinimal`. Keep full-schema overlap group recomputation only in the
|
|
||||||
full-schema path.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `internal/trim/apply.go`
|
|
||||||
- `internal/trim/apply_test.go`
|
|
||||||
- `internal/cli/trim_test.go`
|
|
||||||
- `schema/output.go`
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Add the private projection helper and small supporting types.
|
|
||||||
2. Refactor `Apply` to call the helper, reconstruct full segments from retained
|
|
||||||
indexes, renumber IDs, clear old overlap group IDs, and recompute overlap
|
|
||||||
groups.
|
|
||||||
3. Refactor `ApplyIntermediate` to call the helper and reconstruct intermediate
|
|
||||||
segments.
|
|
||||||
4. Refactor `ApplyMinimal` to call the helper and reconstruct minimal segments.
|
|
||||||
5. Preserve existing error messages from `validateMode`, empty selectors,
|
|
||||||
invalid input IDs, missing selected IDs, and empty output.
|
|
||||||
6. Add a focused table test proving the same selector policy is applied to all
|
|
||||||
three schema shapes.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- Keep/remove behavior is unchanged for all supported artifact schemas.
|
|
||||||
- Segment IDs are still reassigned sequentially from `1`.
|
|
||||||
- Full-schema trim still recomputes overlap groups.
|
|
||||||
- Intermediate and minimal trim still do not create overlap groups.
|
|
||||||
- The common selector and ID policy exists in one helper.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./internal/trim ./internal/cli
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt.
|
|
||||||
|
|
||||||
## Stage 3: Move Trim Orchestration Into `internal/trim`
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Make `trim` match the repository's adapter boundary: CLI parses flags and
|
|
||||||
delegates; artifact-level orchestration lives in `internal/trim`.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Add `Run(ctx context.Context, cfg config.TrimConfig) error` to `internal/trim`.
|
|
||||||
|
|
||||||
Move from `internal/cli/trim.go` into `internal/trim`:
|
|
||||||
|
|
||||||
- selector parsing from validated config;
|
|
||||||
- input file read;
|
|
||||||
- artifact parse;
|
|
||||||
- `ApplyArtifact`;
|
|
||||||
- output schema selection and conversion;
|
|
||||||
- output validation;
|
|
||||||
- transcript output JSON write;
|
|
||||||
- trim audit payload construction;
|
|
||||||
- report event construction;
|
|
||||||
- old-to-new ID mapping ordering.
|
|
||||||
|
|
||||||
Keep in `internal/cli/trim.go`:
|
|
||||||
|
|
||||||
- Cobra command definition;
|
|
||||||
- flag registration;
|
|
||||||
- `cmd.Flags().Changed("output-schema")` handling;
|
|
||||||
- `config.NewTrimConfig`;
|
|
||||||
- delegation to `trim.Run`.
|
|
||||||
|
|
||||||
Temporarily keep any moved JSON writer local to `internal/trim` if Stage 4 has
|
|
||||||
not yet been implemented. Stage 4 will centralize file writing.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `internal/cli/trim.go`
|
|
||||||
- `internal/cli/trim_test.go`
|
|
||||||
- `internal/trim/*.go`
|
|
||||||
- `internal/trim/*_test.go`
|
|
||||||
- `internal/config/config.go`
|
|
||||||
- `internal/report/report.go`
|
|
||||||
- `internal/normalize/normalize.go`
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Create `internal/trim/run.go` or another appropriately named file.
|
|
||||||
2. Move trim audit structs to `internal/trim`. Keep JSON field names unchanged.
|
|
||||||
3. Add `Run(ctx, cfg)` and check `ctx.Err()` before doing work.
|
|
||||||
4. Move helper functions needed only by trim orchestration, including ordered
|
|
||||||
ID mapping.
|
|
||||||
5. Update `internal/cli/trim.go` to delegate to `trim.Run`.
|
|
||||||
6. Add direct `internal/trim` tests for service-level behavior if existing CLI
|
|
||||||
tests do not cover moved report/output behavior clearly.
|
|
||||||
7. Keep all existing trim CLI tests passing.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- `internal/cli/trim.go` contains flag wiring, config construction, and a call
|
|
||||||
to `trim.Run`; it no longer performs artifact I/O or report construction.
|
|
||||||
- Trim output files and report files are unchanged for existing tests.
|
|
||||||
- Trim error wrapping is not weakened for user-facing file, parse, validation,
|
|
||||||
or report-write failures.
|
|
||||||
- No merge pipeline modules are invoked by trim.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./internal/trim ./internal/cli
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt.
|
|
||||||
|
|
||||||
## Stage 4: Centralize Deterministic JSON File Writing
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Remove repeated `os.Create` plus indented `json.Encoder` boilerplate while
|
|
||||||
preserving current JSON formatting.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Create a small package named `internal/jsonfile`.
|
|
||||||
|
|
||||||
Recommended API:
|
|
||||||
|
|
||||||
```go
|
|
||||||
package jsonfile
|
|
||||||
|
|
||||||
func Write(path string, value any) error
|
|
||||||
```
|
|
||||||
|
|
||||||
The helper should:
|
|
||||||
|
|
||||||
- create or truncate the target path with `os.Create`;
|
|
||||||
- encode JSON with `encoder.SetIndent("", " ")`;
|
|
||||||
- preserve the current trailing newline produced by `Encoder.Encode`;
|
|
||||||
- return underlying create/encode/close errors with enough context for callers
|
|
||||||
to wrap where they already wrap.
|
|
||||||
|
|
||||||
Do not implement atomic writes, temporary files, directory creation, lock files,
|
|
||||||
or fsync behavior in this stage.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `internal/builtin/output.go`
|
|
||||||
- `internal/report/report.go`
|
|
||||||
- `internal/normalize/normalize.go`
|
|
||||||
- `internal/trim/run.go` or `internal/cli/trim.go`, depending on Stage 3 state
|
|
||||||
- Existing CLI tests that read output JSON
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Add `internal/jsonfile/jsonfile.go`.
|
|
||||||
2. Add a focused `internal/jsonfile/jsonfile_test.go` covering two-space
|
|
||||||
indentation and valid JSON.
|
|
||||||
3. Update merge JSON output writer to use `jsonfile.Write`.
|
|
||||||
4. Update normalize output writing to use `jsonfile.Write`, preserving
|
|
||||||
user-facing error context.
|
|
||||||
5. Update trim output writing to use `jsonfile.Write`.
|
|
||||||
6. Update `report.WriteJSON` to use `jsonfile.Write`.
|
|
||||||
7. Remove duplicated local `writeOutputJSON` helpers.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- Merge, trim, normalize, and report JSON are still pretty-printed with two
|
|
||||||
spaces and a trailing newline.
|
|
||||||
- There is one implementation of deterministic JSON file writing.
|
|
||||||
- Report construction remains in `internal/report` or command packages; only
|
|
||||||
file-writing mechanics are shared.
|
|
||||||
- No new persistence semantics are introduced.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./internal/jsonfile ./internal/builtin ./internal/report ./internal/normalize ./internal/trim ./internal/cli
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt.
|
|
||||||
|
|
||||||
## Stage 5: Clean Up Config Path Validation
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Reduce repeated path validation in single-input command config without changing
|
|
||||||
config precedence or errors.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Add private helpers in `internal/config/config.go` only. Do not create a config
|
|
||||||
builder framework.
|
|
||||||
|
|
||||||
Recommended helpers:
|
|
||||||
|
|
||||||
```go
|
|
||||||
func normalizeSingleInputFile(path string, flag string) (string, error)
|
|
||||||
func normalizeOptionalOutputPath(path string, flag string) (string, error)
|
|
||||||
```
|
|
||||||
|
|
||||||
`normalizeSingleInputFile` should preserve the current `--input-file is
|
|
||||||
required` and `requireFile` behavior.
|
|
||||||
|
|
||||||
`normalizeOptionalOutputPath` should return `""` for empty or whitespace-only
|
|
||||||
values and otherwise call the existing required output path validation.
|
|
||||||
|
|
||||||
Keep `normalizeInputFiles` separate for merge because merge accepts repeated
|
|
||||||
input files, rejects duplicates, and sorts paths.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `internal/config/config.go`
|
|
||||||
- `internal/config/config_test.go`
|
|
||||||
- `internal/cli/trim_test.go`
|
|
||||||
- `internal/cli/normalize_test.go`
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Add private path helpers.
|
|
||||||
2. Refactor `NewTrimConfig` to use them.
|
|
||||||
3. Refactor `NewNormalizeConfig` to use them.
|
|
||||||
4. Keep `NewMergeConfig` behavior unchanged except where it can reuse existing
|
|
||||||
`normalizeOutputPath`.
|
|
||||||
5. Preserve all current error message substrings tested by config and CLI
|
|
||||||
tests.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- Trim and normalize single-input path normalization is implemented once.
|
|
||||||
- Optional report path handling is implemented once.
|
|
||||||
- Merge multi-input normalization remains explicit and unchanged.
|
|
||||||
- No config struct fields, env vars, flags, defaults, or precedence rules
|
|
||||||
change.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./internal/config ./internal/cli
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt.
|
|
||||||
|
|
||||||
## Stage 6: Add Narrow CLI Flag Helpers
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Reduce typo-prone repeated Cobra flag wiring while keeping command files
|
|
||||||
explicit and readable.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Add helper functions in `internal/cli/flags.go`. Helpers should take a
|
|
||||||
`*cobra.Command` and a target pointer. This avoids adding a direct import of
|
|
||||||
`pflag` unless it becomes clearly cleaner.
|
|
||||||
|
|
||||||
Recommended helpers:
|
|
||||||
|
|
||||||
- `addOutputFileFlag(cmd *cobra.Command, target *string)`
|
|
||||||
- `addReportFileFlag(cmd *cobra.Command, target *string)`
|
|
||||||
- `addOutputModulesFlag(cmd *cobra.Command, target *string)`
|
|
||||||
- `addMergeOutputSchemaFlag(cmd *cobra.Command, target *string)`
|
|
||||||
- `addNormalizeOutputSchemaFlag(cmd *cobra.Command, target *string)`
|
|
||||||
- `addTrimOutputSchemaFlag(cmd *cobra.Command, target *string)`
|
|
||||||
|
|
||||||
Do not create one generic output schema helper because trim has different
|
|
||||||
omitted-flag semantics and help text.
|
|
||||||
|
|
||||||
For `--input-file`, prefer keeping command-local definitions unless a helper
|
|
||||||
improves clarity:
|
|
||||||
|
|
||||||
- merge uses `StringArrayVar`;
|
|
||||||
- trim and normalize use `StringVar`;
|
|
||||||
- usage text differs.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `internal/cli/merge.go`
|
|
||||||
- `internal/cli/trim.go`
|
|
||||||
- `internal/cli/normalize.go`
|
|
||||||
- `internal/cli/*_test.go`
|
|
||||||
- `docs/cli.md`, only to verify flag text if behavior or help text changes
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Add `internal/cli/flags.go`.
|
|
||||||
2. Move only identical or intentionally paired flag definitions into helpers.
|
|
||||||
3. Keep command-specific flags and semantic differences local.
|
|
||||||
4. Run command help manually and compare the important flag names/defaults.
|
|
||||||
5. Update tests only if they assert help text that intentionally changed.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- Public flag names and defaults are unchanged.
|
|
||||||
- Help text remains at least as accurate as before.
|
|
||||||
- Command files remain easy to read.
|
|
||||||
- No command factory or shared command runner is introduced.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./internal/cli
|
|
||||||
go run ./cmd/seriatim --help
|
|
||||||
go run ./cmd/seriatim merge --help
|
|
||||||
go run ./cmd/seriatim trim --help
|
|
||||||
go run ./cmd/seriatim normalize --help
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt.
|
|
||||||
|
|
||||||
## Stage 7: Centralize Common Segment Reference Formatting
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Use one helper for the shared "best available segment reference" policy used by
|
|
||||||
overlap and coalesce logic.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Add a small helper in `internal/model`, because the helper operates on
|
|
||||||
`model.Segment` and expresses domain reference semantics.
|
|
||||||
|
|
||||||
Recommended API:
|
|
||||||
|
|
||||||
```go
|
|
||||||
func SegmentReference(segment Segment) string
|
|
||||||
```
|
|
||||||
|
|
||||||
The helper should:
|
|
||||||
|
|
||||||
- return `fmt.Sprintf("%s#%d", segment.Source, *segment.SourceSegmentIndex)`
|
|
||||||
when `Source` is non-empty and `SourceSegmentIndex` is non-nil;
|
|
||||||
- otherwise return `segment.SourceRef` when non-empty;
|
|
||||||
- otherwise return `""`.
|
|
||||||
|
|
||||||
Use this helper only where the existing code already has this exact fallback
|
|
||||||
policy. Keep generated references such as `word-run:%d:%d:%d`, `coalesce:%d`,
|
|
||||||
and `resolve-danglers:%d` local to the modules that create them.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `internal/model/model.go`
|
|
||||||
- `internal/overlap/detect.go`
|
|
||||||
- `internal/coalesce/coalesce.go`
|
|
||||||
- `internal/overlap/*_test.go`
|
|
||||||
- `internal/coalesce/*_test.go`
|
|
||||||
- `internal/cli/merge_test.go`
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Add `SegmentReference` and tests in `internal/model`.
|
|
||||||
2. Replace duplicated fallback logic in overlap detection.
|
|
||||||
3. Replace duplicated fallback logic in coalesce.
|
|
||||||
4. Do not change generated reference prefixes.
|
|
||||||
5. Do not change sorting behavior or derived-from ordering.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- Existing provenance strings in full output remain unchanged.
|
|
||||||
- `source#index` formatting exists in one shared helper for matching semantics.
|
|
||||||
- Module-specific generated references stay module-local.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./internal/model ./internal/overlap ./internal/coalesce ./internal/cli
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt.
|
|
||||||
|
|
||||||
## Stage 8: Reduce Repetition In Schema Semantic Validation
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Use one private helper for cross-schema segment ID and timing invariants.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Keep this helper private to `schema`. Do not use generics unless the resulting
|
|
||||||
code is clearly simpler than a small projection type.
|
|
||||||
|
|
||||||
Recommended shape:
|
|
||||||
|
|
||||||
```go
|
|
||||||
type segmentSemantics struct {
|
|
||||||
id int
|
|
||||||
start float64
|
|
||||||
end float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateSegmentSemantics(segments []segmentSemantics) error
|
|
||||||
```
|
|
||||||
|
|
||||||
Preserve current error text:
|
|
||||||
|
|
||||||
- `segment %d has id %d; want %d`
|
|
||||||
- `segment %d has end %.3f before start %.3f`
|
|
||||||
|
|
||||||
Keep full-schema overlap group timing validation separate.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `schema/output.go`
|
|
||||||
- `schema/output_test.go`
|
|
||||||
- callers in `internal/artifact`, `internal/trim`, and `internal/normalize`
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Add the private segment semantic helper.
|
|
||||||
2. Adapt full, intermediate, and minimal validation functions to project their
|
|
||||||
segment shapes into the helper.
|
|
||||||
3. Keep full overlap group semantic validation in the full validation path.
|
|
||||||
4. Add or preserve tests that cover invalid IDs and invalid timing for each
|
|
||||||
public schema shape.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- Sequential ID and timing rules are implemented once.
|
|
||||||
- Public schema validation behavior and error wording remain stable.
|
|
||||||
- Full overlap group validation remains full-schema only.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./schema ./internal/artifact ./internal/trim ./internal/normalize ./internal/cli
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt.
|
|
||||||
|
|
||||||
## Stage 9: Test Helper Cleanup
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Reduce repeated test setup after behavior-preserving refactors are complete.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
Keep test helpers package-local. Do not add exported test utility packages.
|
|
||||||
|
|
||||||
Prioritize helpers that reduce noise without hiding public command behavior:
|
|
||||||
|
|
||||||
- config option builders in `internal/config/config_test.go`;
|
|
||||||
- command execution helpers in `internal/cli` if duplication remains after
|
|
||||||
trim orchestration and flag helper cleanup;
|
|
||||||
- fixture builders for trim schema shapes if they stay repetitive.
|
|
||||||
|
|
||||||
Do not abstract command arguments so far that tests no longer show the public
|
|
||||||
CLI contract being exercised.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- `internal/config/config_test.go`
|
|
||||||
- `internal/cli/merge_test.go`
|
|
||||||
- `internal/cli/trim_test.go`
|
|
||||||
- `internal/cli/normalize_test.go`
|
|
||||||
- `internal/trim/*_test.go`
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Identify repeated setup that survived prior stages.
|
|
||||||
2. Add package-local helper builders for config options with valid defaults.
|
|
||||||
3. Consolidate duplicate read/write JSON helpers only inside the test package
|
|
||||||
where they are used.
|
|
||||||
4. Keep high-signal command arguments inline in CLI tests.
|
|
||||||
5. Avoid golden-file rewrites or fixture churn unrelated to cleanup.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- Tests are shorter where setup was noisy.
|
|
||||||
- Public behavior being tested remains obvious.
|
|
||||||
- No production code changes are made in this stage unless a test-only cleanup
|
|
||||||
reveals dead production code from earlier stages.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./internal/config ./internal/cli ./internal/trim
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
One implementation prompt if limited to config/CLI/trim tests. Split by package
|
|
||||||
if the diff becomes large.
|
|
||||||
|
|
||||||
## Stage 10: Final Dead-Code And Documentation Sweep
|
|
||||||
|
|
||||||
### Goal
|
|
||||||
|
|
||||||
Remove stale helpers and update internal documentation only where implemented
|
|
||||||
cleanup changed current boundaries.
|
|
||||||
|
|
||||||
### Decision
|
|
||||||
|
|
||||||
This is a cleanup verification stage, not a feature stage.
|
|
||||||
|
|
||||||
Do not delete `samples/`, move examples, redesign docs, or alter user-facing
|
|
||||||
references unless directly required by implemented cleanup.
|
|
||||||
|
|
||||||
### Files To Inspect
|
|
||||||
|
|
||||||
- All files touched by Stages 1-9
|
|
||||||
- `docs/policy/architecture.md`
|
|
||||||
- `docs/policy/development.md`
|
|
||||||
- `docs/internal/artifacts.md`
|
|
||||||
- `docs/internal/pipeline.md`
|
|
||||||
- `docs/internal/modules.md`
|
|
||||||
- `docs/cli.md`
|
|
||||||
- `docs/config.md`
|
|
||||||
|
|
||||||
### Implementation Steps
|
|
||||||
|
|
||||||
1. Search for obsolete helpers, duplicate schema constants, duplicate JSON
|
|
||||||
writers, old trim CLI orchestration helpers, and unused imports.
|
|
||||||
2. Run `go test ./...`.
|
|
||||||
3. Run command help checks.
|
|
||||||
4. Update internal docs only if package responsibility changed in a way current
|
|
||||||
docs now describe inaccurately.
|
|
||||||
5. Do not add planned cleanup notes outside `docs/roadmap/`.
|
|
||||||
|
|
||||||
### Acceptance Criteria
|
|
||||||
|
|
||||||
- No duplicate output schema string constants remain outside canonical aliases
|
|
||||||
and intentional docs/test fixtures.
|
|
||||||
- No duplicate production `writeOutputJSON` helper remains.
|
|
||||||
- `internal/cli/trim.go` is a thin adapter.
|
|
||||||
- Docs outside `docs/roadmap/` describe only implemented behavior.
|
|
||||||
- Full repository tests pass.
|
|
||||||
|
|
||||||
### Validation Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./...
|
|
||||||
go run ./cmd/seriatim --help
|
|
||||||
go run ./cmd/seriatim merge --help
|
|
||||||
go run ./cmd/seriatim trim --help
|
|
||||||
go run ./cmd/seriatim normalize --help
|
|
||||||
rg -n "SchemaMinimal|SchemaIntermediate|SchemaFull|writeOutputJSON|seriatim-minimal|seriatim-intermediate|seriatim-full" internal schema
|
|
||||||
```
|
|
||||||
|
|
||||||
The `rg` command is a review aid. Raw schema strings may still be appropriate in
|
|
||||||
canonical constants, docs, JSON Schema files, and tests that assert serialized
|
|
||||||
public contracts.
|
|
||||||
|
|
||||||
### Prompt Size
|
|
||||||
|
|
||||||
Small enough for one implementation prompt after prior stages are complete.
|
|
||||||
|
|
||||||
## Deferred Or Explicitly Avoided Work
|
|
||||||
|
|
||||||
Do not implement these as part of the pre-1.0 cleanup sequence unless a later
|
|
||||||
audit identifies a concrete bug or larger duplication pattern:
|
|
||||||
|
|
||||||
- A generic workflow engine for merge, trim, and normalize.
|
|
||||||
- Dynamic plugins or runtime-extensible schemas.
|
|
||||||
- A manifest, checkpoint, resume, dry-run, force, or progress framework.
|
|
||||||
- Atomic output writes or fsync semantics.
|
|
||||||
- A broad filesystem adapter layer.
|
|
||||||
- A combined backchannel/filler classifier framework.
|
|
||||||
- A generic registry resolver that erases stage-specific error messages.
|
|
||||||
- A broad public API for internals.
|
|
||||||
- Destructive changes to `samples/`.
|
|
||||||
|
|
||||||
Backchannel and filler share mechanics, but the cleanup decision is to defer
|
|
||||||
shared category-tagging extraction before 1.0. The current duplication is small,
|
|
||||||
domain-specific, and well isolated.
|
|
||||||
|
|
||||||
## Full Cleanup Validation
|
|
||||||
|
|
||||||
After all implemented stages:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go test ./...
|
|
||||||
go run ./cmd/seriatim --help
|
|
||||||
go run ./cmd/seriatim merge --help
|
|
||||||
go run ./cmd/seriatim trim --help
|
|
||||||
go run ./cmd/seriatim normalize --help
|
|
||||||
```
|
|
||||||
|
|
||||||
Manual review checklist:
|
|
||||||
|
|
||||||
- Public CLI behavior is unchanged.
|
|
||||||
- Public output schemas and JSON shapes are unchanged.
|
|
||||||
- Report event ordering and text remain stable unless tests were deliberately
|
|
||||||
updated.
|
|
||||||
- Trim, normalize, and merge boundaries match `docs/policy/architecture.md`.
|
|
||||||
- No planned or aspirational behavior was added to non-roadmap docs.
|
|
||||||
- Cleanup reduced duplicated policy without introducing broad abstractions.
|
|
||||||
|
|
||||||
## Open Questions
|
|
||||||
|
|
||||||
No blocking questions are required to implement this plan.
|
|
||||||
|
|
||||||
If a future implementation stage discovers that preserving current behavior
|
|
||||||
conflicts with one of the structural decisions above, stop that stage and ask
|
|
||||||
for direction before changing public CLI behavior, public JSON contracts, or
|
|
||||||
report semantics.
|
|
||||||
@@ -2,10 +2,9 @@ package builtin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||||
|
"gitea.maximumdirect.net/eric/seriatim/internal/jsonfile"
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,15 +19,7 @@ func (jsonOutputWriter) Write(ctx context.Context, out any, rpt report.Report, c
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := os.Create(cfg.OutputFile)
|
if err := jsonfile.Write(cfg.OutputFile, out); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
enc := json.NewEncoder(file)
|
|
||||||
enc.SetIndent("", " ")
|
|
||||||
if err := enc.Encode(out); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
internal/cli/flags.go
Normal file
31
internal/cli/flags.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func addOutputFileFlag(cmd *cobra.Command, target *string) {
|
||||||
|
cmd.Flags().StringVar(target, "output-file", "", "output transcript JSON file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func addReportFileFlag(cmd *cobra.Command, target *string) {
|
||||||
|
cmd.Flags().StringVar(target, "report-file", "", "optional report JSON file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func addOutputModulesFlag(cmd *cobra.Command, target *string) {
|
||||||
|
cmd.Flags().StringVar(target, "output-modules", config.DefaultOutputModules, "comma-separated output modules")
|
||||||
|
}
|
||||||
|
|
||||||
|
func addMergeOutputSchemaFlag(cmd *cobra.Command, target *string) {
|
||||||
|
cmd.Flags().StringVar(target, "output-schema", config.DefaultOutputSchema, "output JSON schema: seriatim-minimal, seriatim-intermediate (default), or seriatim-full")
|
||||||
|
}
|
||||||
|
|
||||||
|
func addNormalizeOutputSchemaFlag(cmd *cobra.Command, target *string) {
|
||||||
|
cmd.Flags().StringVar(target, "output-schema", config.DefaultOutputSchema, "output JSON schema: seriatim-minimal, seriatim-intermediate, or seriatim-full")
|
||||||
|
}
|
||||||
|
|
||||||
|
func addTrimOutputSchemaFlag(cmd *cobra.Command, target *string) {
|
||||||
|
cmd.Flags().StringVar(target, "output-schema", "", "optional output JSON schema override: seriatim-minimal, seriatim-intermediate, or seriatim-full")
|
||||||
|
}
|
||||||
@@ -31,13 +31,13 @@ func newMergeCommand() *cobra.Command {
|
|||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.StringArrayVar(&opts.InputFiles, "input-file", nil, "input transcript file; may be repeated")
|
flags.StringArrayVar(&opts.InputFiles, "input-file", nil, "input transcript file; may be repeated")
|
||||||
flags.StringVar(&opts.OutputFile, "output-file", "", "output transcript JSON file")
|
addOutputFileFlag(cmd, &opts.OutputFile)
|
||||||
flags.StringVar(&opts.ReportFile, "report-file", "", "optional report JSON file")
|
addReportFileFlag(cmd, &opts.ReportFile)
|
||||||
flags.StringVar(&opts.SpeakersFile, "speakers", "", "speaker map file")
|
flags.StringVar(&opts.SpeakersFile, "speakers", "", "speaker map file")
|
||||||
flags.StringVar(&opts.AutocorrectFile, "autocorrect", "", "autocorrect rules file")
|
flags.StringVar(&opts.AutocorrectFile, "autocorrect", "", "autocorrect rules file")
|
||||||
flags.StringVar(&opts.InputReader, "input-reader", config.DefaultInputReader, "input reader module")
|
flags.StringVar(&opts.InputReader, "input-reader", config.DefaultInputReader, "input reader module")
|
||||||
flags.StringVar(&opts.OutputModules, "output-modules", config.DefaultOutputModules, "comma-separated output modules")
|
addOutputModulesFlag(cmd, &opts.OutputModules)
|
||||||
flags.StringVar(&opts.OutputSchema, "output-schema", config.DefaultOutputSchema, "output JSON schema: seriatim-minimal, seriatim-intermediate (default), or seriatim-full")
|
addMergeOutputSchemaFlag(cmd, &opts.OutputSchema)
|
||||||
flags.StringVar(&opts.PreprocessingModules, "preprocessing-modules", config.DefaultPreprocessingModules, "comma-separated preprocessing modules")
|
flags.StringVar(&opts.PreprocessingModules, "preprocessing-modules", config.DefaultPreprocessingModules, "comma-separated preprocessing modules")
|
||||||
flags.StringVar(&opts.PostprocessingModules, "postprocessing-modules", config.DefaultPostprocessingModules, "comma-separated postprocessing modules")
|
flags.StringVar(&opts.PostprocessingModules, "postprocessing-modules", config.DefaultPostprocessingModules, "comma-separated postprocessing modules")
|
||||||
flags.StringVar(&opts.CoalesceGap, "coalesce-gap", config.DefaultCoalesceGapValue, "maximum same-speaker gap in seconds for coalesce")
|
flags.StringVar(&opts.CoalesceGap, "coalesce-gap", config.DefaultCoalesceGapValue, "maximum same-speaker gap in seconds for coalesce")
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ func newNormalizeCommand() *cobra.Command {
|
|||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.StringVar(&opts.InputFile, "input-file", "", "input transcript JSON file")
|
flags.StringVar(&opts.InputFile, "input-file", "", "input transcript JSON file")
|
||||||
flags.StringVar(&opts.OutputFile, "output-file", "", "output transcript JSON file")
|
addOutputFileFlag(cmd, &opts.OutputFile)
|
||||||
flags.StringVar(&opts.ReportFile, "report-file", "", "optional report JSON file")
|
addReportFileFlag(cmd, &opts.ReportFile)
|
||||||
flags.StringVar(&opts.OutputSchema, "output-schema", config.DefaultOutputSchema, "output JSON schema: seriatim-minimal, seriatim-intermediate, or seriatim-full")
|
addNormalizeOutputSchemaFlag(cmd, &opts.OutputSchema)
|
||||||
flags.StringVar(&opts.OutputModules, "output-modules", config.DefaultOutputModules, "comma-separated output modules")
|
addOutputModulesFlag(cmd, &opts.OutputModules)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,12 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
"gitea.maximumdirect.net/eric/seriatim/internal/trim"
|
||||||
triminternal "gitea.maximumdirect.net/eric/seriatim/internal/trim"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type trimAuditReport struct {
|
|
||||||
Operation string `json:"operation"`
|
|
||||||
InputFile string `json:"input_file"`
|
|
||||||
OutputFile string `json:"output_file"`
|
|
||||||
InputSchema string `json:"input_schema"`
|
|
||||||
OutputSchema string `json:"output_schema"`
|
|
||||||
Mode string `json:"mode"`
|
|
||||||
Selector string `json:"selector"`
|
|
||||||
SelectedIDs []int `json:"selected_ids"`
|
|
||||||
AllowEmpty bool `json:"allow_empty"`
|
|
||||||
InputSegmentCount int `json:"input_segment_count"`
|
|
||||||
RetainedSegmentCount int `json:"retained_segment_count"`
|
|
||||||
RemovedSegmentCount int `json:"removed_segment_count"`
|
|
||||||
RemovedInputIDs []int `json:"removed_input_ids"`
|
|
||||||
OldToNewIDMapping []trimIDMapping `json:"old_to_new_id_mapping"`
|
|
||||||
OverlapGroupsRecomputed bool `json:"overlap_groups_recomputed"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type trimIDMapping struct {
|
|
||||||
OldID int `json:"old_id"`
|
|
||||||
NewID int `json:"new_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func newTrimCommand() *cobra.Command {
|
func newTrimCommand() *cobra.Command {
|
||||||
var opts config.TrimOptions
|
var opts config.TrimOptions
|
||||||
|
|
||||||
@@ -53,139 +24,18 @@ func newTrimCommand() *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
selector, err := triminternal.ParseSelector(cfg.Selector)
|
return trim.Run(cmd.Context(), cfg)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid selector %q: %w", cfg.Selector, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := os.ReadFile(cfg.InputFile)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("read --input-file %q: %w", cfg.InputFile, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
artifact, err := triminternal.ParseArtifactJSON(data)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("--input-file %q: %w", cfg.InputFile, err)
|
|
||||||
}
|
|
||||||
inputSegmentCount := artifact.SegmentCount()
|
|
||||||
inputSchema := artifact.Schema
|
|
||||||
|
|
||||||
mode := triminternal.ModeKeep
|
|
||||||
if cfg.Mode == "remove" {
|
|
||||||
mode = triminternal.ModeRemove
|
|
||||||
}
|
|
||||||
|
|
||||||
trimmed, err := triminternal.ApplyArtifact(artifact, triminternal.Options{
|
|
||||||
Mode: mode,
|
|
||||||
Selector: selector,
|
|
||||||
AllowEmpty: cfg.AllowEmpty,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
outputSchema := artifact.Schema
|
|
||||||
if cfg.OutputSchema != "" {
|
|
||||||
outputSchema = cfg.OutputSchema
|
|
||||||
}
|
|
||||||
|
|
||||||
outputArtifact, err := triminternal.ConvertArtifact(trimmed.Artifact, outputSchema)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := triminternal.ValidateArtifact(outputArtifact); err != nil {
|
|
||||||
return fmt.Errorf("validate trimmed output: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := writeOutputJSON(cfg.OutputFile, outputArtifact.Value()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.ReportFile != "" {
|
|
||||||
audit := trimAuditReport{
|
|
||||||
Operation: "trim",
|
|
||||||
InputFile: cfg.InputFile,
|
|
||||||
OutputFile: cfg.OutputFile,
|
|
||||||
InputSchema: inputSchema,
|
|
||||||
OutputSchema: outputArtifact.Schema,
|
|
||||||
Mode: cfg.Mode,
|
|
||||||
Selector: cfg.Selector,
|
|
||||||
SelectedIDs: selector.IDs(),
|
|
||||||
AllowEmpty: cfg.AllowEmpty,
|
|
||||||
InputSegmentCount: inputSegmentCount,
|
|
||||||
RetainedSegmentCount: len(trimmed.OldToNewID),
|
|
||||||
RemovedSegmentCount: len(trimmed.RemovedIDs),
|
|
||||||
RemovedInputIDs: append([]int(nil), trimmed.RemovedIDs...),
|
|
||||||
OldToNewIDMapping: orderedIDMapping(trimmed.OldToNewID),
|
|
||||||
OverlapGroupsRecomputed: trimmed.OverlapGroupsRecomputed,
|
|
||||||
}
|
|
||||||
auditJSON, err := json.Marshal(audit)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("marshal trim audit report: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rpt := report.Report{
|
|
||||||
Metadata: report.Metadata{
|
|
||||||
Application: outputArtifact.Application(),
|
|
||||||
Version: outputArtifact.Version(),
|
|
||||||
InputReader: "trim-artifact",
|
|
||||||
InputFiles: []string{cfg.InputFile},
|
|
||||||
OutputModules: []string{"json"},
|
|
||||||
},
|
|
||||||
Events: []report.Event{
|
|
||||||
report.Info("trim", "trim", fmt.Sprintf("trimmed %d input segment(s) into %d output segment(s) with mode=%s", inputSegmentCount, outputArtifact.SegmentCount(), cfg.Mode)),
|
|
||||||
report.Info("trim", "trim-audit", string(auditJSON)),
|
|
||||||
report.Info("trim", "validate-output", fmt.Sprintf("validated %d output segment(s)", outputArtifact.SegmentCount())),
|
|
||||||
report.Info("output", "json", "wrote transcript JSON"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if err := report.WriteJSON(cfg.ReportFile, rpt); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.StringVar(&opts.InputFile, "input-file", "", "input seriatim transcript artifact JSON file")
|
flags.StringVar(&opts.InputFile, "input-file", "", "input seriatim transcript artifact JSON file")
|
||||||
flags.StringVar(&opts.OutputFile, "output-file", "", "output transcript JSON file")
|
addOutputFileFlag(cmd, &opts.OutputFile)
|
||||||
flags.StringVar(&opts.ReportFile, "report-file", "", "optional report JSON file")
|
addReportFileFlag(cmd, &opts.ReportFile)
|
||||||
flags.StringVar(&opts.Keep, "keep", "", "segment ID selector to keep (for example: 1-10,15)")
|
flags.StringVar(&opts.Keep, "keep", "", "segment ID selector to keep (for example: 1-10,15)")
|
||||||
flags.StringVar(&opts.Remove, "remove", "", "segment ID selector to remove (for example: 1-10,15)")
|
flags.StringVar(&opts.Remove, "remove", "", "segment ID selector to remove (for example: 1-10,15)")
|
||||||
flags.StringVar(&opts.OutputSchema, "output-schema", "", "optional output JSON schema override: seriatim-minimal, seriatim-intermediate, or seriatim-full")
|
addTrimOutputSchemaFlag(cmd, &opts.OutputSchema)
|
||||||
flags.BoolVar(&opts.AllowEmpty, "allow-empty", false, "allow trimming to an empty transcript")
|
flags.BoolVar(&opts.AllowEmpty, "allow-empty", false, "allow trimming to an empty transcript")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeOutputJSON(path string, value any) error {
|
|
||||||
file, err := os.Create(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
enc := json.NewEncoder(file)
|
|
||||||
enc.SetIndent("", " ")
|
|
||||||
return enc.Encode(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func orderedIDMapping(mapping map[int]int) []trimIDMapping {
|
|
||||||
keys := make([]int, 0, len(mapping))
|
|
||||||
for oldID := range mapping {
|
|
||||||
keys = append(keys, oldID)
|
|
||||||
}
|
|
||||||
sort.Ints(keys)
|
|
||||||
|
|
||||||
pairs := make([]trimIDMapping, 0, len(keys))
|
|
||||||
for _, oldID := range keys {
|
|
||||||
pairs = append(pairs, trimIDMapping{
|
|
||||||
OldID: oldID,
|
|
||||||
NewID: mapping[oldID],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return pairs
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -12,6 +12,29 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/seriatim/schema"
|
"gitea.maximumdirect.net/eric/seriatim/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type trimAuditReport struct {
|
||||||
|
Operation string `json:"operation"`
|
||||||
|
InputFile string `json:"input_file"`
|
||||||
|
OutputFile string `json:"output_file"`
|
||||||
|
InputSchema string `json:"input_schema"`
|
||||||
|
OutputSchema string `json:"output_schema"`
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
Selector string `json:"selector"`
|
||||||
|
SelectedIDs []int `json:"selected_ids"`
|
||||||
|
AllowEmpty bool `json:"allow_empty"`
|
||||||
|
InputSegmentCount int `json:"input_segment_count"`
|
||||||
|
RetainedSegmentCount int `json:"retained_segment_count"`
|
||||||
|
RemovedSegmentCount int `json:"removed_segment_count"`
|
||||||
|
RemovedInputIDs []int `json:"removed_input_ids"`
|
||||||
|
OldToNewIDMapping []trimIDMapping `json:"old_to_new_id_mapping"`
|
||||||
|
OverlapGroupsRecomputed bool `json:"overlap_groups_recomputed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type trimIDMapping struct {
|
||||||
|
OldID int `json:"old_id"`
|
||||||
|
NewID int `json:"new_id"`
|
||||||
|
}
|
||||||
|
|
||||||
func TestTrimKeepModeEndToEnd(t *testing.T) {
|
func TestTrimKeepModeEndToEnd(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
input := writeTrimFullFixture(t, dir, "input.json")
|
input := writeTrimFullFixture(t, dir, "input.json")
|
||||||
|
|||||||
@@ -160,13 +160,7 @@ func (r run) coalescedSegment(id int) model.Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func segmentRef(segment model.Segment) string {
|
func segmentRef(segment model.Segment) string {
|
||||||
if segment.SourceSegmentIndex != nil {
|
return model.SegmentReference(segment)
|
||||||
return fmt.Sprintf("%s#%d", segment.Source, *segment.SourceSegmentIndex)
|
|
||||||
}
|
|
||||||
if segment.SourceRef != "" {
|
|
||||||
return segment.SourceRef
|
|
||||||
}
|
|
||||||
return segment.Source
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isSkippableInterjection(segment model.Segment) bool {
|
func isSkippableInterjection(segment model.Segment) bool {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/seriatim/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -27,9 +29,9 @@ const (
|
|||||||
WordRunReorderWindowEnv = "SERIATIM_OVERLAP_WORD_RUN_REORDER_WINDOW"
|
WordRunReorderWindowEnv = "SERIATIM_OVERLAP_WORD_RUN_REORDER_WINDOW"
|
||||||
BackchannelMaxDurationEnv = "SERIATIM_BACKCHANNEL_MAX_DURATION"
|
BackchannelMaxDurationEnv = "SERIATIM_BACKCHANNEL_MAX_DURATION"
|
||||||
FillerMaxDurationEnv = "SERIATIM_FILLER_MAX_DURATION"
|
FillerMaxDurationEnv = "SERIATIM_FILLER_MAX_DURATION"
|
||||||
OutputSchemaMinimal = "seriatim-minimal"
|
OutputSchemaMinimal = schema.OutputSchemaMinimal
|
||||||
OutputSchemaIntermediate = "seriatim-intermediate"
|
OutputSchemaIntermediate = schema.OutputSchemaIntermediate
|
||||||
OutputSchemaFull = "seriatim-full"
|
OutputSchemaFull = schema.OutputSchemaFull
|
||||||
)
|
)
|
||||||
|
|
||||||
// MergeOptions captures raw CLI option values before validation.
|
// MergeOptions captures raw CLI option values before validation.
|
||||||
@@ -210,11 +212,8 @@ func NewMergeConfig(opts MergeOptions) (Config, error) {
|
|||||||
|
|
||||||
// NewTrimConfig validates raw trim options and returns normalized config.
|
// NewTrimConfig validates raw trim options and returns normalized config.
|
||||||
func NewTrimConfig(opts TrimOptions) (TrimConfig, error) {
|
func NewTrimConfig(opts TrimOptions) (TrimConfig, error) {
|
||||||
inputFile := filepath.Clean(strings.TrimSpace(opts.InputFile))
|
inputFile, err := normalizeSingleInputFile(opts.InputFile, "--input-file")
|
||||||
if strings.TrimSpace(opts.InputFile) == "" {
|
if err != nil {
|
||||||
return TrimConfig{}, errors.New("--input-file is required")
|
|
||||||
}
|
|
||||||
if err := requireFile(inputFile, "--input-file"); err != nil {
|
|
||||||
return TrimConfig{}, err
|
return TrimConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,12 +222,9 @@ func NewTrimConfig(opts TrimOptions) (TrimConfig, error) {
|
|||||||
return TrimConfig{}, err
|
return TrimConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
reportFile := ""
|
reportFile, err := normalizeOptionalOutputPath(opts.ReportFile, "--report-file")
|
||||||
if strings.TrimSpace(opts.ReportFile) != "" {
|
if err != nil {
|
||||||
reportFile, err = normalizeOutputPath(opts.ReportFile, "--report-file")
|
return TrimConfig{}, err
|
||||||
if err != nil {
|
|
||||||
return TrimConfig{}, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keep := strings.TrimSpace(opts.Keep)
|
keep := strings.TrimSpace(opts.Keep)
|
||||||
@@ -267,11 +263,8 @@ func NewTrimConfig(opts TrimOptions) (TrimConfig, error) {
|
|||||||
|
|
||||||
// NewNormalizeConfig validates raw normalize options and returns normalized config.
|
// NewNormalizeConfig validates raw normalize options and returns normalized config.
|
||||||
func NewNormalizeConfig(opts NormalizeOptions) (NormalizeConfig, error) {
|
func NewNormalizeConfig(opts NormalizeOptions) (NormalizeConfig, error) {
|
||||||
inputFile := filepath.Clean(strings.TrimSpace(opts.InputFile))
|
inputFile, err := normalizeSingleInputFile(opts.InputFile, "--input-file")
|
||||||
if strings.TrimSpace(opts.InputFile) == "" {
|
if err != nil {
|
||||||
return NormalizeConfig{}, errors.New("--input-file is required")
|
|
||||||
}
|
|
||||||
if err := requireFile(inputFile, "--input-file"); err != nil {
|
|
||||||
return NormalizeConfig{}, err
|
return NormalizeConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,12 +273,9 @@ func NewNormalizeConfig(opts NormalizeOptions) (NormalizeConfig, error) {
|
|||||||
return NormalizeConfig{}, err
|
return NormalizeConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
reportFile := ""
|
reportFile, err := normalizeOptionalOutputPath(opts.ReportFile, "--report-file")
|
||||||
if strings.TrimSpace(opts.ReportFile) != "" {
|
if err != nil {
|
||||||
reportFile, err = normalizeOutputPath(opts.ReportFile, "--report-file")
|
return NormalizeConfig{}, err
|
||||||
if err != nil {
|
|
||||||
return NormalizeConfig{}, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputSchema, err := resolveOutputSchema(opts.OutputSchema)
|
outputSchema, err := resolveOutputSchema(opts.OutputSchema)
|
||||||
@@ -332,12 +322,12 @@ func parseModuleList(value string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateOutputSchema(value string) error {
|
func validateOutputSchema(value string) error {
|
||||||
switch value {
|
if schema.ValidOutputSchemaName(value) {
|
||||||
case OutputSchemaMinimal, OutputSchemaIntermediate, OutputSchemaFull:
|
|
||||||
return nil
|
return nil
|
||||||
default:
|
|
||||||
return fmt.Errorf("--output-schema must be one of %q, %q, or %q", OutputSchemaMinimal, OutputSchemaIntermediate, OutputSchemaFull)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
names := schema.OutputSchemaNames()
|
||||||
|
return fmt.Errorf("--output-schema must be one of %q, %q, or %q", names[0], names[1], names[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveOutputSchema(value string) (string, error) {
|
func resolveOutputSchema(value string) (string, error) {
|
||||||
@@ -381,6 +371,26 @@ func normalizeInputFiles(paths []string) ([]string, error) {
|
|||||||
return normalized, nil
|
return normalized, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeSingleInputFile(path string, flag string) (string, error) {
|
||||||
|
path = strings.TrimSpace(path)
|
||||||
|
if path == "" {
|
||||||
|
return "", fmt.Errorf("%s is required", flag)
|
||||||
|
}
|
||||||
|
|
||||||
|
clean := filepath.Clean(path)
|
||||||
|
if err := requireFile(clean, flag); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return clean, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeOptionalOutputPath(path string, flag string) (string, error) {
|
||||||
|
if strings.TrimSpace(path) == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return normalizeOutputPath(path, flag)
|
||||||
|
}
|
||||||
|
|
||||||
func normalizeOutputPath(path string, flag string) (string, error) {
|
func normalizeOutputPath(path string, flag string) (string, error) {
|
||||||
path = strings.TrimSpace(path)
|
path = strings.TrimSpace(path)
|
||||||
if path == "" {
|
if path == "" {
|
||||||
|
|||||||
@@ -538,15 +538,9 @@ func TestCoalesceGapUsesValidOverride(t *testing.T) {
|
|||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
output := filepath.Join(dir, "merged.json")
|
output := filepath.Join(dir, "merged.json")
|
||||||
|
|
||||||
cfg, err := NewMergeConfig(MergeOptions{
|
opts := validMergeOptions(input, output)
|
||||||
InputFiles: []string{input},
|
opts.CoalesceGap = "1.5"
|
||||||
OutputFile: output,
|
cfg, err := NewMergeConfig(opts)
|
||||||
InputReader: DefaultInputReader,
|
|
||||||
OutputModules: DefaultOutputModules,
|
|
||||||
PreprocessingModules: DefaultPreprocessingModules,
|
|
||||||
PostprocessingModules: DefaultPostprocessingModules,
|
|
||||||
CoalesceGap: "1.5",
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("config failed: %v", err)
|
t.Fatalf("config failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -560,15 +554,9 @@ func TestCoalesceGapAllowsZero(t *testing.T) {
|
|||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
output := filepath.Join(dir, "merged.json")
|
output := filepath.Join(dir, "merged.json")
|
||||||
|
|
||||||
cfg, err := NewMergeConfig(MergeOptions{
|
opts := validMergeOptions(input, output)
|
||||||
InputFiles: []string{input},
|
opts.CoalesceGap = "0"
|
||||||
OutputFile: output,
|
cfg, err := NewMergeConfig(opts)
|
||||||
InputReader: DefaultInputReader,
|
|
||||||
OutputModules: DefaultOutputModules,
|
|
||||||
PreprocessingModules: DefaultPreprocessingModules,
|
|
||||||
PostprocessingModules: DefaultPostprocessingModules,
|
|
||||||
CoalesceGap: "0",
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("config failed: %v", err)
|
t.Fatalf("config failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -593,15 +581,9 @@ func TestCoalesceGapRejectsInvalidOverride(t *testing.T) {
|
|||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
output := filepath.Join(dir, "merged.json")
|
output := filepath.Join(dir, "merged.json")
|
||||||
|
|
||||||
_, err := NewMergeConfig(MergeOptions{
|
opts := validMergeOptions(input, output)
|
||||||
InputFiles: []string{input},
|
opts.CoalesceGap = test.value
|
||||||
OutputFile: output,
|
_, err := NewMergeConfig(opts)
|
||||||
InputReader: DefaultInputReader,
|
|
||||||
OutputModules: DefaultOutputModules,
|
|
||||||
PreprocessingModules: DefaultPreprocessingModules,
|
|
||||||
PostprocessingModules: DefaultPostprocessingModules,
|
|
||||||
CoalesceGap: test.value,
|
|
||||||
})
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error")
|
t.Fatal("expected error")
|
||||||
}
|
}
|
||||||
@@ -639,20 +621,16 @@ func TestNewTrimConfigRequiresExactlyOneSelectorFlag(t *testing.T) {
|
|||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
output := filepath.Join(dir, "trimmed.json")
|
output := filepath.Join(dir, "trimmed.json")
|
||||||
|
|
||||||
_, err := NewTrimConfig(TrimOptions{
|
opts := validTrimOptions(input, output)
|
||||||
InputFile: input,
|
opts.Keep = ""
|
||||||
OutputFile: output,
|
_, err := NewTrimConfig(opts)
|
||||||
})
|
|
||||||
if err == nil || !strings.Contains(err.Error(), "exactly one of --keep or --remove is required") {
|
if err == nil || !strings.Contains(err.Error(), "exactly one of --keep or --remove is required") {
|
||||||
t.Fatalf("expected missing selector error, got %v", err)
|
t.Fatalf("expected missing selector error, got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = NewTrimConfig(TrimOptions{
|
opts = validTrimOptions(input, output)
|
||||||
InputFile: input,
|
opts.Remove = "2"
|
||||||
OutputFile: output,
|
_, err = NewTrimConfig(opts)
|
||||||
Keep: "1",
|
|
||||||
Remove: "2",
|
|
||||||
})
|
|
||||||
if err == nil || !strings.Contains(err.Error(), "mutually exclusive") {
|
if err == nil || !strings.Contains(err.Error(), "mutually exclusive") {
|
||||||
t.Fatalf("expected mutually exclusive selector error, got %v", err)
|
t.Fatalf("expected mutually exclusive selector error, got %v", err)
|
||||||
}
|
}
|
||||||
@@ -664,14 +642,13 @@ func TestNewTrimConfigAcceptsOutputSchemaOverride(t *testing.T) {
|
|||||||
output := filepath.Join(dir, "trimmed.json")
|
output := filepath.Join(dir, "trimmed.json")
|
||||||
reportPath := filepath.Join(dir, "report.json")
|
reportPath := filepath.Join(dir, "report.json")
|
||||||
|
|
||||||
cfg, err := NewTrimConfig(TrimOptions{
|
opts := validTrimOptions(input, output)
|
||||||
InputFile: input,
|
opts.Keep = ""
|
||||||
OutputFile: output,
|
opts.Remove = "3-5"
|
||||||
ReportFile: reportPath,
|
opts.ReportFile = reportPath
|
||||||
Remove: "3-5",
|
opts.OutputSchema = OutputSchemaMinimal
|
||||||
OutputSchema: OutputSchemaMinimal,
|
opts.AllowEmpty = true
|
||||||
AllowEmpty: true,
|
cfg, err := NewTrimConfig(opts)
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("config failed: %v", err)
|
t.Fatalf("config failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -692,17 +669,30 @@ func TestNewTrimConfigAcceptsOutputSchemaOverride(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewTrimConfigTreatsWhitespaceReportFileAsOmitted(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
input := writeTempFile(t, dir, "input.json")
|
||||||
|
output := filepath.Join(dir, "trimmed.json")
|
||||||
|
|
||||||
|
opts := validTrimOptions(input, output)
|
||||||
|
opts.ReportFile = " \t "
|
||||||
|
cfg, err := NewTrimConfig(opts)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("config failed: %v", err)
|
||||||
|
}
|
||||||
|
if cfg.ReportFile != "" {
|
||||||
|
t.Fatalf("report file = %q, want empty", cfg.ReportFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewTrimConfigRejectsInvalidOutputSchemaOverride(t *testing.T) {
|
func TestNewTrimConfigRejectsInvalidOutputSchemaOverride(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
output := filepath.Join(dir, "trimmed.json")
|
output := filepath.Join(dir, "trimmed.json")
|
||||||
|
|
||||||
_, err := NewTrimConfig(TrimOptions{
|
opts := validTrimOptions(input, output)
|
||||||
InputFile: input,
|
opts.OutputSchema = "compact"
|
||||||
OutputFile: output,
|
_, err := NewTrimConfig(opts)
|
||||||
Keep: "1",
|
|
||||||
OutputSchema: "compact",
|
|
||||||
})
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected output schema validation error")
|
t.Fatal("expected output schema validation error")
|
||||||
}
|
}
|
||||||
@@ -731,10 +721,8 @@ func TestNewNormalizeConfigRequiresOutputFile(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
|
|
||||||
_, err := NewNormalizeConfig(NormalizeOptions{
|
opts := validNormalizeOptions(input, "")
|
||||||
InputFile: input,
|
_, err := NewNormalizeConfig(opts)
|
||||||
OutputModules: DefaultOutputModules,
|
|
||||||
})
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected output-file required error")
|
t.Fatal("expected output-file required error")
|
||||||
}
|
}
|
||||||
@@ -749,11 +737,8 @@ func TestNewNormalizeConfigResolvesOutputSchemaDefaultAndEnv(t *testing.T) {
|
|||||||
output := filepath.Join(dir, "normalized.json")
|
output := filepath.Join(dir, "normalized.json")
|
||||||
|
|
||||||
t.Setenv(OutputSchemaEnv, "")
|
t.Setenv(OutputSchemaEnv, "")
|
||||||
cfg, err := NewNormalizeConfig(NormalizeOptions{
|
opts := validNormalizeOptions(input, output)
|
||||||
InputFile: input,
|
cfg, err := NewNormalizeConfig(opts)
|
||||||
OutputFile: output,
|
|
||||||
OutputModules: DefaultOutputModules,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("config failed: %v", err)
|
t.Fatalf("config failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -762,11 +747,7 @@ func TestNewNormalizeConfigResolvesOutputSchemaDefaultAndEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Setenv(OutputSchemaEnv, OutputSchemaMinimal)
|
t.Setenv(OutputSchemaEnv, OutputSchemaMinimal)
|
||||||
cfg, err = NewNormalizeConfig(NormalizeOptions{
|
cfg, err = NewNormalizeConfig(opts)
|
||||||
InputFile: input,
|
|
||||||
OutputFile: output,
|
|
||||||
OutputModules: DefaultOutputModules,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("config failed: %v", err)
|
t.Fatalf("config failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -780,12 +761,9 @@ func TestNewNormalizeConfigRejectsInvalidOutputSchema(t *testing.T) {
|
|||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
output := filepath.Join(dir, "normalized.json")
|
output := filepath.Join(dir, "normalized.json")
|
||||||
|
|
||||||
_, err := NewNormalizeConfig(NormalizeOptions{
|
opts := validNormalizeOptions(input, output)
|
||||||
InputFile: input,
|
opts.OutputSchema = "compact"
|
||||||
OutputFile: output,
|
_, err := NewNormalizeConfig(opts)
|
||||||
OutputSchema: "compact",
|
|
||||||
OutputModules: DefaultOutputModules,
|
|
||||||
})
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected output schema error")
|
t.Fatal("expected output schema error")
|
||||||
}
|
}
|
||||||
@@ -799,11 +777,9 @@ func TestNewNormalizeConfigRejectsUnknownOutputModule(t *testing.T) {
|
|||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
output := filepath.Join(dir, "normalized.json")
|
output := filepath.Join(dir, "normalized.json")
|
||||||
|
|
||||||
_, err := NewNormalizeConfig(NormalizeOptions{
|
opts := validNormalizeOptions(input, output)
|
||||||
InputFile: input,
|
opts.OutputModules = "json,yaml"
|
||||||
OutputFile: output,
|
_, err := NewNormalizeConfig(opts)
|
||||||
OutputModules: "json,yaml",
|
|
||||||
})
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected output module error")
|
t.Fatal("expected output module error")
|
||||||
}
|
}
|
||||||
@@ -812,6 +788,22 @@ func TestNewNormalizeConfigRejectsUnknownOutputModule(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewNormalizeConfigTreatsWhitespaceReportFileAsOmitted(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
input := writeTempFile(t, dir, "input.json")
|
||||||
|
output := filepath.Join(dir, "normalized.json")
|
||||||
|
|
||||||
|
opts := validNormalizeOptions(input, output)
|
||||||
|
opts.ReportFile = "\n\t "
|
||||||
|
cfg, err := NewNormalizeConfig(opts)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("config failed: %v", err)
|
||||||
|
}
|
||||||
|
if cfg.ReportFile != "" {
|
||||||
|
t.Fatalf("report file = %q, want empty", cfg.ReportFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func assertPositiveFloatEnvValidation(t *testing.T, envName string) {
|
func assertPositiveFloatEnvValidation(t *testing.T, envName string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -832,14 +824,7 @@ func assertPositiveFloatEnvValidation(t *testing.T, envName string) {
|
|||||||
input := writeTempFile(t, dir, "input.json")
|
input := writeTempFile(t, dir, "input.json")
|
||||||
output := filepath.Join(dir, "merged.json")
|
output := filepath.Join(dir, "merged.json")
|
||||||
|
|
||||||
_, err := NewMergeConfig(MergeOptions{
|
_, err := NewMergeConfig(validMergeOptions(input, output))
|
||||||
InputFiles: []string{input},
|
|
||||||
OutputFile: output,
|
|
||||||
InputReader: DefaultInputReader,
|
|
||||||
OutputModules: DefaultOutputModules,
|
|
||||||
PreprocessingModules: DefaultPreprocessingModules,
|
|
||||||
PostprocessingModules: DefaultPostprocessingModules,
|
|
||||||
})
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error")
|
t.Fatal("expected error")
|
||||||
}
|
}
|
||||||
@@ -850,6 +835,33 @@ func assertPositiveFloatEnvValidation(t *testing.T, envName string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validMergeOptions(inputFile string, outputFile string) MergeOptions {
|
||||||
|
return MergeOptions{
|
||||||
|
InputFiles: []string{inputFile},
|
||||||
|
OutputFile: outputFile,
|
||||||
|
InputReader: DefaultInputReader,
|
||||||
|
OutputModules: DefaultOutputModules,
|
||||||
|
PreprocessingModules: DefaultPreprocessingModules,
|
||||||
|
PostprocessingModules: DefaultPostprocessingModules,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func validTrimOptions(inputFile string, outputFile string) TrimOptions {
|
||||||
|
return TrimOptions{
|
||||||
|
InputFile: inputFile,
|
||||||
|
OutputFile: outputFile,
|
||||||
|
Keep: "1",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func validNormalizeOptions(inputFile string, outputFile string) NormalizeOptions {
|
||||||
|
return NormalizeOptions{
|
||||||
|
InputFile: inputFile,
|
||||||
|
OutputFile: outputFile,
|
||||||
|
OutputModules: DefaultOutputModules,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func writeTempFile(t *testing.T, dir string, name string) string {
|
func writeTempFile(t *testing.T, dir string, name string) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
|||||||
28
internal/jsonfile/jsonfile.go
Normal file
28
internal/jsonfile/jsonfile.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package jsonfile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Write creates or truncates path and writes deterministic indented JSON.
|
||||||
|
func Write(path string, value any) (err error) {
|
||||||
|
file, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("create %q: %w", path, err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
closeErr := file.Close()
|
||||||
|
if err == nil && closeErr != nil {
|
||||||
|
err = fmt.Errorf("close %q: %w", path, closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
encoder := json.NewEncoder(file)
|
||||||
|
encoder.SetIndent("", " ")
|
||||||
|
if err := encoder.Encode(value); err != nil {
|
||||||
|
return fmt.Errorf("encode %q: %w", path, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
69
internal/jsonfile/jsonfile_test.go
Normal file
69
internal/jsonfile/jsonfile_test.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package jsonfile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWriteFormatsWithTwoSpaceIndentAndTrailingNewline(t *testing.T) {
|
||||||
|
type payload struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Items []int `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(t.TempDir(), "out.json")
|
||||||
|
value := payload{
|
||||||
|
Name: "alpha",
|
||||||
|
Items: []int{1, 2},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := Write(path, value); err != nil {
|
||||||
|
t.Fatalf("write failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("read output: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got := string(data)
|
||||||
|
want := "{\n \"name\": \"alpha\",\n \"items\": [\n 1,\n 2\n ]\n}\n"
|
||||||
|
if got != want {
|
||||||
|
t.Fatalf("formatted JSON mismatch\nwant:\n%s\ngot:\n%s", want, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWriteProducesValidJSON(t *testing.T) {
|
||||||
|
path := filepath.Join(t.TempDir(), "out.json")
|
||||||
|
|
||||||
|
value := map[string]any{
|
||||||
|
"application": "seriatim",
|
||||||
|
"segments": []map[string]any{
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"speaker": "A",
|
||||||
|
"text": "hello",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := Write(path, value); err != nil {
|
||||||
|
t.Fatalf("write failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("read output: %v", err)
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(string(data), "\n") {
|
||||||
|
t.Fatalf("output missing trailing newline: %q", string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
var decoded map[string]any
|
||||||
|
if err := json.Unmarshal(data, &decoded); err != nil {
|
||||||
|
t.Fatalf("output is not valid JSON: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// RawTranscript is a loaded input document before canonical normalization.
|
// RawTranscript is a loaded input document before canonical normalization.
|
||||||
type RawTranscript struct {
|
type RawTranscript struct {
|
||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
@@ -61,6 +63,17 @@ type Segment struct {
|
|||||||
OverlapGroupID int `json:"overlap_group_id,omitempty"`
|
OverlapGroupID int `json:"overlap_group_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SegmentReference returns the best available external reference for a segment.
|
||||||
|
func SegmentReference(segment Segment) string {
|
||||||
|
if segment.Source != "" && segment.SourceSegmentIndex != nil {
|
||||||
|
return fmt.Sprintf("%s#%d", segment.Source, *segment.SourceSegmentIndex)
|
||||||
|
}
|
||||||
|
if segment.SourceRef != "" {
|
||||||
|
return segment.SourceRef
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// Word preserves optional word-level timing data.
|
// Word preserves optional word-level timing data.
|
||||||
type Word struct {
|
type Word struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
|
|||||||
41
internal/model/model_test.go
Normal file
41
internal/model/model_test.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestSegmentReferenceUsesSourceAndIndexWhenAvailable(t *testing.T) {
|
||||||
|
index := 3
|
||||||
|
segment := Segment{
|
||||||
|
Source: "input.json",
|
||||||
|
SourceSegmentIndex: &index,
|
||||||
|
SourceRef: "word-run:1:2:3",
|
||||||
|
}
|
||||||
|
|
||||||
|
got := SegmentReference(segment)
|
||||||
|
want := "input.json#3"
|
||||||
|
if got != want {
|
||||||
|
t.Fatalf("reference = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSegmentReferenceFallsBackToSourceRef(t *testing.T) {
|
||||||
|
segment := Segment{
|
||||||
|
Source: "input.json",
|
||||||
|
SourceRef: "coalesce:2",
|
||||||
|
}
|
||||||
|
|
||||||
|
got := SegmentReference(segment)
|
||||||
|
want := "coalesce:2"
|
||||||
|
if got != want {
|
||||||
|
t.Fatalf("reference = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSegmentReferenceReturnsEmptyWhenNoReferenceFieldsPresent(t *testing.T) {
|
||||||
|
segment := Segment{
|
||||||
|
Source: "input.json",
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := SegmentReference(segment); got != "" {
|
||||||
|
t.Fatalf("reference = %q, want empty", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/artifact"
|
"gitea.maximumdirect.net/eric/seriatim/internal/artifact"
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/buildinfo"
|
"gitea.maximumdirect.net/eric/seriatim/internal/buildinfo"
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||||
|
"gitea.maximumdirect.net/eric/seriatim/internal/jsonfile"
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ func Run(ctx context.Context, cfg config.NormalizeConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := writeOutputJSON(cfg.OutputFile, built.Output); err != nil {
|
if err := jsonfile.Write(cfg.OutputFile, built.Output); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,18 +118,3 @@ func Run(ctx context.Context, cfg config.NormalizeConfig) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeOutputJSON(path string, value any) error {
|
|
||||||
file, err := os.Create(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
encoder := json.NewEncoder(file)
|
|
||||||
encoder.SetIndent("", " ")
|
|
||||||
if err := encoder.Encode(value); err != nil {
|
|
||||||
return fmt.Errorf("encode normalize output JSON: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package overlap
|
package overlap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/seriatim/internal/model"
|
"gitea.maximumdirect.net/eric/seriatim/internal/model"
|
||||||
@@ -121,13 +120,7 @@ func distinctSpeakers(segments []model.Segment, indices []int) []string {
|
|||||||
|
|
||||||
// SegmentRef returns the stable overlap reference for a segment.
|
// SegmentRef returns the stable overlap reference for a segment.
|
||||||
func SegmentRef(segment model.Segment) string {
|
func SegmentRef(segment model.Segment) string {
|
||||||
if segment.SourceSegmentIndex != nil {
|
return model.SegmentReference(segment)
|
||||||
return fmt.Sprintf("%s#%d", segment.Source, *segment.SourceSegmentIndex)
|
|
||||||
}
|
|
||||||
if segment.SourceRef != "" {
|
|
||||||
return segment.SourceRef
|
|
||||||
}
|
|
||||||
return segment.Source
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearExisting(in *model.MergedTranscript) {
|
func clearExisting(in *model.MergedTranscript) {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package report
|
package report
|
||||||
|
|
||||||
import (
|
import "gitea.maximumdirect.net/eric/seriatim/internal/jsonfile"
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Severity classifies report events.
|
// Severity classifies report events.
|
||||||
type Severity string
|
type Severity string
|
||||||
@@ -62,13 +59,5 @@ func Warning(stage string, module string, message string) Event {
|
|||||||
|
|
||||||
// WriteJSON writes a deterministic JSON report.
|
// WriteJSON writes a deterministic JSON report.
|
||||||
func WriteJSON(path string, rpt Report) error {
|
func WriteJSON(path string, rpt Report) error {
|
||||||
file, err := os.Create(path)
|
return jsonfile.Write(path, rpt)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
enc := json.NewEncoder(file)
|
|
||||||
enc.SetIndent("", " ")
|
|
||||||
return enc.Encode(rpt)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,54 +44,29 @@ type MinimalResult struct {
|
|||||||
RemovedIDs []int
|
RemovedIDs []int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type projection struct {
|
||||||
|
retainedIndexes []int
|
||||||
|
oldToNewID map[int]int
|
||||||
|
removedIDs []int
|
||||||
|
}
|
||||||
|
|
||||||
// Apply trims a full seriatim output transcript by segment ID.
|
// Apply trims a full seriatim output transcript by segment ID.
|
||||||
func Apply(input schema.Transcript, opts Options) (Result, error) {
|
func Apply(input schema.Transcript, opts Options) (Result, error) {
|
||||||
if err := validateMode(opts.Mode); err != nil {
|
|
||||||
return Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
selected := opts.Selector.IDs()
|
|
||||||
if len(selected) == 0 {
|
|
||||||
return Result{}, fmt.Errorf("selector cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
inputIDs := make([]int, len(input.Segments))
|
inputIDs := make([]int, len(input.Segments))
|
||||||
for index, segment := range input.Segments {
|
for index, segment := range input.Segments {
|
||||||
inputIDs[index] = segment.ID
|
inputIDs[index] = segment.ID
|
||||||
}
|
}
|
||||||
|
proj, err := projectSegmentIDs(inputIDs, opts)
|
||||||
idIndex, err := validateInputIDs(inputIDs)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Result{}, err
|
return Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSelectedIDsExist(selected, idIndex); err != nil {
|
kept := make([]schema.Segment, len(proj.retainedIndexes))
|
||||||
return Result{}, err
|
for outputIndex, inputIndex := range proj.retainedIndexes {
|
||||||
}
|
rewritten := copySegment(input.Segments[inputIndex])
|
||||||
|
rewritten.ID = outputIndex + 1
|
||||||
kept := make([]schema.Segment, 0, len(input.Segments))
|
|
||||||
removed := make([]int, 0, len(input.Segments))
|
|
||||||
oldToNew := make(map[int]int, len(input.Segments))
|
|
||||||
for _, segment := range input.Segments {
|
|
||||||
keep := opts.Mode == ModeKeep && opts.Selector.Contains(segment.ID)
|
|
||||||
if opts.Mode == ModeRemove {
|
|
||||||
keep = !opts.Selector.Contains(segment.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !keep {
|
|
||||||
removed = append(removed, segment.ID)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
rewritten := copySegment(segment)
|
|
||||||
rewritten.ID = len(kept) + 1
|
|
||||||
rewritten.OverlapGroupID = 0
|
rewritten.OverlapGroupID = 0
|
||||||
kept = append(kept, rewritten)
|
kept[outputIndex] = rewritten
|
||||||
oldToNew[segment.ID] = rewritten.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(kept) == 0 && !opts.AllowEmpty {
|
|
||||||
return Result{}, fmt.Errorf("trim operation produced an empty transcript; set AllowEmpty to true to permit this")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kept, groups := recomputeOverlapGroups(kept)
|
kept, groups := recomputeOverlapGroups(kept)
|
||||||
@@ -104,62 +79,35 @@ func Apply(input schema.Transcript, opts Options) (Result, error) {
|
|||||||
out.OverlapGroups = groups
|
out.OverlapGroups = groups
|
||||||
return Result{
|
return Result{
|
||||||
Transcript: out,
|
Transcript: out,
|
||||||
OldToNewID: oldToNew,
|
OldToNewID: proj.oldToNewID,
|
||||||
RemovedIDs: removed,
|
RemovedIDs: proj.removedIDs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyIntermediate trims an intermediate seriatim output transcript by
|
// ApplyIntermediate trims an intermediate seriatim output transcript by
|
||||||
// segment ID.
|
// segment ID.
|
||||||
func ApplyIntermediate(input schema.IntermediateTranscript, opts Options) (IntermediateResult, error) {
|
func ApplyIntermediate(input schema.IntermediateTranscript, opts Options) (IntermediateResult, error) {
|
||||||
if err := validateMode(opts.Mode); err != nil {
|
|
||||||
return IntermediateResult{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
selected := opts.Selector.IDs()
|
|
||||||
if len(selected) == 0 {
|
|
||||||
return IntermediateResult{}, fmt.Errorf("selector cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
inputIDs := make([]int, len(input.Segments))
|
inputIDs := make([]int, len(input.Segments))
|
||||||
for index, segment := range input.Segments {
|
for index, segment := range input.Segments {
|
||||||
inputIDs[index] = segment.ID
|
inputIDs[index] = segment.ID
|
||||||
}
|
}
|
||||||
idIndex, err := validateInputIDs(inputIDs)
|
proj, err := projectSegmentIDs(inputIDs, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return IntermediateResult{}, err
|
return IntermediateResult{}, err
|
||||||
}
|
}
|
||||||
if err := validateSelectedIDsExist(selected, idIndex); err != nil {
|
|
||||||
return IntermediateResult{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
kept := make([]schema.IntermediateSegment, 0, len(input.Segments))
|
|
||||||
removed := make([]int, 0, len(input.Segments))
|
|
||||||
oldToNew := make(map[int]int, len(input.Segments))
|
|
||||||
for _, segment := range input.Segments {
|
|
||||||
keep := opts.Mode == ModeKeep && opts.Selector.Contains(segment.ID)
|
|
||||||
if opts.Mode == ModeRemove {
|
|
||||||
keep = !opts.Selector.Contains(segment.ID)
|
|
||||||
}
|
|
||||||
if !keep {
|
|
||||||
removed = append(removed, segment.ID)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
kept := make([]schema.IntermediateSegment, len(proj.retainedIndexes))
|
||||||
|
for outputIndex, inputIndex := range proj.retainedIndexes {
|
||||||
|
segment := input.Segments[inputIndex]
|
||||||
rewritten := schema.IntermediateSegment{
|
rewritten := schema.IntermediateSegment{
|
||||||
ID: len(kept) + 1,
|
ID: outputIndex + 1,
|
||||||
Start: segment.Start,
|
Start: segment.Start,
|
||||||
End: segment.End,
|
End: segment.End,
|
||||||
Speaker: segment.Speaker,
|
Speaker: segment.Speaker,
|
||||||
Text: segment.Text,
|
Text: segment.Text,
|
||||||
Categories: append([]string(nil), segment.Categories...),
|
Categories: append([]string(nil), segment.Categories...),
|
||||||
}
|
}
|
||||||
kept = append(kept, rewritten)
|
kept[outputIndex] = rewritten
|
||||||
oldToNew[segment.ID] = rewritten.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(kept) == 0 && !opts.AllowEmpty {
|
|
||||||
return IntermediateResult{}, fmt.Errorf("trim operation produced an empty transcript; set AllowEmpty to true to permit this")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return IntermediateResult{
|
return IntermediateResult{
|
||||||
@@ -171,60 +119,33 @@ func ApplyIntermediate(input schema.IntermediateTranscript, opts Options) (Inter
|
|||||||
},
|
},
|
||||||
Segments: kept,
|
Segments: kept,
|
||||||
},
|
},
|
||||||
OldToNewID: oldToNew,
|
OldToNewID: proj.oldToNewID,
|
||||||
RemovedIDs: removed,
|
RemovedIDs: proj.removedIDs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyMinimal trims a minimal seriatim output transcript by segment ID.
|
// ApplyMinimal trims a minimal seriatim output transcript by segment ID.
|
||||||
func ApplyMinimal(input schema.MinimalTranscript, opts Options) (MinimalResult, error) {
|
func ApplyMinimal(input schema.MinimalTranscript, opts Options) (MinimalResult, error) {
|
||||||
if err := validateMode(opts.Mode); err != nil {
|
|
||||||
return MinimalResult{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
selected := opts.Selector.IDs()
|
|
||||||
if len(selected) == 0 {
|
|
||||||
return MinimalResult{}, fmt.Errorf("selector cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
inputIDs := make([]int, len(input.Segments))
|
inputIDs := make([]int, len(input.Segments))
|
||||||
for index, segment := range input.Segments {
|
for index, segment := range input.Segments {
|
||||||
inputIDs[index] = segment.ID
|
inputIDs[index] = segment.ID
|
||||||
}
|
}
|
||||||
idIndex, err := validateInputIDs(inputIDs)
|
proj, err := projectSegmentIDs(inputIDs, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MinimalResult{}, err
|
return MinimalResult{}, err
|
||||||
}
|
}
|
||||||
if err := validateSelectedIDsExist(selected, idIndex); err != nil {
|
|
||||||
return MinimalResult{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
kept := make([]schema.MinimalSegment, 0, len(input.Segments))
|
|
||||||
removed := make([]int, 0, len(input.Segments))
|
|
||||||
oldToNew := make(map[int]int, len(input.Segments))
|
|
||||||
for _, segment := range input.Segments {
|
|
||||||
keep := opts.Mode == ModeKeep && opts.Selector.Contains(segment.ID)
|
|
||||||
if opts.Mode == ModeRemove {
|
|
||||||
keep = !opts.Selector.Contains(segment.ID)
|
|
||||||
}
|
|
||||||
if !keep {
|
|
||||||
removed = append(removed, segment.ID)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
kept := make([]schema.MinimalSegment, len(proj.retainedIndexes))
|
||||||
|
for outputIndex, inputIndex := range proj.retainedIndexes {
|
||||||
|
segment := input.Segments[inputIndex]
|
||||||
rewritten := schema.MinimalSegment{
|
rewritten := schema.MinimalSegment{
|
||||||
ID: len(kept) + 1,
|
ID: outputIndex + 1,
|
||||||
Start: segment.Start,
|
Start: segment.Start,
|
||||||
End: segment.End,
|
End: segment.End,
|
||||||
Speaker: segment.Speaker,
|
Speaker: segment.Speaker,
|
||||||
Text: segment.Text,
|
Text: segment.Text,
|
||||||
}
|
}
|
||||||
kept = append(kept, rewritten)
|
kept[outputIndex] = rewritten
|
||||||
oldToNew[segment.ID] = rewritten.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(kept) == 0 && !opts.AllowEmpty {
|
|
||||||
return MinimalResult{}, fmt.Errorf("trim operation produced an empty transcript; set AllowEmpty to true to permit this")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return MinimalResult{
|
return MinimalResult{
|
||||||
@@ -236,11 +157,53 @@ func ApplyMinimal(input schema.MinimalTranscript, opts Options) (MinimalResult,
|
|||||||
},
|
},
|
||||||
Segments: kept,
|
Segments: kept,
|
||||||
},
|
},
|
||||||
OldToNewID: oldToNew,
|
OldToNewID: proj.oldToNewID,
|
||||||
RemovedIDs: removed,
|
RemovedIDs: proj.removedIDs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func projectSegmentIDs(ids []int, opts Options) (projection, error) {
|
||||||
|
if err := validateMode(opts.Mode); err != nil {
|
||||||
|
return projection{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
selected := opts.Selector.IDs()
|
||||||
|
if len(selected) == 0 {
|
||||||
|
return projection{}, fmt.Errorf("selector cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
idIndex, err := validateInputIDs(ids)
|
||||||
|
if err != nil {
|
||||||
|
return projection{}, err
|
||||||
|
}
|
||||||
|
if err := validateSelectedIDsExist(selected, idIndex); err != nil {
|
||||||
|
return projection{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := projection{
|
||||||
|
retainedIndexes: make([]int, 0, len(ids)),
|
||||||
|
oldToNewID: make(map[int]int, len(ids)),
|
||||||
|
removedIDs: make([]int, 0, len(ids)),
|
||||||
|
}
|
||||||
|
for index, id := range ids {
|
||||||
|
keep := opts.Mode == ModeKeep && opts.Selector.Contains(id)
|
||||||
|
if opts.Mode == ModeRemove {
|
||||||
|
keep = !opts.Selector.Contains(id)
|
||||||
|
}
|
||||||
|
if !keep {
|
||||||
|
result.removedIDs = append(result.removedIDs, id)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result.retainedIndexes = append(result.retainedIndexes, index)
|
||||||
|
result.oldToNewID[id] = len(result.retainedIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result.retainedIndexes) == 0 && !opts.AllowEmpty {
|
||||||
|
return projection{}, fmt.Errorf("trim operation produced an empty transcript; set AllowEmpty to true to permit this")
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func validateMode(mode Mode) error {
|
func validateMode(mode Mode) error {
|
||||||
switch mode {
|
switch mode {
|
||||||
case ModeKeep, ModeRemove:
|
case ModeKeep, ModeRemove:
|
||||||
|
|||||||
@@ -399,6 +399,106 @@ func TestApplyMinimalDoesNotIncludeOverlapGroups(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApplySelectorPolicyIsSharedAcrossSchemas(t *testing.T) {
|
||||||
|
type testCase struct {
|
||||||
|
name string
|
||||||
|
opts Options
|
||||||
|
wantTexts []string
|
||||||
|
wantOldToNew map[int]int
|
||||||
|
wantRemoved []int
|
||||||
|
wantSegmentCount int
|
||||||
|
wantErrorSubstring string
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := []testCase{
|
||||||
|
{
|
||||||
|
name: "keep preserves input order regardless of selector order",
|
||||||
|
opts: Options{Mode: ModeKeep, Selector: mustParseSelector(t, "4,1,3")},
|
||||||
|
wantTexts: []string{"alpha", "gamma", "delta"},
|
||||||
|
wantOldToNew: map[int]int{1: 1, 3: 2, 4: 3},
|
||||||
|
wantRemoved: []int{2},
|
||||||
|
wantSegmentCount: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "remove reports deterministic renumbering metadata",
|
||||||
|
opts: Options{Mode: ModeRemove, Selector: mustParseSelector(t, "2,4")},
|
||||||
|
wantTexts: []string{"alpha", "gamma"},
|
||||||
|
wantOldToNew: map[int]int{1: 1, 3: 2},
|
||||||
|
wantRemoved: []int{2, 4},
|
||||||
|
wantSegmentCount: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing selected id returns error",
|
||||||
|
opts: Options{Mode: ModeKeep, Selector: mustParseSelector(t, "9")},
|
||||||
|
wantErrorSubstring: "does not exist",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty selector returns error",
|
||||||
|
opts: Options{Mode: ModeKeep, Selector: Selector{}},
|
||||||
|
wantErrorSubstring: "selector cannot be empty",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid mode returns error",
|
||||||
|
opts: Options{Mode: Mode("bad"), Selector: mustParseSelector(t, "1")},
|
||||||
|
wantErrorSubstring: `invalid trim mode "bad"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty output blocked when allow empty is false",
|
||||||
|
opts: Options{Mode: ModeRemove, Selector: mustParseSelector(t, "1-4")},
|
||||||
|
wantErrorSubstring: "empty transcript",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty output allowed when allow empty is true",
|
||||||
|
opts: Options{Mode: ModeRemove, Selector: mustParseSelector(t, "1-4"), AllowEmpty: true},
|
||||||
|
wantTexts: []string{},
|
||||||
|
wantOldToNew: map[int]int{},
|
||||||
|
wantRemoved: []int{1, 2, 3, 4},
|
||||||
|
wantSegmentCount: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range cases {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
fullInput := fullTranscriptFixture()
|
||||||
|
intermediateInput := intermediateFixture()
|
||||||
|
minimalInput := minimalFixture()
|
||||||
|
|
||||||
|
fullResult, fullErr := Apply(fullInput, test.opts)
|
||||||
|
intermediateResult, intermediateErr := ApplyIntermediate(intermediateInput, test.opts)
|
||||||
|
minimalResult, minimalErr := ApplyMinimal(minimalInput, test.opts)
|
||||||
|
|
||||||
|
if test.wantErrorSubstring != "" {
|
||||||
|
assertErrorContains(t, fullErr, test.wantErrorSubstring)
|
||||||
|
assertErrorContains(t, intermediateErr, test.wantErrorSubstring)
|
||||||
|
assertErrorContains(t, minimalErr, test.wantErrorSubstring)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if fullErr != nil {
|
||||||
|
t.Fatalf("apply full failed: %v", fullErr)
|
||||||
|
}
|
||||||
|
if intermediateErr != nil {
|
||||||
|
t.Fatalf("apply intermediate failed: %v", intermediateErr)
|
||||||
|
}
|
||||||
|
if minimalErr != nil {
|
||||||
|
t.Fatalf("apply minimal failed: %v", minimalErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
assertIntSlice(t, extractFullIDs(fullResult.Transcript.Segments), extractSequentialIDs(test.wantSegmentCount))
|
||||||
|
assertIntSlice(t, extractIntermediateIDs(intermediateResult.Transcript.Segments), extractSequentialIDs(test.wantSegmentCount))
|
||||||
|
assertIntSlice(t, extractMinimalIDs(minimalResult.Transcript.Segments), extractSequentialIDs(test.wantSegmentCount))
|
||||||
|
assertStringSlice(t, extractFullTexts(fullResult.Transcript.Segments), test.wantTexts)
|
||||||
|
assertStringSlice(t, extractIntermediateTexts(intermediateResult.Transcript.Segments), test.wantTexts)
|
||||||
|
assertStringSlice(t, extractMinimalTexts(minimalResult.Transcript.Segments), test.wantTexts)
|
||||||
|
assertIntMap(t, fullResult.OldToNewID, test.wantOldToNew)
|
||||||
|
assertIntMap(t, intermediateResult.OldToNewID, test.wantOldToNew)
|
||||||
|
assertIntMap(t, minimalResult.OldToNewID, test.wantOldToNew)
|
||||||
|
assertIntSlice(t, fullResult.RemovedIDs, test.wantRemoved)
|
||||||
|
assertIntSlice(t, intermediateResult.RemovedIDs, test.wantRemoved)
|
||||||
|
assertIntSlice(t, minimalResult.RemovedIDs, test.wantRemoved)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestApplyOutputInvariantsValidAfterRenumberAndOverlapRecompute(t *testing.T) {
|
func TestApplyOutputInvariantsValidAfterRenumberAndOverlapRecompute(t *testing.T) {
|
||||||
input := overlapTranscriptFixture()
|
input := overlapTranscriptFixture()
|
||||||
selector := mustParseSelector(t, "2,1")
|
selector := mustParseSelector(t, "2,1")
|
||||||
@@ -666,3 +766,108 @@ func equalStringSlices(got []string, want []string) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func assertErrorContains(t *testing.T, err error, substring string) {
|
||||||
|
t.Helper()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected error containing %q", substring)
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), substring) {
|
||||||
|
t.Fatalf("error %q does not contain %q", err.Error(), substring)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertStringSlice(t *testing.T, got []string, want []string) {
|
||||||
|
t.Helper()
|
||||||
|
if !equalStringSlices(got, want) {
|
||||||
|
t.Fatalf("slice = %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractSequentialIDs(count int) []int {
|
||||||
|
ids := make([]int, count)
|
||||||
|
for index := range ids {
|
||||||
|
ids[index] = index + 1
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractFullIDs(segments []schema.Segment) []int {
|
||||||
|
ids := make([]int, len(segments))
|
||||||
|
for index, segment := range segments {
|
||||||
|
ids[index] = segment.ID
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractIntermediateIDs(segments []schema.IntermediateSegment) []int {
|
||||||
|
ids := make([]int, len(segments))
|
||||||
|
for index, segment := range segments {
|
||||||
|
ids[index] = segment.ID
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractMinimalIDs(segments []schema.MinimalSegment) []int {
|
||||||
|
ids := make([]int, len(segments))
|
||||||
|
for index, segment := range segments {
|
||||||
|
ids[index] = segment.ID
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractFullTexts(segments []schema.Segment) []string {
|
||||||
|
texts := make([]string, len(segments))
|
||||||
|
for index, segment := range segments {
|
||||||
|
texts[index] = segment.Text
|
||||||
|
}
|
||||||
|
return texts
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractIntermediateTexts(segments []schema.IntermediateSegment) []string {
|
||||||
|
texts := make([]string, len(segments))
|
||||||
|
for index, segment := range segments {
|
||||||
|
texts[index] = segment.Text
|
||||||
|
}
|
||||||
|
return texts
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractMinimalTexts(segments []schema.MinimalSegment) []string {
|
||||||
|
texts := make([]string, len(segments))
|
||||||
|
for index, segment := range segments {
|
||||||
|
texts[index] = segment.Text
|
||||||
|
}
|
||||||
|
return texts
|
||||||
|
}
|
||||||
|
|
||||||
|
func intermediateFixture() schema.IntermediateTranscript {
|
||||||
|
return schema.IntermediateTranscript{
|
||||||
|
Metadata: schema.IntermediateMetadata{
|
||||||
|
Application: "seriatim",
|
||||||
|
Version: "v-test",
|
||||||
|
OutputSchema: schema.OutputSchemaIntermediate,
|
||||||
|
},
|
||||||
|
Segments: []schema.IntermediateSegment{
|
||||||
|
{ID: 1, Start: 1, End: 2, Speaker: "Alice", Text: "alpha", Categories: []string{"word-run"}},
|
||||||
|
{ID: 2, Start: 2, End: 3, Speaker: "Bob", Text: "beta", Categories: []string{"filler", "backchannel"}},
|
||||||
|
{ID: 3, Start: 3, End: 4, Speaker: "Carol", Text: "gamma", Categories: []string{"normal"}},
|
||||||
|
{ID: 4, Start: 4, End: 5, Speaker: "Dan", Text: "delta", Categories: []string{"normal"}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func minimalFixture() schema.MinimalTranscript {
|
||||||
|
return schema.MinimalTranscript{
|
||||||
|
Metadata: schema.MinimalMetadata{
|
||||||
|
Application: "seriatim",
|
||||||
|
Version: "v-test",
|
||||||
|
OutputSchema: schema.OutputSchemaMinimal,
|
||||||
|
},
|
||||||
|
Segments: []schema.MinimalSegment{
|
||||||
|
{ID: 1, Start: 1, End: 2, Speaker: "Alice", Text: "alpha"},
|
||||||
|
{ID: 2, Start: 2, End: 3, Speaker: "Bob", Text: "beta"},
|
||||||
|
{ID: 3, Start: 3, End: 4, Speaker: "Carol", Text: "gamma"},
|
||||||
|
{ID: 4, Start: 4, End: 5, Speaker: "Dan", Text: "delta"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SchemaMinimal = "seriatim-minimal"
|
SchemaMinimal = schema.OutputSchemaMinimal
|
||||||
SchemaIntermediate = "seriatim-intermediate"
|
SchemaIntermediate = schema.OutputSchemaIntermediate
|
||||||
SchemaFull = "seriatim-full"
|
SchemaFull = schema.OutputSchemaFull
|
||||||
)
|
)
|
||||||
|
|
||||||
// Artifact stores a parsed seriatim output artifact of one supported schema.
|
// Artifact stores a parsed seriatim output artifact of one supported schema.
|
||||||
@@ -73,20 +73,23 @@ func ParseArtifactJSON(data []byte) (Artifact, error) {
|
|||||||
func ValidateArtifact(artifact Artifact) error {
|
func ValidateArtifact(artifact Artifact) error {
|
||||||
switch artifact.Schema {
|
switch artifact.Schema {
|
||||||
case SchemaFull:
|
case SchemaFull:
|
||||||
if artifact.Full == nil {
|
payload, err := artifact.fullPayload()
|
||||||
return fmt.Errorf("full artifact payload is missing")
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return schema.ValidateTranscript(*artifact.Full)
|
return schema.ValidateTranscript(*payload)
|
||||||
case SchemaIntermediate:
|
case SchemaIntermediate:
|
||||||
if artifact.Intermediate == nil {
|
payload, err := artifact.intermediatePayload()
|
||||||
return fmt.Errorf("intermediate artifact payload is missing")
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return schema.ValidateIntermediateTranscript(*artifact.Intermediate)
|
return schema.ValidateIntermediateTranscript(*payload)
|
||||||
case SchemaMinimal:
|
case SchemaMinimal:
|
||||||
if artifact.Minimal == nil {
|
payload, err := artifact.minimalPayload()
|
||||||
return fmt.Errorf("minimal artifact payload is missing")
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return schema.ValidateMinimalTranscript(*artifact.Minimal)
|
return schema.ValidateMinimalTranscript(*payload)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported artifact schema %q", artifact.Schema)
|
return fmt.Errorf("unsupported artifact schema %q", artifact.Schema)
|
||||||
}
|
}
|
||||||
@@ -188,10 +191,11 @@ func (artifact Artifact) Version() string {
|
|||||||
func ApplyArtifact(input Artifact, opts Options) (ApplyArtifactResult, error) {
|
func ApplyArtifact(input Artifact, opts Options) (ApplyArtifactResult, error) {
|
||||||
switch input.Schema {
|
switch input.Schema {
|
||||||
case SchemaFull:
|
case SchemaFull:
|
||||||
if input.Full == nil {
|
payload, err := input.fullPayload()
|
||||||
return ApplyArtifactResult{}, fmt.Errorf("full artifact payload is missing")
|
if err != nil {
|
||||||
|
return ApplyArtifactResult{}, err
|
||||||
}
|
}
|
||||||
result, err := Apply(*input.Full, opts)
|
result, err := Apply(*payload, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ApplyArtifactResult{}, err
|
return ApplyArtifactResult{}, err
|
||||||
}
|
}
|
||||||
@@ -206,10 +210,11 @@ func ApplyArtifact(input Artifact, opts Options) (ApplyArtifactResult, error) {
|
|||||||
OverlapGroupsRecomputed: true,
|
OverlapGroupsRecomputed: true,
|
||||||
}, nil
|
}, nil
|
||||||
case SchemaIntermediate:
|
case SchemaIntermediate:
|
||||||
if input.Intermediate == nil {
|
payload, err := input.intermediatePayload()
|
||||||
return ApplyArtifactResult{}, fmt.Errorf("intermediate artifact payload is missing")
|
if err != nil {
|
||||||
|
return ApplyArtifactResult{}, err
|
||||||
}
|
}
|
||||||
result, err := ApplyIntermediate(*input.Intermediate, opts)
|
result, err := ApplyIntermediate(*payload, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ApplyArtifactResult{}, err
|
return ApplyArtifactResult{}, err
|
||||||
}
|
}
|
||||||
@@ -224,10 +229,11 @@ func ApplyArtifact(input Artifact, opts Options) (ApplyArtifactResult, error) {
|
|||||||
OverlapGroupsRecomputed: false,
|
OverlapGroupsRecomputed: false,
|
||||||
}, nil
|
}, nil
|
||||||
case SchemaMinimal:
|
case SchemaMinimal:
|
||||||
if input.Minimal == nil {
|
payload, err := input.minimalPayload()
|
||||||
return ApplyArtifactResult{}, fmt.Errorf("minimal artifact payload is missing")
|
if err != nil {
|
||||||
|
return ApplyArtifactResult{}, err
|
||||||
}
|
}
|
||||||
result, err := ApplyMinimal(*input.Minimal, opts)
|
result, err := ApplyMinimal(*payload, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ApplyArtifactResult{}, err
|
return ApplyArtifactResult{}, err
|
||||||
}
|
}
|
||||||
@@ -254,18 +260,19 @@ func ConvertArtifact(input Artifact, outputSchema string) (Artifact, error) {
|
|||||||
|
|
||||||
switch input.Schema {
|
switch input.Schema {
|
||||||
case SchemaFull:
|
case SchemaFull:
|
||||||
if input.Full == nil {
|
payload, err := input.fullPayload()
|
||||||
return Artifact{}, fmt.Errorf("full artifact payload is missing")
|
if err != nil {
|
||||||
|
return Artifact{}, err
|
||||||
}
|
}
|
||||||
switch outputSchema {
|
switch outputSchema {
|
||||||
case SchemaIntermediate:
|
case SchemaIntermediate:
|
||||||
out := intermediateFromFull(*input.Full)
|
out := intermediateFromFull(*payload)
|
||||||
return Artifact{
|
return Artifact{
|
||||||
Schema: SchemaIntermediate,
|
Schema: SchemaIntermediate,
|
||||||
Intermediate: &out,
|
Intermediate: &out,
|
||||||
}, nil
|
}, nil
|
||||||
case SchemaMinimal:
|
case SchemaMinimal:
|
||||||
out := minimalFromFull(*input.Full)
|
out := minimalFromFull(*payload)
|
||||||
return Artifact{
|
return Artifact{
|
||||||
Schema: SchemaMinimal,
|
Schema: SchemaMinimal,
|
||||||
Minimal: &out,
|
Minimal: &out,
|
||||||
@@ -274,12 +281,13 @@ func ConvertArtifact(input Artifact, outputSchema string) (Artifact, error) {
|
|||||||
return Artifact{}, fmt.Errorf("unsupported output schema %q", outputSchema)
|
return Artifact{}, fmt.Errorf("unsupported output schema %q", outputSchema)
|
||||||
}
|
}
|
||||||
case SchemaIntermediate:
|
case SchemaIntermediate:
|
||||||
if input.Intermediate == nil {
|
payload, err := input.intermediatePayload()
|
||||||
return Artifact{}, fmt.Errorf("intermediate artifact payload is missing")
|
if err != nil {
|
||||||
|
return Artifact{}, err
|
||||||
}
|
}
|
||||||
switch outputSchema {
|
switch outputSchema {
|
||||||
case SchemaMinimal:
|
case SchemaMinimal:
|
||||||
out := minimalFromIntermediate(*input.Intermediate)
|
out := minimalFromIntermediate(*payload)
|
||||||
return Artifact{
|
return Artifact{
|
||||||
Schema: SchemaMinimal,
|
Schema: SchemaMinimal,
|
||||||
Minimal: &out,
|
Minimal: &out,
|
||||||
@@ -290,12 +298,13 @@ func ConvertArtifact(input Artifact, outputSchema string) (Artifact, error) {
|
|||||||
return Artifact{}, fmt.Errorf("unsupported output schema %q", outputSchema)
|
return Artifact{}, fmt.Errorf("unsupported output schema %q", outputSchema)
|
||||||
}
|
}
|
||||||
case SchemaMinimal:
|
case SchemaMinimal:
|
||||||
if input.Minimal == nil {
|
payload, err := input.minimalPayload()
|
||||||
return Artifact{}, fmt.Errorf("minimal artifact payload is missing")
|
if err != nil {
|
||||||
|
return Artifact{}, err
|
||||||
}
|
}
|
||||||
switch outputSchema {
|
switch outputSchema {
|
||||||
case SchemaIntermediate:
|
case SchemaIntermediate:
|
||||||
out := intermediateFromMinimal(*input.Minimal)
|
out := intermediateFromMinimal(*payload)
|
||||||
return Artifact{
|
return Artifact{
|
||||||
Schema: SchemaIntermediate,
|
Schema: SchemaIntermediate,
|
||||||
Intermediate: &out,
|
Intermediate: &out,
|
||||||
@@ -310,6 +319,27 @@ func ConvertArtifact(input Artifact, outputSchema string) (Artifact, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (artifact Artifact) fullPayload() (*schema.Transcript, error) {
|
||||||
|
if artifact.Full == nil {
|
||||||
|
return nil, fmt.Errorf("full artifact payload is missing")
|
||||||
|
}
|
||||||
|
return artifact.Full, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (artifact Artifact) intermediatePayload() (*schema.IntermediateTranscript, error) {
|
||||||
|
if artifact.Intermediate == nil {
|
||||||
|
return nil, fmt.Errorf("intermediate artifact payload is missing")
|
||||||
|
}
|
||||||
|
return artifact.Intermediate, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (artifact Artifact) minimalPayload() (*schema.MinimalTranscript, error) {
|
||||||
|
if artifact.Minimal == nil {
|
||||||
|
return nil, fmt.Errorf("minimal artifact payload is missing")
|
||||||
|
}
|
||||||
|
return artifact.Minimal, nil
|
||||||
|
}
|
||||||
|
|
||||||
func intermediateFromFull(input schema.Transcript) schema.IntermediateTranscript {
|
func intermediateFromFull(input schema.Transcript) schema.IntermediateTranscript {
|
||||||
segments := make([]schema.IntermediateSegment, len(input.Segments))
|
segments := make([]schema.IntermediateSegment, len(input.Segments))
|
||||||
for index, segment := range input.Segments {
|
for index, segment := range input.Segments {
|
||||||
|
|||||||
@@ -128,6 +128,61 @@ func TestConvertArtifactMinimalToFullFails(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateArtifactRejectsMissingPayloads(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
artifact Artifact
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "full",
|
||||||
|
artifact: Artifact{Schema: SchemaFull},
|
||||||
|
want: "full artifact payload is missing",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "intermediate",
|
||||||
|
artifact: Artifact{Schema: SchemaIntermediate},
|
||||||
|
want: "intermediate artifact payload is missing",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "minimal",
|
||||||
|
artifact: Artifact{Schema: SchemaMinimal},
|
||||||
|
want: "minimal artifact payload is missing",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
err := ValidateArtifact(test.artifact)
|
||||||
|
assertErrorContains(t, err, test.want)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyArtifactRejectsMissingPayload(t *testing.T) {
|
||||||
|
_, err := ApplyArtifact(Artifact{Schema: SchemaFull}, Options{})
|
||||||
|
assertErrorContains(t, err, "full artifact payload is missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConvertArtifactRejectsMissingPayloadWhenConversionRequested(t *testing.T) {
|
||||||
|
_, err := ConvertArtifact(Artifact{Schema: SchemaFull}, SchemaMinimal)
|
||||||
|
assertErrorContains(t, err, "full artifact payload is missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConvertArtifactSameSchemaDoesNotRequirePayload(t *testing.T) {
|
||||||
|
artifact := Artifact{Schema: SchemaFull}
|
||||||
|
converted, err := ConvertArtifact(artifact, SchemaFull)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("convert failed: %v", err)
|
||||||
|
}
|
||||||
|
if converted.Schema != SchemaFull {
|
||||||
|
t.Fatalf("schema = %q, want %q", converted.Schema, SchemaFull)
|
||||||
|
}
|
||||||
|
if converted.Full != nil {
|
||||||
|
t.Fatalf("full payload = %#v, want nil", converted.Full)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func mustMarshalJSON(t *testing.T, value any) []byte {
|
func mustMarshalJSON(t *testing.T, value any) []byte {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
data, err := json.Marshal(value)
|
data, err := json.Marshal(value)
|
||||||
|
|||||||
156
internal/trim/run.go
Normal file
156
internal/trim/run.go
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
package trim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||||
|
"gitea.maximumdirect.net/eric/seriatim/internal/jsonfile"
|
||||||
|
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
||||||
|
)
|
||||||
|
|
||||||
|
type auditReport struct {
|
||||||
|
Operation string `json:"operation"`
|
||||||
|
InputFile string `json:"input_file"`
|
||||||
|
OutputFile string `json:"output_file"`
|
||||||
|
InputSchema string `json:"input_schema"`
|
||||||
|
OutputSchema string `json:"output_schema"`
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
Selector string `json:"selector"`
|
||||||
|
SelectedIDs []int `json:"selected_ids"`
|
||||||
|
AllowEmpty bool `json:"allow_empty"`
|
||||||
|
InputSegmentCount int `json:"input_segment_count"`
|
||||||
|
RetainedSegmentCount int `json:"retained_segment_count"`
|
||||||
|
RemovedSegmentCount int `json:"removed_segment_count"`
|
||||||
|
RemovedInputIDs []int `json:"removed_input_ids"`
|
||||||
|
OldToNewIDMapping []idMapping `json:"old_to_new_id_mapping"`
|
||||||
|
OverlapGroupsRecomputed bool `json:"overlap_groups_recomputed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type idMapping struct {
|
||||||
|
OldID int `json:"old_id"`
|
||||||
|
NewID int `json:"new_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run executes artifact-level trim orchestration.
|
||||||
|
func Run(ctx context.Context, cfg config.TrimConfig) error {
|
||||||
|
if err := ctx.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
selector, err := ParseSelector(cfg.Selector)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid selector %q: %w", cfg.Selector, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(cfg.InputFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("read --input-file %q: %w", cfg.InputFile, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
artifact, err := ParseArtifactJSON(data)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("--input-file %q: %w", cfg.InputFile, err)
|
||||||
|
}
|
||||||
|
inputSegmentCount := artifact.SegmentCount()
|
||||||
|
inputSchema := artifact.Schema
|
||||||
|
|
||||||
|
mode := ModeKeep
|
||||||
|
if cfg.Mode == "remove" {
|
||||||
|
mode = ModeRemove
|
||||||
|
}
|
||||||
|
|
||||||
|
trimmed, err := ApplyArtifact(artifact, Options{
|
||||||
|
Mode: mode,
|
||||||
|
Selector: selector,
|
||||||
|
AllowEmpty: cfg.AllowEmpty,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
outputSchema := artifact.Schema
|
||||||
|
if cfg.OutputSchema != "" {
|
||||||
|
outputSchema = cfg.OutputSchema
|
||||||
|
}
|
||||||
|
|
||||||
|
outputArtifact, err := ConvertArtifact(trimmed.Artifact, outputSchema)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ValidateArtifact(outputArtifact); err != nil {
|
||||||
|
return fmt.Errorf("validate trimmed output: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := jsonfile.Write(cfg.OutputFile, outputArtifact.Value()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.ReportFile == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
audit := auditReport{
|
||||||
|
Operation: "trim",
|
||||||
|
InputFile: cfg.InputFile,
|
||||||
|
OutputFile: cfg.OutputFile,
|
||||||
|
InputSchema: inputSchema,
|
||||||
|
OutputSchema: outputArtifact.Schema,
|
||||||
|
Mode: cfg.Mode,
|
||||||
|
Selector: cfg.Selector,
|
||||||
|
SelectedIDs: selector.IDs(),
|
||||||
|
AllowEmpty: cfg.AllowEmpty,
|
||||||
|
InputSegmentCount: inputSegmentCount,
|
||||||
|
RetainedSegmentCount: len(trimmed.OldToNewID),
|
||||||
|
RemovedSegmentCount: len(trimmed.RemovedIDs),
|
||||||
|
RemovedInputIDs: append([]int(nil), trimmed.RemovedIDs...),
|
||||||
|
OldToNewIDMapping: orderedIDMapping(trimmed.OldToNewID),
|
||||||
|
OverlapGroupsRecomputed: trimmed.OverlapGroupsRecomputed,
|
||||||
|
}
|
||||||
|
auditJSON, err := json.Marshal(audit)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("marshal trim audit report: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rpt := report.Report{
|
||||||
|
Metadata: report.Metadata{
|
||||||
|
Application: outputArtifact.Application(),
|
||||||
|
Version: outputArtifact.Version(),
|
||||||
|
InputReader: "trim-artifact",
|
||||||
|
InputFiles: []string{cfg.InputFile},
|
||||||
|
OutputModules: []string{"json"},
|
||||||
|
},
|
||||||
|
Events: []report.Event{
|
||||||
|
report.Info("trim", "trim", fmt.Sprintf("trimmed %d input segment(s) into %d output segment(s) with mode=%s", inputSegmentCount, outputArtifact.SegmentCount(), cfg.Mode)),
|
||||||
|
report.Info("trim", "trim-audit", string(auditJSON)),
|
||||||
|
report.Info("trim", "validate-output", fmt.Sprintf("validated %d output segment(s)", outputArtifact.SegmentCount())),
|
||||||
|
report.Info("output", "json", "wrote transcript JSON"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := report.WriteJSON(cfg.ReportFile, rpt); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func orderedIDMapping(mapping map[int]int) []idMapping {
|
||||||
|
keys := make([]int, 0, len(mapping))
|
||||||
|
for oldID := range mapping {
|
||||||
|
keys = append(keys, oldID)
|
||||||
|
}
|
||||||
|
sort.Ints(keys)
|
||||||
|
|
||||||
|
pairs := make([]idMapping, 0, len(keys))
|
||||||
|
for _, oldID := range keys {
|
||||||
|
pairs = append(pairs, idMapping{
|
||||||
|
OldID: oldID,
|
||||||
|
NewID: mapping[oldID],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return pairs
|
||||||
|
}
|
||||||
28
internal/trim/run_test.go
Normal file
28
internal/trim/run_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package trim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRunReturnsContextErrorBeforeWork(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
err := Run(ctx, config.TrimConfig{
|
||||||
|
InputFile: filepath.Join(dir, "input.json"),
|
||||||
|
OutputFile: filepath.Join(dir, "output.json"),
|
||||||
|
Mode: "keep",
|
||||||
|
Selector: "1",
|
||||||
|
OutputSchema: "",
|
||||||
|
AllowEmpty: false,
|
||||||
|
})
|
||||||
|
if !errors.Is(err, context.Canceled) {
|
||||||
|
t.Fatalf("error = %v, want context.Canceled", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,10 @@ import (
|
|||||||
var schemaFS embed.FS
|
var schemaFS embed.FS
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
OutputSchemaMinimal = "seriatim-minimal"
|
||||||
|
OutputSchemaIntermediate = "seriatim-intermediate"
|
||||||
|
OutputSchemaFull = "seriatim-full"
|
||||||
|
|
||||||
fullOutputSchemaPath = "full-output.schema.json"
|
fullOutputSchemaPath = "full-output.schema.json"
|
||||||
intermediateOutputSchemaPath = "intermediate-output.schema.json"
|
intermediateOutputSchemaPath = "intermediate-output.schema.json"
|
||||||
minimalOutputSchemaPath = "minimal-output.schema.json"
|
minimalOutputSchemaPath = "minimal-output.schema.json"
|
||||||
@@ -115,6 +119,25 @@ type OverlapGroup struct {
|
|||||||
Resolution string `json:"resolution"`
|
Resolution string `json:"resolution"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidOutputSchemaName reports whether value is a supported output schema name.
|
||||||
|
func ValidOutputSchemaName(value string) bool {
|
||||||
|
switch value {
|
||||||
|
case OutputSchemaMinimal, OutputSchemaIntermediate, OutputSchemaFull:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OutputSchemaNames returns supported output schema names in validation order.
|
||||||
|
func OutputSchemaNames() []string {
|
||||||
|
return []string{
|
||||||
|
OutputSchemaMinimal,
|
||||||
|
OutputSchemaIntermediate,
|
||||||
|
OutputSchemaFull,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ValidateTranscript validates a full transcript against the public JSON
|
// ValidateTranscript validates a full transcript against the public JSON
|
||||||
// schema and seriatim-specific semantic rules.
|
// schema and seriatim-specific semantic rules.
|
||||||
func ValidateTranscript(transcript Transcript) error {
|
func ValidateTranscript(transcript Transcript) error {
|
||||||
@@ -228,15 +251,17 @@ func outputSchema(schemaPath string) (*jsonschema.Schema, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateSemantics(transcript Transcript) error {
|
func validateSemantics(transcript Transcript) error {
|
||||||
|
segments := make([]segmentSemantics, len(transcript.Segments))
|
||||||
for index, segment := range transcript.Segments {
|
for index, segment := range transcript.Segments {
|
||||||
wantID := index + 1
|
segments[index] = segmentSemantics{
|
||||||
if segment.ID != wantID {
|
id: segment.ID,
|
||||||
return fmt.Errorf("segment %d has id %d; want %d", index, segment.ID, wantID)
|
start: segment.Start,
|
||||||
}
|
end: segment.End,
|
||||||
if segment.End < segment.Start {
|
|
||||||
return fmt.Errorf("segment %d has end %.3f before start %.3f", index, segment.End, segment.Start)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := validateSegmentSemantics(segments); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for index, group := range transcript.OverlapGroups {
|
for index, group := range transcript.OverlapGroups {
|
||||||
if group.End < group.Start {
|
if group.End < group.Start {
|
||||||
return fmt.Errorf("overlap_group %d has end %.3f before start %.3f", index, group.End, group.Start)
|
return fmt.Errorf("overlap_group %d has end %.3f before start %.3f", index, group.End, group.Start)
|
||||||
@@ -246,26 +271,43 @@ func validateSemantics(transcript Transcript) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateIntermediateSemantics(transcript IntermediateTranscript) error {
|
func validateIntermediateSemantics(transcript IntermediateTranscript) error {
|
||||||
|
segments := make([]segmentSemantics, len(transcript.Segments))
|
||||||
for index, segment := range transcript.Segments {
|
for index, segment := range transcript.Segments {
|
||||||
wantID := index + 1
|
segments[index] = segmentSemantics{
|
||||||
if segment.ID != wantID {
|
id: segment.ID,
|
||||||
return fmt.Errorf("segment %d has id %d; want %d", index, segment.ID, wantID)
|
start: segment.Start,
|
||||||
}
|
end: segment.End,
|
||||||
if segment.End < segment.Start {
|
|
||||||
return fmt.Errorf("segment %d has end %.3f before start %.3f", index, segment.End, segment.Start)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return validateSegmentSemantics(segments)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateMinimalSemantics(transcript MinimalTranscript) error {
|
func validateMinimalSemantics(transcript MinimalTranscript) error {
|
||||||
|
segments := make([]segmentSemantics, len(transcript.Segments))
|
||||||
for index, segment := range transcript.Segments {
|
for index, segment := range transcript.Segments {
|
||||||
wantID := index + 1
|
segments[index] = segmentSemantics{
|
||||||
if segment.ID != wantID {
|
id: segment.ID,
|
||||||
return fmt.Errorf("segment %d has id %d; want %d", index, segment.ID, wantID)
|
start: segment.Start,
|
||||||
|
end: segment.End,
|
||||||
}
|
}
|
||||||
if segment.End < segment.Start {
|
}
|
||||||
return fmt.Errorf("segment %d has end %.3f before start %.3f", index, segment.End, segment.Start)
|
return validateSegmentSemantics(segments)
|
||||||
|
}
|
||||||
|
|
||||||
|
type segmentSemantics struct {
|
||||||
|
id int
|
||||||
|
start float64
|
||||||
|
end float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateSegmentSemantics(segments []segmentSemantics) error {
|
||||||
|
for index, segment := range segments {
|
||||||
|
wantID := index + 1
|
||||||
|
if segment.id != wantID {
|
||||||
|
return fmt.Errorf("segment %d has id %d; want %d", index, segment.id, wantID)
|
||||||
|
}
|
||||||
|
if segment.end < segment.start {
|
||||||
|
return fmt.Errorf("segment %d has end %.3f before start %.3f", index, segment.end, segment.start)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -5,6 +5,43 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestValidOutputSchemaName(t *testing.T) {
|
||||||
|
valid := []string{
|
||||||
|
OutputSchemaMinimal,
|
||||||
|
OutputSchemaIntermediate,
|
||||||
|
OutputSchemaFull,
|
||||||
|
}
|
||||||
|
for _, name := range valid {
|
||||||
|
if !ValidOutputSchemaName(name) {
|
||||||
|
t.Fatalf("expected %q to be valid", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
invalid := []string{"", "compact", "minimal", "seriatim"}
|
||||||
|
for _, name := range invalid {
|
||||||
|
if ValidOutputSchemaName(name) {
|
||||||
|
t.Fatalf("expected %q to be invalid", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOutputSchemaNames(t *testing.T) {
|
||||||
|
names := OutputSchemaNames()
|
||||||
|
want := []string{
|
||||||
|
OutputSchemaMinimal,
|
||||||
|
OutputSchemaIntermediate,
|
||||||
|
OutputSchemaFull,
|
||||||
|
}
|
||||||
|
if len(names) != len(want) {
|
||||||
|
t.Fatalf("len(names) = %d, want %d", len(names), len(want))
|
||||||
|
}
|
||||||
|
for index := range want {
|
||||||
|
if names[index] != want[index] {
|
||||||
|
t.Fatalf("names[%d] = %q, want %q", index, names[index], want[index])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestValidateTranscriptAcceptsValidTranscript(t *testing.T) {
|
func TestValidateTranscriptAcceptsValidTranscript(t *testing.T) {
|
||||||
transcript := validTranscript()
|
transcript := validTranscript()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user