Skip to content

refactor: centralize fingerprint method resolution in a Fingerprinter - #2924

Merged
vmaerten merged 7 commits into
mainfrom
refactor/fingerprinter
Aug 10, 2026
Merged

refactor: centralize fingerprint method resolution in a Fingerprinter#2924
vmaerten merged 7 commits into
mainfrom
refactor/fingerprinter

Conversation

@vmaerten

@vmaerten vmaerten commented Jul 19, 2026

Copy link
Copy Markdown
Member

Summary

The decision "is this task up to date?" was spread over five call sites: the method-selection idiom (task method falling back to the Taskfile method) was copied verbatim in RunTask, Status and ToEditorOutput, and the sources checker was built separately in statusOnError and in compiledTask for the fingerprint variable. A Fingerprinter in internal/fingerprint now owns method resolution and checker construction behind a small interface (UpToDate, OnError, Kind, SourceValue), and every call site goes through it.

This also fixes the fingerprint variable ignoring a method set at the Taskfile level: compiledTask picked the checker from the task's own method only, so with a Taskfile-level method: timestamp the injected variable was computed by the checksum checker while the up-to-date check used timestamp, and {{.TIMESTAMP}} came out empty.

Behaviour change worth a reviewer's call: only the variable matching the effective method is injected now, so a task inheriting a Taskfile-level method: timestamp (or none) that references {{.CHECKSUM}} renders an empty string instead of a checksum. The CHANGELOG entry spells this out.

Test plan

  • TestFingerprintVarMethodInheritedFromTaskfile and TestFingerprintVarMethodNone cover a Taskfile-level method: timestamp and method: none, with new fixtures under testdata/. The first one asserts on an actual timestamp value rather than on the ts= prefix, which an unresolved (empty) variable also satisfies — checked in a worktree that the assertion does fail against the pre-fix code.
  • TestFingerprinterMethodResolution locks the resolution itself: the task method wins over the Taskfile default, the default is inherited (including none), and an invalid method is rejected identically by Kind, SourceValue, UpToDate and OnError instead of being silently treated as checksum on one path.
  • Manually verified with binaries built from main and from this branch: on a Taskfile with a root method: timestamp, main prints an empty {{.TIMESTAMP}} and a checksum for {{.CHECKSUM}}; this branch prints the timestamp and an empty {{.CHECKSUM}}.

@vmaerten
vmaerten marked this pull request as ready for review July 19, 2026 19:08
@vmaerten
vmaerten force-pushed the refactor/fingerprinter branch from 2dcf108 to 95ec19f Compare July 19, 2026 19:09
@vmaerten
vmaerten force-pushed the refactor/fingerprinter branch from 95ec19f to 67380cb Compare August 3, 2026 20:27
The decision "is this task up to date?" was spread over five call sites:
the method-selection idiom (task method falling back to the Taskfile
method) was copied verbatim in RunTask, Status and ToEditorOutput, and
the sources checker was constructed separately in statusOnError and in
compiledTask for the CHECKSUM/TIMESTAMP variable injection.

Introduce a Fingerprinter in internal/fingerprint that owns method
resolution and checker construction behind a small interface (UpToDate,
OnError, Kind, SourceValue), and route all five call sites through it.
It is built on the fly from the Executor's current state because
exported fields like Dry may legitimately be mutated between runs.

This also fixes the fingerprint variable ignoring a method set at the
Taskfile level: compiledTask picked the checker from the task's own
method only, so with a Taskfile-level "method: timestamp" the injected
variable was computed by the checksum checker while the up-to-date
check used timestamp. The variable now follows the same resolution as
the up-to-date check, and is no longer injected when the effective
method is "none".
@vmaerten
vmaerten force-pushed the refactor/fingerprinter branch 3 times, most recently from daf98d5 to 2a26747 Compare August 9, 2026 19:45
…alue

SourceValue built its checker from the normalized Kind, so a mistyped
"method:" produced a checksum on that path while UpToDate and OnError
rejected it with "invalid method". Resolve the checker from the task's
method in all three, and leave Kind as the one tolerant entry point:
it only names the variable to inject, so compiling a task never fails
over a method it doesn't use — runs that skip fingerprinting (--force)
go through it all the same.

Also hoist the sources guard in compiledTask so no Fingerprinter is
built for tasks without sources, and reuse a single one for Kind and
SourceValue.
Table the two Taskfile-level method tests, assert on an actual
timestamp rather than on the "ts=" prefix an unresolved variable also
satisfies, and add a --force case over an invalid method, which no
test caught. On the unit side, check that Kind and SourceValue agree
on the resolved method, and that an invalid one is rejected by every
entry point that needs a checker.
Drop the step-by-step comments inside UpToDate, which the truth table
right above the function already spells out, and cut the doc comments
carried over from the extraction down to what the signature doesn't
say.
@vmaerten
vmaerten force-pushed the refactor/fingerprinter branch from 2a26747 to 1c095ad Compare August 9, 2026 19:50
The table restated the if-chain right below it in the godoc; it belongs
where it is exercised.
Kind tolerates an invalid method so that naming a variable cannot fail,
but SourceValue then rejected it, so a task referencing {{.CHECKSUM}}
with a typo'd method failed to compile: --force, which skips
fingerprinting entirely, stopped working, and the error lost the task
name and its 201 exit code on every other path.

Mark it with ErrInvalidMethod so compiledTask can skip the injection
without swallowing a checker that genuinely failed on the sources, and
leave the reporting to the up-to-date check, as before the refactor.
The option constructors and the FingerprinterOption alias said nothing
their names don't; the remaining comments are trimmed to the part the
signature doesn't carry.
@vmaerten
vmaerten merged commit fc49c72 into main Aug 10, 2026
20 checks passed
@vmaerten
vmaerten deleted the refactor/fingerprinter branch August 10, 2026 14:12
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