-
Notifications
You must be signed in to change notification settings - Fork 0
Three answers the seams gave about repositories they were not looking at #7
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 | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -790,6 +790,45 @@ fn file_identity(path: &Path) -> Option<PathBuf> { | |||||||||||||||||||||||||||||||||||||||||||||||
| path.canonicalize().ok() | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// How this process was reached, which is the only thing that differs when | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// nothing here declares the command. | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// Both are the same seam and the same reading. One is a command being run -- | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// through a link named for it, on a PATH that spans the whole machine -- and | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// the other is a question asked about this repository, typed with the answer | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// in mind. | ||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) enum Invoked { | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// Through a link named for the command: argv[0] decided. | ||||||||||||||||||||||||||||||||||||||||||||||||
| AsTheCommand, | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// As `uphold shim <command>`, with the command named as an argument. | ||||||||||||||||||||||||||||||||||||||||||||||||
| ByName, | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Run the command with nothing standing in front of it. | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// The transparent path, for the two answers that are not "check this": no | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// policy where the command was typed, and a policy that declares no shim for | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// it. Both are readings rather than failures to read, and a shim installed for | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// the whole machine meets them constantly -- every directory outside a | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// participating repository is one of them. | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// No stdin is replayed because none was collected: reading it belongs to the | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// checking path, and a command whose text nothing here reads must be handed | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// the descriptor it was given rather than a copy of what this process drained | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// out of it. | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) fn exec_through(name: &str, argv: &[OsString]) -> Result<Exit> { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let own = std::env::current_exe().ok(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let Some(real) = real_command(name, own.as_deref()) else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return Err(Fatal::new(format!( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "nothing here stands in front of {name}, and there is no {name} on PATH to run" | ||||||||||||||||||||||||||||||||||||||||||||||||
| ))); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut command = Command::new(&real); | ||||||||||||||||||||||||||||||||||||||||||||||||
| command.args(argv); | ||||||||||||||||||||||||||||||||||||||||||||||||
| hand_off(&mut command, name, None) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+820
to
+830
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. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Fail when the shim cannot identify itself. Line 821 discards a Proposed fix- let own = std::env::current_exe().ok();
- let Some(real) = real_command(name, own.as_deref()) else {
+ let own = std::env::current_exe()
+ .map_err(|error| Fatal::new(format!("{name}: cannot identify shim executable: {error}")))?;
+ let Some(real) = real_command(name, Some(&own)) else {As per coding guidelines, “When continuing cannot satisfy the contract safely, detect the condition at the earliest reliable boundary and return an explicit failure with evidence.” 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// The real command, found by walking PATH past ourselves. | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// "Past ourselves" is a question about the FILE, not about the directory. A | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1083,7 +1122,13 @@ fn hand_off(command: &mut Command, name: &str, stdin: Option<&[u8]>) -> Result<E | |||||||||||||||||||||||||||||||||||||||||||||||
| /// the exec. The two cannot disagree about a decision, because every string | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// this shim compares against is ASCII, and lossy conversion only ever replaces | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// a sequence that was not text to begin with. | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) fn run(root: &Path, policy: &Policy, name: &str, argv: &[OsString]) -> Result<Exit> { | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) fn run( | ||||||||||||||||||||||||||||||||||||||||||||||||
| root: &Path, | ||||||||||||||||||||||||||||||||||||||||||||||||
| policy: &Policy, | ||||||||||||||||||||||||||||||||||||||||||||||||
| name: &str, | ||||||||||||||||||||||||||||||||||||||||||||||||
| argv: &[OsString], | ||||||||||||||||||||||||||||||||||||||||||||||||
| invoked: Invoked, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Result<Exit> { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let words: Vec<String> = argv | ||||||||||||||||||||||||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||||||||||||||||||||||||
| .map(|argument| argument.to_string_lossy().into_owned()) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1102,14 +1147,35 @@ pub(crate) fn run(root: &Path, policy: &Policy, name: &str, argv: &[OsString]) - | |||||||||||||||||||||||||||||||||||||||||||||||
| .map(|shim| (shim.command.as_str(), shim)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let Some(shim) = shims.get(name) else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return Err(Fatal::new(format!( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "no shim declares the command {name:?}; this policy declares {}", | ||||||||||||||||||||||||||||||||||||||||||||||||
| if shims.is_empty() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| String::from("none") | ||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| shims.keys().copied().collect::<Vec<&str>>().join(", ") | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| ))); | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Nothing here declares this command. The reading is the same either | ||||||||||||||||||||||||||||||||||||||||||||||||
| // way -- an absent declaration is a place the rule does not run, the | ||||||||||||||||||||||||||||||||||||||||||||||||
| // same way an absent `[git]` table is, and it is not a could-not-look, | ||||||||||||||||||||||||||||||||||||||||||||||||
| // so it is not exit 2 by the rule that governs those. What differs is | ||||||||||||||||||||||||||||||||||||||||||||||||
| // what was asked. | ||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Run AS the command, the answer lets it run. The link is on PATH for | ||||||||||||||||||||||||||||||||||||||||||||||||
| // the whole machine while a `[[shim]]` is a line in one repository's | ||||||||||||||||||||||||||||||||||||||||||||||||
| // policy, so refusing an undeclared command meant `git` exiting 2 in | ||||||||||||||||||||||||||||||||||||||||||||||||
| // every repository that had not declared one, and in every directory | ||||||||||||||||||||||||||||||||||||||||||||||||
| // that is not a repository at all. What gets installed after that is | ||||||||||||||||||||||||||||||||||||||||||||||||
| // nothing, which loses the seam everywhere rather than where it was | ||||||||||||||||||||||||||||||||||||||||||||||||
| // undeclared. | ||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Asked for BY NAME, the answer is an error: `uphold shim faux ...` | ||||||||||||||||||||||||||||||||||||||||||||||||
| // names a shim this repository does not have, nothing is standing in | ||||||||||||||||||||||||||||||||||||||||||||||||
| // front of anything, and the caller is entitled to hear that rather | ||||||||||||||||||||||||||||||||||||||||||||||||
| // than watch a typo run. | ||||||||||||||||||||||||||||||||||||||||||||||||
| return match invoked { | ||||||||||||||||||||||||||||||||||||||||||||||||
| Invoked::AsTheCommand => exec_through(name, argv), | ||||||||||||||||||||||||||||||||||||||||||||||||
| Invoked::ByName => Err(Fatal::new(format!( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "no shim declares the command {name:?}; this policy declares {}", | ||||||||||||||||||||||||||||||||||||||||||||||||
| if shims.is_empty() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| String::from("none") | ||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| shims.keys().copied().collect::<Vec<&str>>().join(", ") | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| ))), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Only the rules that name THIS command line. A checker used to be | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -241,3 +241,62 @@ hooks = ["pre-commit"] | |||||||||||||||||||||||||||||||||||||||||||||||
| "a literal owner outside the first variant was never objected to:\n{report}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// A `refs/audit/pull/*` ref the forge no longer serves is not audited. | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// That destination is written by this subcommand and by nothing else, so a ref | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// left by an earlier run stays until something prunes it -- including after | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// `origin` is repointed at a different repository, which is when every ref | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// under it names a pull request the current forge never had. Read unpruned, | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// those commits are reported as `would be republished`, and the reader's only | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// fix is to delete something that was never published where the report says it | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// was. It is the same defect the branch half was fixed for, on the ref set that | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// half does not cover. | ||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||
| fn a_pull_ref_the_forge_no_longer_serves_is_not_audited() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let root = repository(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| // A real remote, because the fetch is what prunes: with no origin at all the | ||||||||||||||||||||||||||||||||||||||||||||||||
| // subcommand reports the surface unreadable and never walks a ref. | ||||||||||||||||||||||||||||||||||||||||||||||||
| let origin = | ||||||||||||||||||||||||||||||||||||||||||||||||
| std::env::temp_dir().join(format!("uphold-publication-origin-{}", std::process::id())); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = std::fs::remove_dir_all(&origin); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git(&root, &["init", "-q", "--bare", origin.to_str().unwrap()]); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git( | ||||||||||||||||||||||||||||||||||||||||||||||||
| &root, | ||||||||||||||||||||||||||||||||||||||||||||||||
| &["remote", "add", "origin", origin.to_str().unwrap()], | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| std::fs::write(root.join("a.txt"), "nothing to see\n").unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git(&root, &["add", "-A"]); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git(&root, &["commit", "-qm", "one", "--no-verify"]); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git(&root, &["push", "-q", "origin", "main"]); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // A commit the remote does not have, parked under the audit's own | ||||||||||||||||||||||||||||||||||||||||||||||||
| // destination the way a previous run against another forge would leave it. | ||||||||||||||||||||||||||||||||||||||||||||||||
| std::fs::write(root.join("STALE.md"), "PrivateOrg\n").unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git(&root, &["add", "-A"]); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git( | ||||||||||||||||||||||||||||||||||||||||||||||||
| &root, | ||||||||||||||||||||||||||||||||||||||||||||||||
| &[ | ||||||||||||||||||||||||||||||||||||||||||||||||
| "commit", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "-qm", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "a pull request on some other forge", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "--no-verify", | ||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let stale = Command::new("git") | ||||||||||||||||||||||||||||||||||||||||||||||||
| .args(["rev-parse", "HEAD"]) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .current_dir(&root) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .output() | ||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let stale = String::from_utf8_lossy(&stale.stdout).trim().to_owned(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git(&root, &["update-ref", "refs/audit/pull/9", &stale]); | ||||||||||||||||||||||||||||||||||||||||||||||||
| git(&root, &["reset", "-q", "--hard", "HEAD~1"]); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| let output = audit(&root); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let report = text(&output); | ||||||||||||||||||||||||||||||||||||||||||||||||
| assert!( | ||||||||||||||||||||||||||||||||||||||||||||||||
| !report.contains("STALE.md") && !report.contains("some other forge"), | ||||||||||||||||||||||||||||||||||||||||||||||||
| "a pruned pull ref was still read as a surface this forge serves:\n{report}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+296
to
+301
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 Assert that the stale destination ref was pruned. This assertion also passes when After Proposed test strengthening let output = audit(&root);
let report = text(&output);
+ let stale_ref = Command::new("git")
+ .args(["show-ref", "--verify", "--quiet", "refs/audit/pull/9"])
+ .current_dir(&root)
+ .status()
+ .unwrap();
+ assert!(!stale_ref.success(), "the stale audit pull ref was not pruned");
+ assert!(
+ report.contains("refs/pull/*/head fetched no commits")
+ && !report.contains("refs/pull/*/head could not be fetched"),
+ "the pull-ref fetch did not complete successfully:\n{report}"
+ );
assert!(
!report.contains("STALE.md") && !report.contains("some other forge"),As per coding guidelines, a constraint becomes machine enforcement only when it has observable evidence. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the no-policy explanation.
The paragraph includes the no-policy case, but Lines 484-485 state that “the policy was read.” No policy is read when discovery finds no policy. State that only the unrelated-shim case reads a policy.
🤖 Prompt for AI Agents