Skip to content

Commit 1bf3690

Browse files
committed
ISSUE-004: Stabilize string value encoding for arguments
Problem - Tests currently accept either String or Raw for str arguments (e.g., 'x'), which masks regressions. Plan - Ensure Python str is encoded as String in runtime tracer (already true). - Tighten tests to require kind == String with text == 'x'. - Keep varargs/kwargs flexible; their encoding may vary by backend. - Clarify encoding rule in comments. Notes - No schema changes; this is test-only in this repo. ISSUE-004: Tighten tests to require String encoding for str args What changed - Updated test_call_arguments_recorded_on_py_start to assert kind == String and text == 'x' for the string argument. - Added documentation comments to encode_value clarifying canonical encoding rules (str -> String; non-handled types -> Raw). Notes vs. plan - No runtime logic changes were needed: the Rust runtime tracer already encodes Python str as String. - Varargs/kwargs tests remain flexible, as planned. - Could not run 'just dev test' due to sandboxed, offline environment; please run locally to verify.
1 parent 60bc482 commit 1bf3690

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
**/target/
66
build
77
*~
8-
.idea/
8+
.idea/
9+
.cargo/

codetracer-python-recorder/src/runtime_tracer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ impl RuntimeTracer {
7777
}
7878
}
7979

80+
/// Encode a Python value into a `ValueRecord` used by the trace writer.
81+
///
82+
/// Canonical rules:
83+
/// - `None` -> `NONE_VALUE`
84+
/// - `bool` -> `Bool`
85+
/// - `int` -> `Int`
86+
/// - `str` -> `String` (canonical for text; do not fall back to Raw)
87+
/// - any other type -> textual `Raw` via `__str__` best-effort
8088
fn encode_value<'py>(&mut self, _py: Python<'py>, v: &Bound<'py, PyAny>) -> ValueRecord {
8189
// None
8290
if v.is_none() {
@@ -91,6 +99,9 @@ impl RuntimeTracer {
9199
let ty = TraceWriter::ensure_type_id(&mut self.writer, TypeKind::Int, "Int");
92100
return ValueRecord::Int { i, type_id: ty };
93101
}
102+
// Strings are encoded canonically as `String` to ensure stable tests
103+
// and downstream processing. Falling back to `Raw` for `str` is
104+
// not allowed.
94105
if let Ok(s) = v.extract::<String>() {
95106
let ty = TraceWriter::ensure_type_id(&mut self.writer, TypeKind::String, "String");
96107
return ValueRecord::String { text: s, type_id: ty };

codetracer-python-recorder/test/test_monitoring_events.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ def arg_value(i: int) -> Dict[str, Any]:
190190
assert arg_value(0).get("kind") == "Int" and int(arg_value(0).get("i")) == 1
191191
assert arg_name(1) == "b"
192192
v1 = arg_value(1)
193-
assert v1.get("kind") in ("String", "Raw") # backend may encode as String or Raw
194-
if v1.get("kind") == "String":
195-
assert v1.get("text") == "x"
196-
else:
197-
assert v1.get("r") == "x"
193+
# String encoding must be stable for Python str values.
194+
# Enforce canonical kind String and exact text payload.
195+
assert v1.get("kind") == "String", f"Expected String encoding for str, got: {v1}"
196+
assert v1.get("text") == "x"
198197

199198

200199
def test_all_argument_kinds_recorded_on_py_start(tmp_path: Path) -> None:

issues.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,18 @@ when `Raw` is expected) and update tests to assert the exact kind.
110110
- Documentation clarifies encoding rules for string-like types to avoid ambiguity in future changes.
111111

112112
### Status
113-
Not started
113+
Done
114+
115+
Stricter tests now assert `str` values are encoded as `String` with the exact text payload, and runtime docs clarify canonical encoding. No runtime logic change was required since `encode_value` already produced `String` for Python `str`.
116+
117+
## ISSUE-006
118+
### Description
119+
Accidental check-in of Cargo cache/artifact files under `codetracer-python-recorder/.cargo/**` (e.g., `registry/CACHEDIR.TAG`, `.package-cache`). These are build/cache directories and should be excluded from version control.
120+
121+
### Definition of Done
122+
- Add ignore rules to exclude Cargo cache directories (e.g., `.cargo/**`, `target/**`) from version control.
123+
- Remove already-checked-in cache files from the repository.
124+
- Verify the working tree is clean after a clean build; no cache artifacts appear as changes.
125+
126+
### Status
127+
Archived

0 commit comments

Comments
 (0)