Skip to content

Use one channel snapshot for header and signal writes - #848

Merged
tompollard merged 2 commits into
mainfrom
refactor/snapshot-signal-writer
Dec 2, 2026
Merged

tompollard merged 2 commits into
mainfrom
refactor/snapshot-signal-writer

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

  • Use the same captured channel fields for signal value validation and encoding that were used to write the header.
  • Remove a second dynamic get_write_fields() lookup from the normal write path. Direct calls without a snapshot retain their existing behavior.
  • Test both uniform and expanded writes when a mutable format list changes between header and data writing. The output remains readable in the header's format.

This advances #749 and #744. It does not change the public Record fields.

Validation

  • Offline suite: 1,662 passed, 4 skipped, 23 network tests deselected.
  • Ruff lint and format checks passed.
  • Strict Sphinx docs build passed.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge. The signal-value check now uses the same fmt and samps_per_frame snapshot as the header and the encoder, so all three agree.

What I checked

  • I wrote every single-segment record in sample-data with wrsamp, both uniform and expanded (141 writes), on this branch and on the merge base. Every written file is byte-identical, and the record's fields after writing are unchanged. The 21 writes that fail on main fail in the same way here.
  • I ran the new test against main. Both cases fail there: the value check reads the edited fmt ("80") and raises IndexError, even though the header and the encoder still use "212". On this branch, both pass.
  • Offline suite (1,662 passed, 4 skipped), Ruff, the strict docs build and CI all pass.

One behaviour change, which I think is an improvement

wrsamp(expanded=True) no longer modifies the record. On main, a samps_per_frame of [None, 1] becomes [1, 1] on the record after writing; on this branch it stays [None, 1]. The header and data files are identical either way. Nothing in the write path reads the list after this point, so a write that leaves its input alone seems better. A direct call to check_sig_cohesion without a snapshot still fills in the defaults, as before.

Optional

  • The test only edits fmt. A second case that edits samps_per_frame[0] after the header would cover the new length check in the expanded branch.
  • The test could also assert that samps_per_frame is unchanged after an expanded write, so the behaviour above is deliberate rather than incidental.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks for checking the output against the merge base, including all 141 writes. I agree that leaving samps_per_frame unchanged is the better behavior here.

I added both suggested tests in 38f694a. One changes samps_per_frame[0] after the header write and checks that the expanded data still uses the captured frame size. The other confirms that an expanded write leaves an omitted frame size as None on the input record. Both tests fail on main and pass on this branch. The 53 focused writer and header tests pass; this follow-up changes tests only.

@tompollard
tompollard merged commit 6a6b99f into main Dec 2, 2026
19 checks passed
@tompollard
tompollard deleted the refactor/snapshot-signal-writer branch December 2, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant