35cd0657bd
Replace the placeholder browser script with the PLAN.md upload flow. The static UI now creates upload records, slices the selected file into fixed-size chunks, uploads missing chunks with a concurrency pool of three workers, retries failed chunks with exponential backoff, pauses via AbortController, and completes the upload once the server has accepted every chunk. Persist pending upload records in IndexedDB and render them in the page so a reload can resume from server-authoritative progress. When the File System Access API is available, the app stores a file handle and asks for read permission during resume; when it is unavailable or permission is denied, the same pending record resumes after the user reselects the matching file. Browser state is helpful but not trusted: every resume starts by querying the server for completed chunks. Add a JavaScript syntax check to the justfile, update the static-page test and documentation, and extend TESTS.md with the manual resume scenarios that still need real-browser repetition. Test Plan: - just check - UPL_BIND=127.0.0.1:39123 UPL_DATA_DIR=$(mktemp -d) cargo run - curl -fsS http://127.0.0.1:39123/healthz - curl -fsS http://127.0.0.1:39123/ | rg "Choose file|Pending uploads|app.js" - firefox --headless --screenshot /tmp/upl-page.png http://127.0.0.1:39123/ Refs: PLAN.md milestones 5, 6, and 7
54 lines
1.4 KiB
Rust
54 lines
1.4 KiB
Rust
use std::{
|
|
net::{Ipv4Addr, SocketAddr},
|
|
path::Path,
|
|
};
|
|
|
|
use axum::{body::Body, http::Request};
|
|
use http_body_util::BodyExt;
|
|
use tower::ServiceExt;
|
|
use upl::app::{AppConfig, build_router};
|
|
|
|
#[tokio::test]
|
|
async fn serves_index_page() -> Result<(), Box<dyn std::error::Error>> {
|
|
let app = test_app();
|
|
|
|
let response = app
|
|
.oneshot(Request::builder().uri("/").body(Body::empty())?)
|
|
.await?;
|
|
|
|
assert_eq!(response.status(), axum::http::StatusCode::OK);
|
|
|
|
let body = response.into_body().collect().await?.to_bytes();
|
|
let body = String::from_utf8(body.to_vec())?;
|
|
|
|
assert!(body.contains("<title>upl</title>"));
|
|
assert!(body.contains("Choose file"));
|
|
assert!(body.contains("Pending uploads"));
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn reports_health() -> Result<(), Box<dyn std::error::Error>> {
|
|
let app = test_app();
|
|
|
|
let response = app
|
|
.oneshot(Request::builder().uri("/healthz").body(Body::empty())?)
|
|
.await?;
|
|
|
|
assert_eq!(response.status(), axum::http::StatusCode::OK);
|
|
|
|
let body = response.into_body().collect().await?.to_bytes();
|
|
assert_eq!(body.as_ref(), b"ok");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn test_app() -> axum::Router {
|
|
build_router(&AppConfig::new(
|
|
SocketAddr::from((Ipv4Addr::LOCALHOST, 0)),
|
|
concat!(env!("CARGO_MANIFEST_DIR"), "/static"),
|
|
Path::new(env!("CARGO_MANIFEST_DIR")).join("target/test-data/static-server"),
|
|
))
|
|
}
|