Test runner: isolated=false opt-out, ignore free text after the setup url
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4d4564b58
commit
96cb866d5c
4 files changed
+20
-3
No files matched your search
@@ -1642,7 +1642,7 @@ How to work:
|
||||
5. Also keep the file `setup.json` in your working directory: it tells the acceptance stage how to start the finished app, so the app can be checked by looking at it. Once the tech stack is settled write it, and update it when the stack changes. Format (one JSON object, all values strings, no comments):
|
||||
`{"install": "optional one-off setup command, e.g. npm ci", "start": "command that runs the app in the foreground", "url": "where it listens, e.g. http://localhost:8080"}`
|
||||
Ask the user for the port and commands if the spec leaves them open. A static site may use e.g. `"start": "python3 -m http.server 8080"`. Without a start command acceptance has to guess, so do not skip this file for anything that runs.
|
||||
Acceptance may run the app in a fresh throw-away container: then add `"image"` (a Docker image that has the toolchain for install/start, e.g. `node:22-bookworm`, `python:3.12`, `golang:1.23`) and, if the app needs a database or similar, `"services": {"db": {"image": "postgres:16", "env": {"POSTGRES_PASSWORD": "app"}}}` (reachable under the name `db`). Never write secrets there.
|
||||
Acceptance may run the app in a fresh throw-away container: then add `"image"` (a Docker image that has the toolchain for install/start, e.g. `node:22-bookworm`, `python:3.12`, `golang:1.23`) and, if the app needs a database or similar, `"services": {"db": {"image": "postgres:16", "env": {"POSTGRES_PASSWORD": "app"}}}` (reachable under the name `db`). Use `"ready_seconds"` for apps that need long to install and start. The app must listen on 0.0.0.0, not only 127.0.0.1. For something that cannot run in a container (a native desktop window, a library) set `"isolated": false`. Never write secrets there.
|
||||
6. When the user says the spec is done, propose a short project name and a repository slug (lowercase, digits and dashes) and end your message with exactly one fenced json block and nothing after it:
|
||||
```json
|
||||
{"decision": "ready", "name": "Project name", "slug": "project-name", "description": "one sentence"}
|
||||
|
||||
@@ -75,6 +75,10 @@ pub struct Started {
|
||||
/// Parse `.factory/setup.json` into a request (without `work`). `None` when there is nothing to start.
|
||||
pub fn parse_setup(text: &str) -> Option<StartReq> {
|
||||
let v: Value = serde_json::from_str(text).ok()?;
|
||||
// `"isolated": false`: the app cannot run in a container (e.g. a native window); acceptance starts it itself.
|
||||
if v["isolated"].as_bool() == Some(false) {
|
||||
return None;
|
||||
}
|
||||
let start = v["start"].as_str()?.trim().to_string();
|
||||
if start.is_empty() {
|
||||
return None;
|
||||
@@ -111,8 +115,9 @@ pub fn parse_setup(text: &str) -> Option<StartReq> {
|
||||
|
||||
/// Port of `http://host:1234/path` (80/443 by scheme when missing).
|
||||
pub fn port_of(url: &str) -> Option<u16> {
|
||||
let (scheme, rest) = url.split_once("://")?;
|
||||
let host = rest.split('/').next()?;
|
||||
let (scheme, rest) = url.trim().split_once("://")?;
|
||||
// Free text after the URL ("http://localhost:8080 (trunk serve)") is ignored.
|
||||
let host = rest.split(|c: char| c == '/' || c.is_whitespace()).next()?;
|
||||
match host.rsplit_once(':') {
|
||||
Some((_, p)) if p.chars().all(|c| c.is_ascii_digit()) && !p.is_empty() => p.parse().ok(),
|
||||
_ => Some(if scheme == "https" { 443 } else { 80 }),
|
||||
@@ -548,6 +553,8 @@ mod tests {
|
||||
assert_eq!(port_of("http://localhost"), Some(80));
|
||||
assert_eq!(port_of("https://x/y"), Some(443));
|
||||
assert_eq!(port_of("nonsense"), None);
|
||||
assert_eq!(port_of("http://localhost:8080 (web build: trunk serve)"), Some(8080));
|
||||
assert!(parse_setup(r#"{"start":"x","port":1,"isolated":false}"#).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user