Compare commits

...
Author SHA1 Message Date
Abdul WahabandCursor b83a0480f6 Fix: Windows update line prompt (#760)
Raw-mode readline is Unix-only; Windows TTY sessions now use the
existing line-based prompt instead of aborting.

AI assistance: Cursor Grok 4.6, under maintainer direction.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 02:10:51 +05:00
Paul BakausandGitHub ea8bfc1d99 Fix Windows CSP candidate path normalization (#778)
* Test nested Windows CSP candidate paths

Regression coverage for #761 before the path-normalization fix.

AI assistance: Codex, under maintainer direction.

* Fix Windows CSP candidate path normalization

Normalize native relative paths before slash-based CSP classification and signal output. Preserve literal Unix backslashes.

AI assistance: Codex, under maintainer direction.

* Avoid reusing stale CSP test fixtures

Retry an unused test directory on AlreadyExists without deleting or reading any pre-existing fixture contents.

AI assistance: Codex, under maintainer direction.
2026-09-07 13:48:29 -07:00
2 changed files with 123 additions and 2 deletions
+90 -1
View File
@@ -167,7 +167,11 @@ fn walk(root: &str, dir: &str, depth: usize, hits: &mut Hits) {
let Ok(bytes) = std::fs::read(&abs) else { continue };
let slice = if bytes.len() > MAX_READ_BYTES { &bytes[..MAX_READ_BYTES] } else { &bytes[..] };
let body = String::from_utf8_lossy(slice);
visit(root, &abs, &jsp::relative("/", root, &abs), &body, hits);
// Candidate patterns use '/', while native Windows relative paths
// use '\\'. Normalize once for classification and portable signals;
// to_posix preserves literal backslashes in Unix filenames.
let rel = jsp::to_posix(&jsp::relative("/", root, &abs));
visit(root, &abs, &rel, &body, hits);
}
}
@@ -197,3 +201,88 @@ pub fn run(_args: &[String], io: &mut Io) -> i32 {
io.out(&format!("{}\n", json_pretty(&v)));
0
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
use std::sync::atomic::{AtomicUsize, Ordering};
static NEXT_FIXTURE: AtomicUsize = AtomicUsize::new(0);
struct Fixture(PathBuf);
impl Fixture {
fn new() -> Self {
loop {
let root = std::env::temp_dir().join(format!(
"impeccable-csp-761-{}-{}",
std::process::id(), NEXT_FIXTURE.fetch_add(1, Ordering::Relaxed),
));
match std::fs::create_dir(&root) {
Ok(()) => return Self(root),
// Never reuse or remove files left by another run.
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
Err(e) => panic!("create CSP fixture: {e}"),
}
}
}
fn scan(&self, path: &str, body: &str) -> Value {
let file = self.0.join(path);
std::fs::create_dir_all(file.parent().unwrap()).unwrap();
std::fs::write(file, body).unwrap();
detect_csp(self.0.to_str().unwrap())
}
}
impl Drop for Fixture {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.0);
}
}
#[test]
fn nested_csp_candidates_use_portable_paths() {
// Exercise the filesystem walker and native path.relative semantics,
// not just regexes with pre-normalized input. Windows CI reproduces #761.
for (path, body, shape) in [
("packages/app/src/security/csp.ts", "buildCSPConfig()", "append-arrays"),
("packages/app/src/next-config.ts", "createBaseNextConfig()", "append-arrays"),
("apps/web/svelte.config.js", "kit: { csp: { directives: {} } }", "append-arrays"),
("apps/web/nuxt.config.ts", "'nuxt-security'; contentSecurityPolicy", "append-arrays"),
("apps/web/next.config.mjs", "'Content-Security-Policy': 'script-src self; connect-src self'", "append-string"),
("next.config.mjs", "'Content-Security-Policy': 'script-src self; connect-src self'", "append-string"),
("apps/web/src/middleware.ts", "headers.set('Content-Security-Policy', policy)", "middleware"),
("apps/web/src/layout.astro", "<meta http-equiv='Content-Security-Policy'>", "meta-tag"),
] {
assert_eq!(Fixture::new().scan(path, body), serde_json::json!({
"shape": shape, "signals": [path],
}), "{path}");
}
}
#[test]
fn unrelated_nested_files_are_not_csp_candidates() {
for (path, body) in [
("packages/app/src/utils/csp.ts", "buildCSPConfig()"),
("apps/web/not-svelte.config.js", "kit: { csp: { directives: {} } }"),
("apps/web/next.config.mjs", "'Content-Security-Policy': 'script-src self'"),
] {
assert_eq!(Fixture::new().scan(path, body), serde_json::json!({
"shape": null, "signals": [],
}), "{path}");
}
}
#[cfg(unix)]
#[test]
fn posix_backslashes_remain_literal_filename_characters() {
let result = Fixture::new().scan(
"packages/app/src/config\\notes.ts", "buildCSPConfig()",
);
assert_eq!(result, serde_json::json!({
"shape": "append-arrays", "signals": ["packages/app/src/config\\notes.ts"],
}));
}
}
+33 -1
View File
@@ -35,6 +35,10 @@ impl Prompt {
self.stdin_tty && self.stdout_tty && cfg!(unix)
}
fn uses_tty_readline(&self, io: &Io) -> bool {
cfg!(unix) && self.stdout_tty && io.env("TERM") != Some("dumb")
}
fn ansi(&self, open: &str, close: &str, value: &str) -> String {
if self.style {
format!("{open}{value}{close}")
@@ -70,7 +74,7 @@ impl Prompt {
let next = self.piped.as_mut().and_then(|v| v.pop()).unwrap_or_default();
return Ok(next.trim().to_lowercase());
}
if self.stdout_tty && io.env("TERM") != Some("dumb") {
if self.uses_tty_readline(io) {
return self.tty_readline(io, question);
}
io.out(question);
@@ -624,6 +628,9 @@ fn terminal_rows() -> Option<u16> {
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::path::PathBuf;
use super::*;
#[test]
@@ -637,4 +644,29 @@ mod tests {
assert_eq!(visible_window(15, 16, 10), (6, 16));
assert_eq!(visible_window(2, 3, 10), (0, 3));
}
fn tty_prompt() -> Prompt {
Prompt { stdin_tty: true, stdout_tty: true, style: false, piped: None }
}
#[test]
fn ask_uses_raw_readline_only_on_unix() {
let prompt = tty_prompt();
let (io, _) = Io::captured("", PathBuf::from("."), HashMap::new());
assert_eq!(prompt.uses_tty_readline(&io), cfg!(unix));
}
#[cfg(not(unix))]
#[test]
fn ask_on_windows_tty_does_not_throw_unsupported() {
// Line fallback reads process stdin. Skip on a live console so the
// test cannot hang; CI pipes EOF and gets Ok("").
if std::io::IsTerminal::is_terminal(&std::io::stdin()) {
return;
}
let mut prompt = tty_prompt();
let (mut io, _) = Io::captured("", PathBuf::from("."), HashMap::new());
let result = prompt.ask(&mut io, "Update skills in 1 provider folder(s)? (Y/n) ");
assert_eq!(result, Ok(String::new()));
}
}