-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(template): if/else instead of cmd && log || log for the integrity check
#27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,42 @@ mod tests { | |
| } | ||
| } | ||
|
|
||
| /// No `cmd && log ... || log ...` ternaries in the template. | ||
| /// | ||
| /// In that form a FAILING command on the success branch also fires the | ||
| /// failure branch, so a run that actually worked reports both "generated" | ||
| /// and "generation failed". Codacy flagged a real instance of this at | ||
| /// launcher.sh.tera:410; it was spelled across three continued lines, so a | ||
| /// single-line grep missed it — hence a test that joins continuations. | ||
| /// | ||
| /// `A && { B || C; }` is NOT this bug: the `||` is inside a braced group, | ||
| /// making it a compound condition rather than a ternary. | ||
| #[test] | ||
| fn template_has_no_command_log_ternaries() { | ||
| // Join backslash continuations so multi-line ternaries are visible. | ||
| let joined = LAUNCHER_TEMPLATE.replace("\\\n", " "); | ||
| for (i, line) in joined.lines().enumerate() { | ||
| let l = line.trim(); | ||
| if l.starts_with('#') { | ||
| continue; // comments may describe the pattern | ||
| } | ||
| if let Some(amp) = l.find("&& log") { | ||
| if let Some(pipe) = l[amp..].find("|| log") { | ||
|
Comment on lines
+199
to
+207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '160,235p' crates/launcher-common/src/template.rs
printf '\n--- related definitions and tests ---\n'
rg -n -C 4 'LAUNCHER_TEMPLATE|starts_with|&& log|\|\| log|template' crates/launcher-common/src/template.rs crates/launcher-commonRepository: hyperpolymath/launch-scaffolder Length of output: 30353 🏁 Script executed: rg -n -C 5 '&&|\\$|\|\|' templates/launcher.sh.teraRepository: hyperpolymath/launch-scaffolder Length of output: 10846 Normalise whitespace before matching continued commands. When a continuation uses 🤖 Prompt for AI Agents |
||
| // a braced group between them is the safe compound form | ||
| let between = &l[amp..amp + pipe]; | ||
| assert!( | ||
| between.contains('{'), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 MEDIUM RISK Suggestion: The check for a brace |
||
| "line {} is a `cmd && log || log` ternary; use if/else so a \ | ||
| failing log on the success branch cannot fire the failure \ | ||
| branch: {}", | ||
| i + 1, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ LOW RISK The reported line number Refactor the |
||
| l | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// The template source must OPEN with the shebang. | ||
| /// | ||
| /// It previously opened with a Tera comment block, so every launcher the | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -407,9 +407,15 @@ do_integ_linux() { | |||||||||||||||||||||
| gio set "$DESKTOP_SHORTCUT_TARGET" "metadata::trusted" true 2>/dev/null || true | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| if [ -x "/var/mnt/eclipse/repos/.desktop-tools/verify-desktop-integrity.sh" ]; then | ||||||||||||||||||||||
| /var/mnt/eclipse/repos/.desktop-tools/verify-desktop-integrity.sh --generate 2>/dev/null \ | ||||||||||||||||||||||
| && log " + integrity hashes generated" \ | ||||||||||||||||||||||
| || log " · integrity hash generation failed (non-fatal)" | ||||||||||||||||||||||
| # if/else, not `cmd && log || log`: in that form a FAILING log on the | ||||||||||||||||||||||
| # success branch also fires the failure branch, so a run that worked | ||||||||||||||||||||||
| # reports both "generated" and "generation failed". The command's own | ||||||||||||||||||||||
| # status is what should choose the message. | ||||||||||||||||||||||
| if /var/mnt/eclipse/repos/.desktop-tools/verify-desktop-integrity.sh --generate 2>/dev/null; then | ||||||||||||||||||||||
| log " + integrity hashes generated" | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| log " · integrity hash generation failed (non-fatal)" | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
Comment on lines
+414
to
+418
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Make logging non-fatal at the function boundary.
Proposed fix if /var/mnt/eclipse/repos/.desktop-tools/verify-desktop-integrity.sh --generate 2>/dev/null; then
- log " + integrity hashes generated"
+ log " + integrity hashes generated" || true
else
- log " · integrity hash generation failed (non-fatal)"
+ log " · integrity hash generation failed (non-fatal)" || true
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ LOW RISK
Suggestion: The use of
l.find("&& log")is brittle as it requires exactly one space. If multiple spaces or tabs are used, the test will pass despite the bug being present. Consider using a regex like&&\s+logfor better resilience.