Skip to content

[Low] fix(cli): fix unreachable branch in resolveInput — directories named *.json/yaml now fall through to 'path'#716

Open
katnisscalls99 wants to merge 1 commit into
profullstack:masterfrom
katnisscalls99:fix/resolve-input-dead-code
Open

[Low] fix(cli): fix unreachable branch in resolveInput — directories named *.json/yaml now fall through to 'path'#716
katnisscalls99 wants to merge 1 commit into
profullstack:masterfrom
katnisscalls99:fix/resolve-input-dead-code

Conversation

@katnisscalls99
Copy link
Copy Markdown

resolveInput() had two consecutive branches classifying local paths as 'doc' when their extension matched DOC_EXTS (.json, .yaml, .yml, .toml, .md, .pdf):

if (ext && DOC_EXTS.has(ext)) {             // always returns here
    return { kind: 'doc', … };
}
if (exists && statSync(abs).isFile() && ext && DOC_EXTS.has(ext)) {  // UNREACHABLE
    return { kind: 'doc', … };
}

The second branch was clearly intended to restrict 'doc' classification to actual files (excluding directories that happen to carry a doc-like extension), but the identical first predicate makes it dead code. The consequence: sh1pt build --from ./config.yaml where config.yaml is a directory (a real pattern in consul-template, vault, dotnet) returns kind='doc', and downstream callers fail with EISDIR when they try to read it as a file.

Fix: collapse to one correct check that returns 'doc' only when the path has a doc extension AND either does not exist yet (legitimate future-output path) or is a confirmed regular file. A directory named *.yaml now falls through to the 'path' default.

Severity: Low

…*.json/yaml now fall through to 'path'

resolveInput() had two consecutive branches classifying local paths as
'doc' when their extension matched DOC_EXTS (.json, .yaml, .yml, .toml,
.md, .pdf):

  if (ext && DOC_EXTS.has(ext)) {             // always returns here ↩
    return { kind: 'doc', … };
  }
  if (exists && statSync(abs).isFile() && ext && DOC_EXTS.has(ext)) {  // UNREACHABLE
    return { kind: 'doc', … };
  }

The second branch was clearly intended to restrict 'doc' classification
to actual files (excluding directories that happen to carry a doc-like
extension), but the identical first predicate makes it dead code. The
consequence: 'sh1pt build --from ./config.yaml' where config.yaml is a
directory (a real pattern in consul-template, vault, dotnet) returns
kind='doc', and downstream callers fail with EISDIR when they try to
read it as a file.

Fix: collapse to one correct check that returns 'doc' only when the path
has a doc extension AND either does not exist yet (legitimate future-
output path) or is a confirmed regular file. A directory named *.yaml
now falls through to the 'path' default.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 6, 2026

Greptile Summary

This PR fixes a dead-code bug in resolveInput() where the first branch (if (ext && DOC_EXTS.has(ext))) returned unconditionally on extension match, making the second branch (which correctly gated on isFile()) unreachable. The consequence was that a directory whose name ends in a doc extension — e.g. ./config.yaml/ — was misclassified as kind: 'doc', causing EISDIR errors downstream.

  • Bug fix: Collapses the two branches into a single predicate (isDocLike && isFileOrMissing) that returns 'doc' only when the path has a recognised extension AND is either a regular file or does not exist yet, letting directories with doc-like names fall through to 'path'.
  • Correctness: The exists field returned for non-existent future-output paths is preserved as false, consistent with the original first branch and the ResolvedInput contract.

Confidence Score: 5/5

Safe to merge — the change is a minimal, targeted collapse of two branches into one correct predicate with no new logic introduced beyond an isFile() guard that was already present in the dead branch.

The fix addresses exactly the scenario described in the PR: a directory named *.yaml was previously classified as 'doc' and would cause EISDIR failures downstream. The new combined predicate correctly handles all three cases — regular file, non-existent path, and directory — with no change to other classification branches or the returned ResolvedInput shape.

No files require special attention. packages/cli/src/input.ts is the only changed file and the diff is small and self-contained.

Important Files Changed

Filename Overview
packages/cli/src/input.ts Collapses two consecutive resolveInput branches into one correct predicate that gates 'doc' classification on both extension match and isFile(), fixing a dead-code bug that caused directories with doc-like extensions to be misclassified.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["resolveInput(raw)"] --> B{SSH or Git URL?}
    B -- yes --> C["kind: git"]
    B -- no --> D{HTTPS Git URL?}
    D -- yes --> C
    D -- no --> E{HTTPS URL?}
    E -- yes --> F["kind: url"]
    E -- no --> G["Resolve abs path<br/>ext = extname<br/>exists = existsSync"]
    G --> H["isDocLike = ext in DOC_EXTS"]
    H --> I["isFileOrMissing = !exists OR statSync.isFile()"]
    I --> J{"isDocLike AND isFileOrMissing?"}
    J -- yes --> K["kind: doc"]
    J -- no --> L["kind: path (default)<br/>directories named *.yaml land here"]
Loading

Reviews (1): Last reviewed commit: "fix(cli): fix unreachable branch in reso..." | Re-trigger Greptile

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

8 similar comments
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

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