Skip to content

Segments: fix segment types and segment assignment requirements - #18

Merged
nbarrett-anet merged 7 commits into
mainfrom
fixes-01-segments
Nov 26, 2026
Merged

nbarrett-anet merged 7 commits into
mainfrom
fixes-01-segments

Conversation

@nbarrett-anet

@nbarrett-anet nbarrett-anet commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Segments read from a real VCO now work end to end. Assigning one no longer crashes, a ref row that names a PRIVATE or CDE segment loads, and an edge can no longer add a segment its profile lacks.

What changed

  • Segments read from the VCO can be assigned. NetworkSegment stores enum fields as their wire strings (use_enum_values), so a segment parsed from getEnterpriseNetworkSegments held type_ as a str. SegmentResolver.load passed it on unchanged, and assign_segment then crashed on .value. The resolver now converts it to NetworkSegmentType, and descriptor_of takes either form. The test fakes (make_segment_resolver, MockVcoClient.get_enterprise_network_segments) now parse a real wire answer, built by the new pyvelo.testing.network_segment_wire, so tests meet the form the VCO actually sends.
  • Refs naming a PRIVATE or CDE segment load. DeviceSettingsSegmentRef.type_ was a "REGULAR" literal and is now NetworkSegmentType. Every type still dumps as its wire string.
  • An edge cannot add a segment its profile lacks. Such an entry used to be saved and never used, because an edge uses only its profile's segments. It is now refused before anything merges, with PatchError (segment_rule). The message gives the profile patch that assigns the segment, in a form a JSON caller can follow ({"segments": {"Lab": {"_op": "add"}}}, or assign_segment).
  • The rule covers an add under "+". It holds whether the add's body names the segment by segment.name or only by an ID (segmentId or segmentLogicalId). The older rule against an add of an inherited segment now covers ID-only adds too. The ID is read the way merge_patch reads it ("7" and 7.0 are segment 7), through one shared helper, read_given_id in core/merge.py.
  • An ID that names no segment is left to merge_patch. With a segment resolver loaded, merge_patch reports it as an unknown ID. With no resolver, it reports the missing segment.name (invalid_value). A lookup that needs a resolver not yet loaded raises ResolverNotLoadedError, so apply loads the resolver and tries again.
  • _prepare_segment is split into its three cases, with its context in one _SegmentScope. The noqa it carried is removed.

CONFIGURATION.md and the README's pyvelo.testing row describe the new behaviour.

Behaviour changes

  • An edge add of a segment the profile lacks now raises PatchError (segment_rule). Before, it was saved silently if a segment resolver knew the segment, and otherwise raised a LookupError. One existing test that pinned the LookupError now expects the refusal.
  • Nothing sent to the VCO changes for data that loaded before.

Known limits

  • apply loads only a resolver that has to be loaded first. The stock SegmentResolver doesn't, and while unloaded it knows no segment. A state from load always has it loaded, so only a state built by hand can see "Unknown SegmentIdentity" for a real ID.
  • The refusal does not name the profile, and it does not list the profile's segments, which would help catch a typo. Both are left for the work on error messages.

Testing

scripts/check.sh passes: ruff (all rules), ruff format, basedpyright (all, failing on warnings) and strict pytest, with 7886 passed and 2 skipped.

@nbarrett-anet nbarrett-anet changed the title fixes 01 segments Segments: a segment read from the VCO is assigned, PRIVATE and CDE refs load, and an edge cannot add a segment its profile lacks Nov 26, 2026
@nbarrett-anet nbarrett-anet changed the title Segments: a segment read from the VCO is assigned, PRIVATE and CDE refs load, and an edge cannot add a segment its profile lacks Segments: fix segment types and segment assignment requirements Nov 26, 2026
@nbarrett-anet
nbarrett-anet merged commit 7861e0e into main Nov 26, 2026
3 checks passed
@nbarrett-anet
nbarrett-anet deleted the fixes-01-segments branch November 26, 2026 06:32
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