mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 11:15:01 +03:00
refactor(frontend): tighten harness gate, ratchet prefixes, and move icon
Check (package, kind, name) tuples for harness Cargo targets in check-invariants.sh. Duplicate target names of another kind now fail the check. Add desktop.app_tabs.tab., desktop.split.resize., and desktop.explorer.group. to ZERO_IN_PRODUCTION. Update the snapshot prefix test count to 68. Extract PresentationIcon into ui_tokens::icons::PRESENTATION. Replace the inline SVG in edgeless/present.rs with that static icon definition.
This commit is contained in:
1 parent
d0f4d0b0ec
commit
b817bd251d
6 files changed
+66
-8
No files matched your search
@@ -299,7 +299,7 @@ impl PlaygroundView {
|
||||
}
|
||||
|
||||
// Source: PresentationIcon in @blocksuite/icons 2.2.17.
|
||||
pub const PRESENTATION_ICON: &[u8] = br#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"><path fill="currentColor" fill-rule="evenodd" d="M3.174 3.952c0-.426.346-.772.772-.772h15.957a.772.772 0 0 1 0 1.544h-.368v9.853h.367a.772.772 0 0 1 0 1.545h-7.206v1.661l3.942 2.252a.772.772 0 1 1-.766 1.341l-3.176-1.815v1.487a.772.772 0 0 1-1.544 0v-1.421l-3.062 1.75a.772.772 0 1 1-.766-1.341l3.828-2.188v-1.726H3.946a.772.772 0 1 1 0-1.545h.368V4.724h-.368a.77.77 0 0 1-.772-.772m2.684.772h12.133v9.853H5.858zm3.42 4.357a.772.772 0 0 0-1.545 0v2.28a.772.772 0 0 0 1.544 0zm2.646-2.482c.427 0 .772.346.772.772v3.99a.772.772 0 0 1-1.544 0V7.37c0-.426.346-.772.772-.772m4.192 3.622a.772.772 0 0 0-1.545 0v1.14a.772.772 0 1 0 1.545 0z" clip-rule="evenodd"/></svg>"#;
|
||||
pub const PRESENTATION_ICON: &[u8] = crate::theme::icons::PRESENTATION.svg.as_bytes();
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
@@ -723,4 +723,42 @@ mod tests {
|
||||
assert_eq!(*events.borrow(), [true, false]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presentation_production_code_has_no_inline_svg_and_matches_legacy_mask() {
|
||||
use ui::{DevicePixels, HeadlessPlatform, SvgSize, size};
|
||||
|
||||
let source = include_str!("present.rs");
|
||||
let (production, _) = source
|
||||
.split_once("\n#[cfg(test)]\n")
|
||||
.expect("present.rs must contain #[cfg(test)] module");
|
||||
assert!(
|
||||
!production.contains("<svg"),
|
||||
"production code in present.rs must not contain inline <svg"
|
||||
);
|
||||
|
||||
const LEGACY_PRESENTATION: &[u8] = br#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"><path fill="currentColor" fill-rule="evenodd" d="M3.174 3.952c0-.426.346-.772.772-.772h15.957a.772.772 0 0 1 0 1.544h-.368v9.853h.367a.772.772 0 0 1 0 1.545h-7.206v1.661l3.942 2.252a.772.772 0 1 1-.766 1.341l-3.176-1.815v1.487a.772.772 0 0 1-1.544 0v-1.421l-3.062 1.75a.772.772 0 1 1-.766-1.341l3.828-2.188v-1.726H3.946a.772.772 0 1 1 0-1.545h.368V4.724h-.368a.77.77 0 0 1-.772-.772m2.684.772h12.133v9.853H5.858zm3.42 4.357a.772.772 0 0 0-1.545 0v2.28a.772.772 0 0 0 1.544 0zm2.646-2.482c.427 0 .772.346.772.772v3.99a.772.772 0 0 1-1.544 0V7.37c0-.426.346-.772.772-.772m4.192 3.622a.772.772 0 0 0-1.545 0v1.14a.772.772 0 1 0 1.545 0z" clip-rule="evenodd"/></svg>"#;
|
||||
let platform = HeadlessPlatform::new(64, 64, 1.0);
|
||||
let app = ui::Application::with_platform(platform).run_embedded(|_| {});
|
||||
let renderer = app.update(|cx| cx.svg_renderer());
|
||||
let alpha_mask = |svg_bytes: &[u8]| -> Vec<u8> {
|
||||
let parsed = renderer.parse_svg(svg_bytes).expect("parse icon svg");
|
||||
let image = renderer
|
||||
.render_parsed(
|
||||
&parsed,
|
||||
SvgSize::ExactSize(size(DevicePixels(48), DevicePixels(48))),
|
||||
)
|
||||
.expect("rasterize icon svg");
|
||||
image
|
||||
.as_bytes(0)
|
||||
.expect("rendered frame bytes")
|
||||
.chunks_exact(4)
|
||||
.map(|bgra| bgra[3])
|
||||
.collect()
|
||||
};
|
||||
assert_eq!(
|
||||
alpha_mask(PRESENTATION_ICON),
|
||||
alpha_mask(LEGACY_PRESENTATION)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -73,8 +73,9 @@ for pkg in meta["packages"]:
|
||||
if pkg["id"] not in members:
|
||||
continue
|
||||
for target in pkg["targets"]:
|
||||
if target_kinds.intersection(target["kind"]) and "harness" in target.get("required-features", []):
|
||||
targets.add(target["name"])
|
||||
if "harness" in target.get("required-features", []):
|
||||
for kind in target_kinds.intersection(target["kind"]):
|
||||
targets.add((pkg["name"], kind, target["name"]))
|
||||
test_dir = Path(pkg["manifest_path"]).parent / "tests"
|
||||
for path in test_dir.rglob("*.rs"):
|
||||
if any(
|
||||
@@ -83,7 +84,11 @@ for pkg in meta["packages"]:
|
||||
):
|
||||
integration_tests.add(path.relative_to(repo_root).as_posix())
|
||||
|
||||
expected_targets = {"bs-harness", "desktop-harness", "mobile-harness"}
|
||||
expected_targets = {
|
||||
("playground", "bin", "bs-harness"),
|
||||
("affine-desktop", "bin", "desktop-harness"),
|
||||
("affine-mobile", "bin", "mobile-harness"),
|
||||
}
|
||||
expected_integration_tests = {
|
||||
"packages/ui/ui/tests/bidi_multiline_controls.rs",
|
||||
"packages/ui/ui/tests/metal_atlas_fence.rs",
|
||||
|
||||
@@ -85,6 +85,9 @@ export const ZERO_IN_PRODUCTION = Object.freeze([
|
||||
'desktop.trash.restore.',
|
||||
'desktop.trash.delete.',
|
||||
'desktop.inspector.journal.day.',
|
||||
'desktop.app_tabs.tab.',
|
||||
'desktop.split.resize.',
|
||||
'desktop.explorer.group.',
|
||||
]);
|
||||
|
||||
const WASM_MAGIC = new Uint8Array([0x00, 0x61, 0x73, 0x6d]);
|
||||
|
||||
@@ -38,6 +38,9 @@ const NEW_DESKTOP_PREFIXES = [
|
||||
'desktop.trash.restore.',
|
||||
'desktop.trash.delete.',
|
||||
'desktop.inspector.journal.day.',
|
||||
'desktop.app_tabs.tab.',
|
||||
'desktop.split.resize.',
|
||||
'desktop.explorer.group.',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -138,15 +141,15 @@ test('rejects bare snapshot container IDs in Wasm Data segments', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('verifies all 65 live prefixes including desktop production sources', () => {
|
||||
assert.equal(ZERO_IN_PRODUCTION.length, 65);
|
||||
test('verifies all 68 live prefixes including desktop production sources', () => {
|
||||
assert.equal(ZERO_IN_PRODUCTION.length, 68);
|
||||
const result = verifySourcePrefixes();
|
||||
assert.equal(
|
||||
result.ok,
|
||||
true,
|
||||
`Missing prefixes in repo: ${result.missing.join(', ')}`
|
||||
);
|
||||
assert.equal(Object.keys(result.counts).length, 65);
|
||||
assert.equal(Object.keys(result.counts).length, 68);
|
||||
for (const prefix of [...DESKTOP_PREFIXES, ...NEW_DESKTOP_PREFIXES]) {
|
||||
assert.ok(
|
||||
result.counts[prefix] >= 1,
|
||||
@@ -270,7 +273,7 @@ test('fails CLI gate on desktop prefixes in Section 11 and ignores custom/code s
|
||||
encoding: 'utf8',
|
||||
});
|
||||
assert.equal(passRun.status, 0, passRun.stderr);
|
||||
assert.match(passRun.stdout, /65\/65 prefixes at 0/);
|
||||
assert.match(passRun.stdout, /68\/68 prefixes at 0/);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ const CORE_ICONS = [
|
||||
['LAYER', 'LayerIcon'],
|
||||
['STOP_AI', 'StopAiIcon'],
|
||||
['EXPAND_CLOSE', 'ExpandCloseIcon'],
|
||||
['PRESENTATION', 'PresentationIcon'],
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -1123,6 +1124,7 @@ mod tests {
|
||||
assert_eq!(icon_by_name("LayerIcon"), Some(&LAYER));
|
||||
assert_eq!(icon_by_name("StopAiIcon"), Some(&STOP_AI));
|
||||
assert_eq!(icon_by_name("ExpandCloseIcon"), Some(&EXPAND_CLOSE));
|
||||
assert_eq!(icon_by_name("PresentationIcon"), Some(&PRESENTATION));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -533,6 +533,11 @@ pub const EXPAND_CLOSE: IconDef = IconDef {
|
||||
svg: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M20.53 3.47a.75.75 0 0 1 0 1.06l-4.22 4.22h2.19a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1-.75-.75v-4a.75.75 0 0 1 1.5 0v2.19l4.22-4.22a.75.75 0 0 1 1.06 0M5.5 15.25a.75.75 0 0 1 0-1.5h4a.75.75 0 0 1 .75.75v4a.75.75 0 0 1-1.5 0v-2.19l-4.22 4.22a.75.75 0 0 1-1.06-1.06l4.22-4.22z\" fill=\"#000\" fill-rule=\"evenodd\" clip-rule=\"evenodd\"/></svg>",
|
||||
};
|
||||
|
||||
pub const PRESENTATION: IconDef = IconDef {
|
||||
name: "PresentationIcon",
|
||||
svg: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M3.174 3.952c0-.426.346-.772.772-.772h15.957a.772.772 0 0 1 0 1.544h-.368v9.853h.367a.772.772 0 0 1 0 1.545h-7.206v1.661l3.942 2.252a.772.772 0 1 1-.766 1.341l-3.176-1.815v1.487a.772.772 0 0 1-1.544 0v-1.421l-3.062 1.75a.772.772 0 1 1-.766-1.341l3.828-2.188v-1.726H3.946a.772.772 0 1 1 0-1.545h.368V4.724h-.368a.77.77 0 0 1-.772-.772m2.684.772h12.133v9.853H5.858zm3.42 4.357a.772.772 0 0 0-1.545 0v2.28a.772.772 0 0 0 1.544 0zm2.646-2.482c.427 0 .772.346.772.772v3.99a.772.772 0 0 1-1.544 0V7.37c0-.426.346-.772.772-.772m4.192 3.622a.772.772 0 0 0-1.545 0v1.14a.772.772 0 1 0 1.545 0z\" fill=\"#000\" fill-rule=\"evenodd\" clip-rule=\"evenodd\"/></svg>",
|
||||
};
|
||||
|
||||
pub const ALL_ICONS: &[IconDef] = &[
|
||||
ADD_TEXT,
|
||||
ALL_DOCS,
|
||||
@@ -608,6 +613,7 @@ pub const ALL_ICONS: &[IconDef] = &[
|
||||
PAGE,
|
||||
PEN,
|
||||
PLUS,
|
||||
PRESENTATION,
|
||||
QUOTE,
|
||||
REDO,
|
||||
RIGHT_TAB,
|
||||
@@ -689,6 +695,7 @@ mod tests {
|
||||
assert_eq!(icon_by_name("LayerIcon"), Some(&LAYER));
|
||||
assert_eq!(icon_by_name("StopAiIcon"), Some(&STOP_AI));
|
||||
assert_eq!(icon_by_name("ExpandCloseIcon"), Some(&EXPAND_CLOSE));
|
||||
assert_eq!(icon_by_name("PresentationIcon"), Some(&PRESENTATION));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user