Skip to content

Commit 369f585

Browse files
feat: make svg output reproducible
1 parent 4114429 commit 369f585

16 files changed

+203
-160
lines changed

Cargo.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ regex = "1.12.2"
5555
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
5656
assert_cmd = "2.1.1"
5757
libtest-mimic = "0.8.1"
58+
similar-asserts = "1.7.0"
5859
tempfile = "3"
5960

6061
[dev-dependencies]

src/diagram.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ impl Diagram {
441441
svg.push_str(" </g>\n");
442442
}
443443
}
444+
for id in &self.order {
445+
let node = self.nodes.get(id).unwrap();
444446

445-
for (id, node) in &self.nodes {
446447
let position = geometry
447448
.positions
448449
.get(id)

tests/cli.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use assert_cmd::cargo::cargo_bin_cmd;
88
#[cfg(not(target_arch = "wasm32"))]
99
use libtest_mimic::Failed;
1010
#[cfg(not(target_arch = "wasm32"))]
11+
use similar_asserts::SimpleDiff;
12+
#[cfg(not(target_arch = "wasm32"))]
1113
use tempfile::TempDir;
1214

1315
#[cfg(target_arch = "wasm32")]
@@ -43,10 +45,10 @@ fn main() {
4345
[
4446
libtest_mimic::Trial::test(format!("svg_{stem}"), {
4547
let in_path = in_path.clone();
46-
let out_path = manifest_dir
47-
.join("tests/output/svg")
48+
let expected_path = manifest_dir
49+
.join("tests/expected")
4850
.join(format!("{stem}.svg"));
49-
move || smoke_test_svg(in_path, out_path)
51+
move || test_svg(in_path, expected_path)
5052
}),
5153
libtest_mimic::Trial::test(format!("png_{stem}"), {
5254
let in_path = in_path.clone();
@@ -61,10 +63,11 @@ fn main() {
6163
}
6264

6365
#[cfg(not(target_arch = "wasm32"))]
64-
fn smoke_test_svg(in_path: PathBuf, out_path: PathBuf) -> Result<(), Failed> {
65-
if out_path.exists() {
66-
fs::remove_file(&out_path)?;
67-
}
66+
fn test_svg(in_path: PathBuf, expected_path: PathBuf) -> Result<(), Failed> {
67+
let temp_dir = TempDir::new().expect("create temp dir");
68+
69+
let stem = in_path.file_stem().unwrap().to_str().unwrap();
70+
let out_path = temp_dir.path().join(format!("{stem}.svg"));
6871

6972
let mut cmd = cargo_bin_cmd!("oxdraw");
7073
cmd.arg("--input")
@@ -76,12 +79,23 @@ fn smoke_test_svg(in_path: PathBuf, out_path: PathBuf) -> Result<(), Failed> {
7679

7780
cmd.assert().success();
7881

79-
let svg_contents = fs::read_to_string(&out_path)?;
80-
assert!(
81-
svg_contents.contains("<svg"),
82-
"{} output should contain an <svg> element",
83-
out_path.display()
84-
);
82+
let actual = fs::read_to_string(&out_path)?;
83+
84+
if std::env::var("UPDATE_EXPECTED").is_ok() {
85+
fs::write(expected_path, actual)?;
86+
return Ok(());
87+
}
88+
89+
let expected = fs::read_to_string(&expected_path)?;
90+
91+
if expected != actual {
92+
let diff = format!(
93+
"{}",
94+
SimpleDiff::from_str(&actual, &expected, "actual", "expected")
95+
);
96+
return Err(diff.into());
97+
}
98+
8599
Ok(())
86100
}
87101

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,34 @@
4141
<rect x="273.8" y="2154.8" width="38.2" height="28.0" rx="6" ry="6" fill="white" fill-opacity="0.96" stroke="#2d3748" stroke-width="1" />
4242
<text x="292.9" y="2168.8" fill="#2d3748" font-size="13" text-anchor="middle" dominant-baseline="middle" xml:space="preserve">无反馈</text>
4343
</g>
44-
<rect x="188.6" y="1601.0" width="148.8" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
45-
<text x="263.0" y="1626.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.3 规范文档生成引擎</text>
46-
<rect x="173.8" y="617.0" width="178.4" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
47-
<text x="263.0" y="642.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.1.1 跨模态融合与冲突检测</text>
44+
<ellipse cx="263.0" cy="150.0" rx="70.0" ry="70.0" fill="#e9d8fd" stroke="#2d3748" stroke-width="2" />
45+
<text x="263.0" y="150.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">开始</text>
46+
<rect x="193.0" y="289.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
47+
<text x="263.0" y="314.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">接收多模态输入</text>
4848
<rect x="184.9" y="453.0" width="156.2" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
4949
<text x="263.0" y="478.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.1 多模态输入理解引擎</text>
50-
<rect x="192.3" y="1929.0" width="141.4" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
51-
<text x="263.0" y="1954.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.4 规范一致性验证</text>
50+
<rect x="173.8" y="617.0" width="178.4" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
51+
<text x="263.0" y="642.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.1.1 跨模态融合与冲突检测</text>
52+
<rect x="193.0" y="781.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
53+
<text x="263.0" y="806.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">生成统一需求表示</text>
54+
<rect x="184.9" y="945.0" width="156.2" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
55+
<text x="263.0" y="970.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.2 需求完整性检查引擎</text>
5256
<polygon points="263.0,1109.0 333.0,1134.0 263.0,1159.0 193.0,1134.0" fill="#fbcfe8" stroke="#2d3748" stroke-width="2" />
5357
<text x="263.0" y="1134.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">发现缺失或冲突?</text>
54-
<ellipse cx="343.7" cy="2282.0" rx="70.0" ry="70.0" fill="#e9d8fd" stroke="#2d3748" stroke-width="2" />
55-
<text x="343.7" y="2282.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">结束</text>
56-
<rect x="193.0" y="1437.0" width="140.0" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
57-
<text x="263.0" y="1462.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">等待用户澄清</text>
5858
<rect x="193.0" y="1273.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
5959
<text x="263.0" y="1298.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">生成澄清问题列表</text>
60-
<ellipse cx="263.0" cy="150.0" rx="70.0" ry="70.0" fill="#e9d8fd" stroke="#2d3748" stroke-width="2" />
61-
<text x="263.0" y="150.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">开始</text>
62-
<rect x="184.9" y="945.0" width="156.2" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
63-
<text x="263.0" y="970.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.2 需求完整性检查引擎</text>
60+
<rect x="193.0" y="1437.0" width="140.0" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
61+
<text x="263.0" y="1462.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">等待用户澄清</text>
62+
<rect x="188.6" y="1601.0" width="148.8" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
63+
<text x="263.0" y="1626.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.3 规范文档生成引擎</text>
6464
<rect x="193.0" y="1765.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
6565
<text x="263.0" y="1790.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">生成完整规范文档</text>
66-
<rect x="112.3" y="2257.0" width="141.4" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
67-
<text x="183.0" y="2282.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.5 交互式规范细化</text>
66+
<rect x="192.3" y="1929.0" width="141.4" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
67+
<text x="263.0" y="1954.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.4 规范一致性验证</text>
6868
<polygon points="263.0,2093.0 333.0,2118.0 263.0,2143.0 193.0,2118.0" fill="#fbcfe8" stroke="#2d3748" stroke-width="2" />
6969
<text x="263.0" y="2118.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">等待用户反馈</text>
70-
<rect x="193.0" y="781.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
71-
<text x="263.0" y="806.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">生成统一需求表示</text>
72-
<rect x="193.0" y="289.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
73-
<text x="263.0" y="314.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">接收多模态输入</text>
70+
<rect x="112.3" y="2257.0" width="141.4" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
71+
<text x="183.0" y="2282.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">6.5 交互式规范细化</text>
72+
<ellipse cx="343.7" cy="2282.0" rx="70.0" ry="70.0" fill="#e9d8fd" stroke="#2d3748" stroke-width="2" />
73+
<text x="343.7" y="2282.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">结束</text>
7474
</svg>
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@
3636
<line x1="1048.6" y1="381.1" x2="1115.2" y2="351.6" stroke="#2d3748" stroke-width="2" marker-end="url(#arrow-end)" />
3737
<line x1="1250.4" y1="326.1" x2="1269.4" y2="326.1" stroke="#2d3748" stroke-width="2" marker-end="url(#arrow-end)" />
3838
<polyline points="1323.5,301.1 1102.3,80.0 856.2,80.0 610.1,80.0 384.6,305.4" fill="none" stroke="#2d3748" stroke-width="2" marker-end="url(#arrow-end)" />
39+
<rect x="80.0" y="301.1" width="163.6" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
40+
<text x="161.8" y="326.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Deploy Release</text>
3941
<polygon points="363.9,301.1 464.2,326.1 363.9,351.1 263.6,326.1" fill="#fbcfe8" stroke="#2d3748" stroke-width="2" />
4042
<text x="363.9" y="326.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Health Checks Pass?</text>
41-
<rect x="484.2" y="381.1" width="193.2" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
42-
<text x="580.8" y="406.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Continuous Monitor</text>
43-
<rect x="910.6" y="381.1" width="163.6" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
44-
<text x="992.4" y="406.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Follow Runbook</text>
45-
<polygon points="794.0,381.1 890.6,406.1 794.0,431.1 697.4,406.1" fill="#fbcfe8" stroke="#2d3748" stroke-width="2" />
46-
<text x="794.0" y="406.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Incident Detected?</text>
4743
<rect x="491.6" y="221.1" width="178.4" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
4844
<text x="580.8" y="246.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Trigger Rollback</text>
49-
<rect x="1270.4" y="301.1" width="156.2" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
50-
<text x="1348.5" y="326.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Deploy Hotfix</text>
5145
<rect x="723.3" y="221.1" width="141.4" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
5246
<text x="794.0" y="246.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Notify Team</text>
47+
<rect x="484.2" y="381.1" width="193.2" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
48+
<text x="580.8" y="406.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Continuous Monitor</text>
49+
<polygon points="794.0,381.1 890.6,406.1 794.0,431.1 697.4,406.1" fill="#fbcfe8" stroke="#2d3748" stroke-width="2" />
50+
<text x="794.0" y="406.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Incident Detected?</text>
5351
<rect x="922.4" y="221.1" width="140.0" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
5452
<text x="992.4" y="246.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Stable</text>
53+
<rect x="910.6" y="381.1" width="163.6" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
54+
<text x="992.4" y="406.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Follow Runbook</text>
5555
<rect x="1094.2" y="301.1" width="156.2" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
5656
<text x="1172.3" y="326.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Create Hotfix</text>
57-
<rect x="80.0" y="301.1" width="163.6" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
58-
<text x="161.8" y="326.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Deploy Release</text>
57+
<rect x="1270.4" y="301.1" width="156.2" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
58+
<text x="1348.5" y="326.1" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Deploy Hotfix</text>
5959
</svg>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
</g>
3333
<rect x="240.0" y="80.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
3434
<text x="310.0" y="105.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Start</text>
35-
<rect x="240.0" y="560.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
36-
<text x="310.0" y="585.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Python</text>
35+
<rect x="240.0" y="240.0" width="140.0" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
36+
<text x="310.0" y="265.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Idea</text>
37+
<polygon points="310.0,400.0 380.0,425.0 310.0,450.0 240.0,425.0" fill="#fbcfe8" stroke="#2d3748" stroke-width="2" />
38+
<text x="310.0" y="425.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Lang?</text>
3739
<rect x="80.0" y="560.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
3840
<text x="150.0" y="585.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Go</text>
41+
<rect x="240.0" y="560.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
42+
<text x="310.0" y="585.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Python</text>
3943
<rect x="400.0" y="560.0" width="140.0" height="50.0" rx="8" ry="8" fill="#fde68a" stroke="#2d3748" stroke-width="2" />
4044
<text x="470.0" y="585.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Rust</text>
41-
<polygon points="310.0,400.0 380.0,425.0 310.0,450.0 240.0,425.0" fill="#fbcfe8" stroke="#2d3748" stroke-width="2" />
42-
<text x="310.0" y="425.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Lang?</text>
43-
<rect x="240.0" y="240.0" width="140.0" height="50.0" rx="30" ry="30" fill="#c4f1f9" stroke="#2d3748" stroke-width="2" />
44-
<text x="310.0" y="265.0" fill="#1a202c" font-size="14" text-anchor="middle" dominant-baseline="middle">Idea</text>
4545
</svg>

0 commit comments

Comments
 (0)