-
Notifications
You must be signed in to change notification settings - Fork 0
Rectify: Trace Identity Contract #776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7d8df47
130477a
5b4df88
098eec9
84810f0
7a5a713
a881b84
a30da9b
1809a8c
d90c682
f407904
cb49a00
794134a
5247553
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,9 @@ | |
| from __future__ import annotations | ||
|
|
||
| import dataclasses | ||
| import inspect | ||
| import logging | ||
| import os | ||
| import tempfile | ||
| from dataclasses import dataclass, field | ||
| from pathlib import Path | ||
|
|
@@ -193,6 +195,25 @@ class LinuxTracingConfig: | |
| log_dir: str = "" # empty = platform default (~/.local/share/autoskillit/logs on Linux) | ||
| tmpfs_path: str = "/dev/shm" # RAM-backed tmpfs for crash-resilient streaming | ||
|
|
||
| def __post_init__(self) -> None: | ||
| if self.tmpfs_path != "/dev/shm" or not os.environ.get("PYTEST_CURRENT_TEST"): | ||
| return | ||
| # Only raise when called directly from test code — not from library machinery | ||
Trecek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # (e.g. AutomationConfig default_factory, from_dynaconf). We inspect the call | ||
| # frame two levels up: __post_init__ → __init__ (generated) → actual caller. | ||
| frame = inspect.currentframe() | ||
| init_frame = frame.f_back if frame is not None else None | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [warning] arch: The call-stack depth heuristic is fragile. The
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Investigated — this is intentional. The commit message 'fix: scope post_init guard to direct test callers only' (9e07dc5) explicitly defines the scope. Fixtures calling helpers and from_dynaconf bypassing the guard is the desired behavior — only direct test-code instantiation of LinuxTracingConfig(tmpfs_path='/dev/shm') should be blocked. The category: false_positive_intentional_pattern. |
||
| caller = init_frame.f_back if init_frame is not None else None | ||
| if caller is not None and "/tests/" in (caller.f_code.co_filename or ""): | ||
| raise RuntimeError( | ||
| "LinuxTracingConfig.tmpfs_path is '/dev/shm' but PYTEST_CURRENT_TEST " | ||
| "is set — this test would write to the real shared tmpfs and pollute " | ||
| "production state. Override tmpfs_path with a test-local path, e.g.: " | ||
| "LinuxTracingConfig(tmpfs_path=str(tmp_path)). " | ||
| "Use the isolated_tracing_config fixture for new tests." | ||
| ) | ||
| del frame, init_frame, caller | ||
|
|
||
|
|
||
| @dataclass | ||
| class McpResponseConfig: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[warning] defense: The guard walks exactly two frames back (
frame.f_back.f_back) to find the test caller. IfLinuxTracingConfigis constructed via a helper factory,dataclasses.replace, a classmethod, or a one-liner wrapper, the test-file frame will be further than two levels up and the guard will silently not fire. The depth assumption is fragile and not documented in the error message.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Investigated — this is intentional. The two-level frame walk is deliberately scoped to direct test callers only (commit 9e07dc5, comment on lines 200-202 documents this). Factory paths, from_dynaconf, and AutomationConfig default_factory are intentionally excluded: they construct LinuxTracingConfig with production defaults and should not be blocked. The 'fragility' is the feature: indirect paths bypass the guard by design.