Skip to content

Commit f4ffd6a

Browse files
stream: labeled_trailer_counts option (SPEC 8.4.1)
Opt-in labeled trailer counts for the graph streaming encoder: labeled_trailer_counts=True emits the '##! summary' counts field as label:count (counts=targets:1,related:1,edges:1) instead of the positional default. Conformance runner reads options.labeledTrailerCounts and the skip-guard now treats labeledTrailerCounts as supported, so fixture 005 runs and passes (default output unchanged; 004 positional still passes).
1 parent 54ffe72 commit f4ffd6a

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/gcf/stream.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ def __init__(
3838
tokens_used: int = 0,
3939
pack_root: str = "",
4040
session: bool = False,
41+
labeled_trailer_counts: bool = False,
4142
) -> None:
4243
self._w = writer
44+
self._labeled_trailer_counts = labeled_trailer_counts
4345
self._lock = threading.Lock()
4446
self._sym_index: dict[str, int] = {}
4547
self._next_id = 0
@@ -122,22 +124,29 @@ def write_bare_ref(self, qname: str, distance: int) -> None:
122124
def close(self) -> None:
123125
"""Emit ##! summary trailer with final counts."""
124126
with self._lock:
125-
counts: list[str] = []
127+
# Build label:count sections, then either emit as-is (labeled form,
128+
# SPEC 8.4.1) or strip to values (default positional form).
129+
sections: list[str] = []
126130
group_order = ["targets", "related", "extended"]
127131

128132
for g in group_order:
129133
c = self._group_counts.get(g, 0)
130134
if c > 0:
131-
counts.append(str(c))
135+
sections.append(f"{g}:{c}")
132136
for g, c in self._group_counts.items():
133137
if g not in group_order and c > 0:
134-
counts.append(str(c))
138+
sections.append(f"{g}:{c}")
135139
if self._edge_count > 0:
136-
counts.append(str(self._edge_count))
140+
sections.append(f"edges:{self._edge_count}")
141+
142+
if self._labeled_trailer_counts:
143+
counts_str = ",".join(sections)
144+
else:
145+
counts_str = ",".join(s.split(":", 1)[1] for s in sections)
137146

138147
self._w.write(
139148
f"##! summary symbols={self._next_id} edges={self._edge_count}"
140-
f" counts={','.join(counts)}\n"
149+
f" counts={counts_str}\n"
141150
)
142151

143152
@property

tests/test_conformance_v2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ def _set(s):
199199
)
200200

201201
elif op == "graph-stream-encode":
202-
# Skip a fixture requesting stream options this runner does not support
203-
# (e.g. labeledTrailerCounts, SPEC 8.4.1). This runner supports none.
204-
if data.get("options"):
202+
# labeledTrailerCounts (SPEC 8.4.1) is supported; skip a fixture only if
203+
# it requests some OTHER stream option this runner does not support.
204+
options = data.get("options", {})
205+
if any(k != "labeledTrailerCounts" for k in options):
205206
pytest.skip("unsupported stream options")
206207
import io
207208

@@ -216,6 +217,7 @@ def _set(s):
216217
token_budget=inp.get("tokenBudget", 0),
217218
tokens_used=inp.get("tokensUsed", 0),
218219
pack_root=inp.get("packRoot", ""),
220+
labeled_trailer_counts=options.get("labeledTrailerCounts", False),
219221
)
220222
for s in inp.get("symbols", []):
221223
enc.write_symbol(

0 commit comments

Comments
 (0)