refactor: centralize fingerprint method resolution in a Fingerprinter - #2924
Merged
Conversation
vmaerten
marked this pull request as ready for review
July 19, 2026 19:08
vmaerten
force-pushed
the
refactor/fingerprinter
branch
from
July 19, 2026 19:09
2dcf108 to
95ec19f
Compare
vmaerten
force-pushed
the
refactor/fingerprinter
branch
from
August 3, 2026 20:27
95ec19f to
67380cb
Compare
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
force-pushed
the
refactor/fingerprinter
branch
3 times, most recently
from
August 9, 2026 19:45
daf98d5 to
2a26747
Compare
…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
force-pushed
the
refactor/fingerprinter
branch
from
August 9, 2026 19:50
2a26747 to
1c095ad
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,StatusandToEditorOutput, and the sources checker was built separately instatusOnErrorand incompiledTaskfor the fingerprint variable. AFingerprinterininternal/fingerprintnow 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:
compiledTaskpicked the checker from the task's own method only, so with a Taskfile-levelmethod: timestampthe 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(ornone) that references{{.CHECKSUM}}renders an empty string instead of a checksum. The CHANGELOG entry spells this out.Test plan
TestFingerprintVarMethodInheritedFromTaskfileandTestFingerprintVarMethodNonecover a Taskfile-levelmethod: timestampandmethod: none, with new fixtures undertestdata/. The first one asserts on an actual timestamp value rather than on thets=prefix, which an unresolved (empty) variable also satisfies — checked in a worktree that the assertion does fail against the pre-fix code.TestFingerprinterMethodResolutionlocks the resolution itself: the task method wins over the Taskfile default, the default is inherited (includingnone), and an invalid method is rejected identically byKind,SourceValue,UpToDateandOnErrorinstead of being silently treated aschecksumon one path.mainand from this branch: on a Taskfile with a rootmethod: timestamp,mainprints an empty{{.TIMESTAMP}}and a checksum for{{.CHECKSUM}}; this branch prints the timestamp and an empty{{.CHECKSUM}}.