Skip to content

[P1] U-17: VIBEGUARD_LOG_FILE unguarded in session_metrics.py — incomplete fix from #93 #103

Description

@majiayu000

Description

hooks/_lib/session_metrics.py:35 still uses a bare bracket access:

log_file = os.environ["VIBEGUARD_LOG_FILE"]

PR #93 fixed the same class of bug for VIBEGUARD_PROJECT_LOG_DIR (line 163) and VIBEGUARD_SESSION_ID (line 39) by switching to .get() with an early sys.exit(0), but VIBEGUARD_LOG_FILE was left unchanged. When the script is invoked standalone — without this env var exported — it raises a noisy KeyError: 'VIBEGUARD_LOG_FILE' Python traceback instead of silently exiting.

The unit test file tests/unit/test_session_metrics_env_guard.sh always supplies VIBEGUARD_LOG_FILE in every test case (see line ~50 VIBEGUARD_LOG_FILE="${TMPDIR_TEST}/events.jsonl"), so this code path has never been exercised by the test suite.

File reference

  • hooks/_lib/session_metrics.py:35

Recommended action

Replace line 35 with:

log_file = os.environ.get("VIBEGUARD_LOG_FILE", "")
if not log_file:
    sys.exit(0)

Then add a test case to tests/unit/test_session_metrics_env_guard.sh that runs the script with VIBEGUARD_LOG_FILE unset and asserts exit code 0 with empty stdout (matching the guard pattern for VIBEGUARD_PROJECT_LOG_DIR at line 163).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High priority - two weeksreviewPeriodic health review finding

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions