diff --git a/crates/live/src/live_accept.rs b/crates/live/src/live_accept.rs index 7844af0593..d6a0e6012d 100644 --- a/crates/live/src/live_accept.rs +++ b/crates/live/src/live_accept.rs @@ -2,6 +2,7 @@ //! accept/discard of variant sessions: HTML/JSX wrapper carbonize, the //! Svelte component inline path, receipts, source locks, buffer scrub. +use crate::inject::resolve_source_traits; use crate::paths::{live_dir, safe_session_id}; use crate::pending_edits::{read_buffer, write_buffer}; use crate::roots::enter_live_root; @@ -670,11 +671,33 @@ fn handle_discard_unlocked(id: &str, lines: &[String], target_file: &str) -> Res Ok(()) } +/// The opening `", + "
", + "

Title

", + "
", + "
", + "

Title

", + "
", + " ", + " ", + " ", + "", + "", + ] + .iter() + .map(|s| s.to_string()) + .collect() + } + + fn carbonize(file_name: &str, style_open: &str) -> String { + let nanos = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_nanos()) + .unwrap_or(0); + let dir = std::env::temp_dir().join(format!("impeccable-carbonize-{}-{nanos}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let file = dir.join(file_name); + let lines = wrapped(style_open); + std::fs::write(&file, lines.join("\n")).unwrap(); + let outcome = handle_accept_unlocked("ab12cd34", "2", &lines, &file.to_string_lossy(), None, None); + let out = std::fs::read_to_string(&file).unwrap(); + let _ = std::fs::remove_dir_all(&dir); + assert!( + matches!(outcome, Ok(AcceptOutcome::Carbonized { carbonize: true, .. })), + "accept did not carbonize: {out}" + ); + out + } + + /// Every ``, `{/* … */}` comments, `style={{ display: 'contents' }}` on the variant div. Result `{handled:true, file: rel, carbonize:boolean, todo?:'REQUIRED before next poll: carbonize cleanup in . See reference/live.md "Required after accept".', bakeSkipped?}`. Discard: replace range with deindented original → `{handled:true, file, carbonize:false}`. diff --git a/tests/framework-fixtures/astro-vite7/files/package.json b/tests/framework-fixtures/astro-vite7/files/package.json index ae52e5ae92..bd826d09a1 100644 --- a/tests/framework-fixtures/astro-vite7/files/package.json +++ b/tests/framework-fixtures/astro-vite7/files/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "7.3.5" + "astro": "^7.1.0" } } diff --git a/tests/oracle/cases/live-accept.mjs b/tests/oracle/cases/live-accept.mjs index a9af86b891..eeeafde000 100644 --- a/tests/oracle/cases/live-accept.mjs +++ b/tests/oracle/cases/live-accept.mjs @@ -7,7 +7,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { - LIVE_FILES, linkSvelte, lockPathFor, stageWrappedHtml, stageWrappedJsx, write, writeBuffer, + LIVE_FILES, linkSvelte, lockPathFor, stageWrappedAstro, stageWrappedHtml, stageWrappedJsx, write, writeBuffer, } from '../live-helpers.mjs'; const F = LIVE_FILES; @@ -45,6 +45,10 @@ export default [ fs.writeFileSync(p, fs.readFileSync(p, 'utf8').replace(/ {8}\n \n \n
\n

Astro Fixture

\n
\n

Minimal Astro tree for oracle live-mode goldens.

\n
\n
One
\n
Two
\n
\n \n\n" + } +} diff --git a/tests/oracle/live-helpers.mjs b/tests/oracle/live-helpers.mjs index 6590944646..42d1da0f1c 100644 --- a/tests/oracle/live-helpers.mjs +++ b/tests/oracle/live-helpers.mjs @@ -148,6 +148,31 @@ export function stageWrappedHtml(ws, id = 'ab12cd34') { fs.writeFileSync(file, src.replace(' ' + original, block)); } +/** + * live-astro src/pages/index.astro with the hero h1 wrapped and variants + * written the way an agent writes them for `styleMode: astro-global-prefixed`: + * an `is:inline` style tag and variant-prefixed selectors, no `@scope`. + */ +export function stageWrappedAstro(ws, id = 'ab12cd34') { + const file = path.join(ws, 'src', 'pages', 'index.astro'); + const src = fs.readFileSync(file, 'utf8'); + const original = '

Astro Fixture

'; + const indent = ' '; + const css = [ + '[data-impeccable-variant="1"] > h1 { font-weight: 300; color: oklch(var(--p-lightness, 0.5) 0.25 25); }', + '[data-impeccable-variant="2"] > h1 { font-weight: 900; }', + '[data-impeccable-variant="2"][data-p-face="serif"] > h1 { font-family: ui-serif, serif; }', + '[data-impeccable-variant="3"] > h1 { font-weight: 600; text-transform: uppercase; }', + ]; + const block = wrappedBlock({ id, tag: 'h1', inner: original, original, indent }) + .replace(/', + ].join('\n')); + fs.writeFileSync(file, src.replace(indent + original, block)); +} + /** live-vite src/App.jsx with the hero h1 wrapped and variants written (JSX syntax). */ export function stageWrappedJsx(ws, id = 'ab12cd34') { const file = path.join(ws, 'src', 'App.jsx');