Skip to content

fix(learn): gate lessons on the learner's code, not the hint comments - #1259

Merged
Chemaclass merged 1 commit into
mainfrom
fix/1258-lesson-gates
Aug 14, 2026
Merged

fix(learn): gate lessons on the learner's code, not the hint comments#1259
Chemaclass merged 1 commit into
mainfrom
fix/1258-lesson-gates

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1258

Every lesson checks "did the learner use this API", but the template each lesson writes carries that name in its own TODO/Hint lines. All nine gates passed on their own untouched template — and a lesson could be completed with an unrelated passing assertion:

function test_multiple_assertions() {
  # TODO: Check that message contains "bashunit"
  # Hint: assert_contains "substring" "$message"
  assert_same 1 1
}
gate (assert_contains): 1 match — on the comment
run --fail-on-risky:    exit 0
=> "✓ Excellent! Lesson 2 completed!"

without ever using assert_contains, assert_matches or assert_not_empty, which is the whole lesson. Pairs with #1257: that closed the "no work at all" path, this closes the "wrong work" path.

💡 Changes

  • One shared bashunit::learn::count_in_code helper counting matches outside comment lines, used by all nine gates rather than nine copies
  • Two tests: the gates that name an assertion are not satisfied by their own template, and the helper itself ignores a hint while counting the same call in code

On the guard's scope

It covers gates naming an assertion. The others look for function set_up() or function data_provider_, which the template declares in code as a skeleton on purpose — those cannot distinguish template from solution and are not meant to; --fail-on-risky is what makes an unfilled skeleton fail.

An earlier version asserted the invariant over every gate and passed only because a stray break stopped it after the first file, where it would have been false for five of them. The version here also asserts it compared something, so an empty set cannot fake a pass. Mutation-checked: reverting the helper to a plain grep fails both tests.

Every lesson checks "did the learner use this API", but the template each
lesson writes carries that name in its own TODO/Hint lines. A plain grep
matched the hint, so all nine gates passed on an untouched file -- and a lesson
could be completed with an unrelated passing assertion:

  # TODO: Check that message contains "bashunit"
  # Hint: assert_contains "substring" "$message"
  assert_same 1 1

gate: 1 match (on the comment), run: exit 0, "Lesson 2 completed" -- without
ever using assert_contains, assert_matches or assert_not_empty, which is the
whole lesson.

One shared helper counts matches outside comment lines, used by all nine gates.

The guard is scoped to gates that name an assertion. The others look for
`function set_up()` or `function data_provider_`, which the template declares
in code as a skeleton on purpose -- those cannot distinguish template from
solution and are not meant to; --fail-on-risky (#1257) is what makes an
unfilled skeleton fail. An earlier version asserted the invariant over every
gate and passed only because it stopped after the first file, where it would
have been false for five of them. It now also asserts it compared something.

Closes #1258
@Chemaclass Chemaclass added the bug Something isn't working label Aug 14, 2026
@Chemaclass Chemaclass self-assigned this Aug 14, 2026
@Chemaclass
Chemaclass merged commit 579c888 into main Aug 14, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the fix/1258-lesson-gates branch August 14, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant