Skip to content

[$25 BOUNTY] [Perl] Add log watchdog malformed JSON fixture coverage#24

Open
leo202000 wants to merge 2 commits into
Soengkit:mainfrom
leo202000:feat/frailbox-log-watchdog
Open

[$25 BOUNTY] [Perl] Add log watchdog malformed JSON fixture coverage#24
leo202000 wants to merge 2 commits into
Soengkit:mainfrom
leo202000:feat/frailbox-log-watchdog

Conversation

@leo202000

Copy link
Copy Markdown

Summary

Adds malformed JSON fixture coverage for the v2 log watchdog summary output, as requested in issue #6.

Changes

  • v2/scripts/log_watchdog.pl:

    • Add --scan mode: process log files once and exit (non-daemon), suitable for CI and fixture testing.
    • Add --json-summary flag: output JSON summary with json_lines count, malformed_json count, alerts_sent, version, and pattern_matches.
    • Add JSON line detection in process_line: lines starting with { are parsed with JSON::PP; malformed JSON is counted but does not crash the watchdog.
    • Exit code 1 when malformed JSON detected, 0 otherwise.
    • Make File::Tail optional (not needed for --scan mode).
    • Fix pre-existing compile errors: add MAGIC_NUMBER_47 constant, fix $PID_FILE and $DEFAULT_CONFIG bareword usage under use strict.
  • v2/scripts/test_watchdog_fixtures.pl (new): 25 tests covering:

    • Valid JSON log lines (3 lines, 0 malformed, exit 0)
    • Malformed JSON log lines (4 lines, all malformed, exit 1)
    • Mixed valid + malformed + plain text (4 JSON-like, 2 malformed, exit 1)
    • Plain text only (0 JSON lines, exit 0)
    • Empty file (0 JSON lines, exit 0)
    • JSON summary field completeness (version, json_lines, malformed_json, alerts_sent, pattern_matches)
  • docs/OPERATIONS.md: Documented --scan/--json-summary usage, JSON output format, malformed JSON handling, and fixture test command.

Testing

  • perl v2/scripts/test_watchdog_fixtures.pl — 25 tests, all pass (WSL Ubuntu, Perl 5.38.2)
  • python3 build.py — diagnostic build log generated and included below
    • Build results: frontend PASS, frailbox PASS, engine PASS (3/10 modules; 7 FAIL due to missing toolchains)

Checklist

  • Relevant modules affected by these changes build locally
  • Tests pass locally
  • Diagnostic build log is committed in this PR (diagnostic/build-9fcca4fe.logd)
  • Changes are scoped to the PR purpose
  • Security, privacy, and error-handling implications have been considered

Closes #6

…tput

- Add --scan mode to log_watchdog.pl: process log files once and exit
  (non-daemon), suitable for CI and fixture testing.
- Add --json-summary flag: output JSON summary with json_lines count,
  malformed_json count, alerts_sent, and pattern_matches.
- Add JSON line detection in process_line: lines starting with '{' are
  parsed with JSON::PP; malformed JSON is counted but does not crash.
- Exit code 1 when malformed JSON detected, 0 otherwise.
- Make File::Tail optional (not needed for --scan mode).
- Fix pre-existing compile errors: add MAGIC_NUMBER_47 constant,
  fix \ and \ bareword usage under strict.
- Add v2/scripts/test_watchdog_fixtures.pl: 25 tests covering valid
  JSON, malformed JSON, mixed input, plain text, empty files, exit
  codes, and JSON field completeness.
- Document --scan/--json-summary in docs/OPERATIONS.md.

Closes #6
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.

Payout tracking for upstream PR #444

1 participant