Skip to content

fix(benchmarks): use awk -v for variable passing to fix newline parse error#55

Merged
anhermon merged 4 commits into
devfrom
feature/anga-601-fix-awk-benchmark
Apr 6, 2026
Merged

fix(benchmarks): use awk -v for variable passing to fix newline parse error#55
anhermon merged 4 commits into
devfrom
feature/anga-601-fix-awk-benchmark

Conversation

@anhermon

@anhermon anhermon commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Thinking Path

  1. Anvil repo → benchmarks/run.sh provides build-quality scoring
  2. PR feat: add benchmark suite for build quality scoring #51 (ANGA-593) added the benchmark suite but CI fails on the awk weighted-score calculation
  3. Error: awk: cmd. line:3: unexpected newline or end of string — the multi-line awk expression breaks
  4. Root cause: awk treats newlines as statement terminators; a trailing + operator before a newline has no right operand
  5. The original code used double-quoted shell expansion (awk "BEGIN { ... $VAR ... }"), which is fragile — empty or newline-containing variables also break parsing
  6. Fix: switch all awk calls to -v variable passing with single-quoted programs — portable, safe from shell injection, and avoids the newline issue entirely

What Changed

  • benchmarks/run.sh: Replaced all 5 awk "BEGIN { ... $VAR ... }" invocations with awk -v var="$VAR" 'BEGIN { ... var ... }' pattern
    • normalize() fallback awk call (line 38)
    • TEST_PASS_RATE calculation (line 98)
    • BINARY_MB calculation (line 163)
    • OVERALL weighted score calculation (line 169) — primary fix for the reported error
    • PASS threshold check (line 179)

Verification

  • bash -n benchmarks/run.sh passes syntax check (confirmed locally)
  • bash benchmarks/run.sh completes without awk error
  • benchmark-results.json is generated with valid JSON
  • CI benchmark job passes

Risks

Low risk — this is a targeted fix to shell quoting in a single file. The awk -v pattern is POSIX-standard and more portable than double-quoted expansion. No behavioral change to scoring logic.

Checklist

  • Commit messages follow Conventional Commits
  • PR description explains the reasoning
  • Co-Authored-By: Paperclip <noreply@paperclip.ing> in commit

Closes ANGA-601

anhermon and others added 4 commits April 5, 2026 06:05
Release: merge dev into main (26 commits)
The two auth::resolve() tests both mutate CLAUDE_CONFIG_DIR and
ANTHROPIC_API_KEY env vars. When cargo runs them in parallel, one
test can clear the vars while the other is still using them, causing
a spurious "No Anthropic credentials found" failure.

Add a static Mutex so the tests serialize their env-var access.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
Add benchmarks/run.sh that measures build time, test pass rate,
clippy/fmt compliance, and binary size. Outputs standard
benchmark-results.json format.

Integrate benchmark job into CI workflow.

Closes ANGA-593

Co-Authored-By: Paperclip <noreply@paperclip.ing>
… error

The multi-line awk expression for weighted score calculation broke because
awk treats newlines as statement terminators — a trailing `+` operator
before a newline has no right operand. Switch all awk calls from
double-quoted shell expansion to `-v` variable passing with single-quoted
programs, which is both more portable and avoids shell injection of
malformed values.

Closes ANGA-601

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@anhermon anhermon merged commit e3720de into dev Apr 6, 2026
4 checks passed
@anhermon anhermon deleted the feature/anga-601-fix-awk-benchmark branch April 6, 2026 00:44
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.

1 participant