mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-03 22:41:38 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69168763d0 | ||
|
|
abdbc32e80 |
@@ -0,0 +1,79 @@
|
||||
param([Parameter(Mandatory)][string]$Binary)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if ($env:GITHUB_ACTIONS -ne 'true' -or $env:RUNNER_OS -ne 'Windows' -or $env:RUNNER_ENVIRONMENT -ne 'github-hosted') {
|
||||
throw 'This capture uses the spooler of a disposable hosted Windows machine.'
|
||||
}
|
||||
$Binary = (Resolve-Path -LiteralPath $Binary).Path
|
||||
$driver = 'Microsoft Print to PDF'
|
||||
$feature = 'Printing-PrintToPDFServices-Features'
|
||||
Set-Service Spooler -StartupType Manual
|
||||
Start-Service Spooler
|
||||
if (-not (Get-PrinterDriver -Name $driver -ErrorAction SilentlyContinue)) {
|
||||
$current = Get-WindowsOptionalFeature -Online -FeatureName $feature
|
||||
if ($current.State -ne 'Enabled') {
|
||||
$change = Enable-WindowsOptionalFeature -Online -FeatureName $feature -NoRestart
|
||||
if ($change.RestartNeeded) { throw 'The inbox Print to PDF feature requires a restart.' }
|
||||
}
|
||||
if (-not (Get-PrinterDriver -Name $driver -ErrorAction SilentlyContinue)) {
|
||||
Add-PrinterDriver -Name $driver
|
||||
}
|
||||
}
|
||||
$installed = Get-PrinterDriver -Name $driver
|
||||
$installed | Select-Object Name, Manufacturer, MajorVersion |
|
||||
ConvertTo-Json | Write-Output
|
||||
|
||||
$tag = [Guid]::NewGuid().ToString('N')
|
||||
$env:GRIDCRAFT_WINDOWS_PRINT_TEST = $tag
|
||||
$output = New-Item -ItemType Directory -Path (Join-Path $PWD 'gridcraft-windows-paper-output')
|
||||
$queues = @{}
|
||||
$ports = @{}
|
||||
try {
|
||||
foreach ($case in 'a4', 'legal') {
|
||||
$name = "GridCraft QA $tag $case"
|
||||
$port = Join-Path $output.FullName "$case.pdf"
|
||||
if ((Test-Path -LiteralPath $port) -or (Get-Printer -Name $name -ErrorAction SilentlyContinue)) {
|
||||
throw 'The private destination already exists.'
|
||||
}
|
||||
Add-PrinterPort -Name $port
|
||||
$ports[$case] = $port
|
||||
Add-Printer -Name $name -DriverName $driver -PortName $port
|
||||
$queues[$case] = $name
|
||||
$queue = Get-Printer -Name $name
|
||||
if ($queue.PortName -ne $port -or $queue.Shared -or $queue.DriverName -ne $driver) {
|
||||
throw 'The queue is not bound exclusively to the private file port and expected driver.'
|
||||
}
|
||||
Set-PrintConfiguration -PrinterName $name -PaperSize Letter
|
||||
if ((Get-PrintConfiguration -PrinterName $name).PaperSize -ne 'Letter') {
|
||||
throw 'Both private queues must start with Letter as their default.'
|
||||
}
|
||||
if (Get-PrintJob -PrinterName $name) { throw 'The new private queue is not empty.' }
|
||||
}
|
||||
$log = Join-Path $output.FullName 'gridcraft.log'
|
||||
& $Binary --exact print::windows_paper_qa::file_print_switches_windows_stock_and_only_prints_the_visible_worksheet_selection --nocapture |
|
||||
Tee-Object -FilePath $log
|
||||
if ($LASTEXITCODE) { throw "GridCraft native test failed with status $LASTEXITCODE." }
|
||||
foreach ($case in 'a4', 'legal') {
|
||||
if (@(Select-String -LiteralPath $log -Pattern "^WINDOWS_GRIDCRAFT_RECEIPT $case ").Count -ne 1) {
|
||||
throw "Expected exactly one successful native receipt for $case."
|
||||
}
|
||||
$deadline = (Get-Date).AddSeconds(60)
|
||||
do {
|
||||
$file = Get-Item -LiteralPath $ports[$case] -ErrorAction SilentlyContinue
|
||||
if ($file.Length -gt 0 -and -not (Get-PrintJob -PrinterName $queues[$case])) { break }
|
||||
if ((Get-Date) -gt $deadline) { throw "Timed out waiting for $case PDF output." }
|
||||
Start-Sleep -Seconds 1
|
||||
} while ($true)
|
||||
Get-FileHash -LiteralPath $file.FullName | Format-List
|
||||
}
|
||||
} finally {
|
||||
foreach ($name in $queues.Values) {
|
||||
try { Remove-Printer -Name $name } catch { Write-Warning "Could not remove private queue: $_" }
|
||||
}
|
||||
foreach ($path in $ports.Values) {
|
||||
try {
|
||||
$port = Get-PrinterPort | Where-Object Name -eq $path
|
||||
if ($port) { Remove-PrinterPort -InputObject $port }
|
||||
} catch { Write-Warning "Could not remove private file port on disposable runner: $_" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Verify the document printed by Windows, including rendered text."""
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
root = pathlib.Path(sys.argv[1])
|
||||
markers = {"AUTUMN LANTERN", "WINTER ANCHOR", "EXCLUDED ORCHARD"}
|
||||
for case, width, height, expected in (
|
||||
("a4", 595.28, 841.89, "AUTUMN LANTERN"),
|
||||
("legal", 612, 1008, "WINTER ANCHOR"),
|
||||
):
|
||||
pdf = root / f"{case}.pdf"
|
||||
info = subprocess.check_output(["pdfinfo", str(pdf)], text=True)
|
||||
assert re.search(r"^Pages:\s+1$", info, re.M), info
|
||||
size = re.search(r"^Page size:\s+([0-9.]+) x ([0-9.]+) pts", info, re.M)
|
||||
assert size, info
|
||||
actual_width, actual_height = map(float, size.groups())
|
||||
assert abs(actual_width - width) < 1 and abs(actual_height - height) < 1, info
|
||||
text_layer = subprocess.check_output(["pdftotext", "-layout", str(pdf), "-"], text=True)
|
||||
assert " ".join(text_layer.split()) == expected, (case, text_layer)
|
||||
prefix = root / case
|
||||
subprocess.run(["pdftoppm", "-r", "300", "-gray", "-singlefile", "-png", str(pdf), str(prefix)], check=True)
|
||||
text = subprocess.check_output(["tesseract", f"{prefix}.png", "stdout", "--psm", "6"], text=True)
|
||||
(root / f"{case}.ocr.txt").write_text(text, encoding="utf-8")
|
||||
recognized = " ".join(text.upper().split())
|
||||
assert expected in recognized, (case, text)
|
||||
assert not any(other in recognized for other in markers - {expected}), (case, text)
|
||||
print(f"{case}: one {actual_width:g} x {actual_height:g} pt sheet with {expected!r} and no other marker")
|
||||
@@ -0,0 +1,114 @@
|
||||
name: GridCraft Windows queue paper capture
|
||||
on:
|
||||
push:
|
||||
branches: [verify/gridcraft-windows-queue-paper-4859]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
build_run:
|
||||
description: Reuse the compiled test from this run ID
|
||||
required: false
|
||||
build_sha256:
|
||||
description: Expected SHA-256 for a reused test binary
|
||||
required: false
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
env:
|
||||
GRID_FRAMEWORK: 6992dba3069ff7342bb81efb40d657e81ee37ca8
|
||||
CARGO_PROFILE_TEST_DEBUG: '0'
|
||||
CARGO_PROFILE_DEV_DEBUG: '0'
|
||||
CARGO_INCREMENTAL: '0'
|
||||
CRAFT_FONTS_REQUIRED: '1'
|
||||
CRAFT_FONTS_DIR: ${{ github.workspace }}/craft-fonts
|
||||
jobs:
|
||||
build:
|
||||
if: inputs.build_run == ''
|
||||
runs-on: windows-2025
|
||||
timeout-minutes: 90
|
||||
outputs:
|
||||
sha256: ${{ steps.binary.outputs.sha256 }}
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-fonts@58848078cd09e3ca182891a8b76ee979f1eb6e1c
|
||||
with:
|
||||
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
|
||||
- name: Apply exact app framework baseline plus catalog and range code
|
||||
shell: bash
|
||||
run: bash .github/qa/queue-paper-overlay.sh
|
||||
- name: Build the GridCraft Windows binary with the real File Print test
|
||||
id: binary
|
||||
shell: pwsh
|
||||
run: |
|
||||
$buildLog = Join-Path $env:RUNNER_TEMP 'gridcraft-build.jsonl'
|
||||
cargo test --locked -p gridcraft --bin gridcraft --no-run --message-format json > $buildLog
|
||||
if ($LASTEXITCODE) { exit $LASTEXITCODE }
|
||||
$binary = Select-String -LiteralPath $buildLog -SimpleMatch '"executable":"' |
|
||||
ForEach-Object { $_.Line | ConvertFrom-Json } |
|
||||
Where-Object { $_.reason -eq 'compiler-artifact' -and $_.profile.test -and $_.target.name -eq 'gridcraft' } |
|
||||
Select-Object -ExpandProperty executable
|
||||
if (@($binary).Count -ne 1) { throw 'Expected one native GridCraft test binary.' }
|
||||
Copy-Item -LiteralPath $binary -Destination gridcraft-paper-test.exe
|
||||
$sha = (Get-FileHash -LiteralPath gridcraft-paper-test.exe).Hash
|
||||
"sha256=$sha" >> $env:GITHUB_OUTPUT
|
||||
"Native test SHA-256 $sha"
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
|
||||
with:
|
||||
name: gridcraft-windows-paper-test
|
||||
path: gridcraft-paper-test.exe
|
||||
if-no-files-found: error
|
||||
capture:
|
||||
if: always() && (needs.build.result == 'success' || (needs.build.result == 'skipped' && inputs.build_run != ''))
|
||||
needs: build
|
||||
runs-on: windows-2025
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
with:
|
||||
name: gridcraft-windows-paper-test
|
||||
path: native-test
|
||||
github-token: ${{ github.token }}
|
||||
run-id: ${{ inputs.build_run || github.run_id }}
|
||||
- name: Submit from File Print to private Windows PDF queues
|
||||
shell: pwsh
|
||||
env:
|
||||
BUILD_SHA256: ${{ inputs.build_sha256 || needs.build.outputs.sha256 }}
|
||||
run: |
|
||||
$binary = 'native-test/gridcraft-paper-test.exe'
|
||||
if ((Get-FileHash -LiteralPath $binary).Hash -ne $env:BUILD_SHA256) {
|
||||
throw 'The downloaded test binary does not match the recorded SHA-256.'
|
||||
}
|
||||
.github/qa/verify-queue-paper-windows.ps1 -Binary $binary
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
|
||||
if: always()
|
||||
with:
|
||||
name: gridcraft-windows-paper-capture
|
||||
path: gridcraft-windows-paper-output/
|
||||
if-no-files-found: warn
|
||||
verify:
|
||||
needs: capture
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
with:
|
||||
name: gridcraft-windows-paper-capture
|
||||
path: gridcraft-windows-paper-output
|
||||
- uses: storytold/craft-common-actions/actions/install-apt-packages@58848078cd09e3ca182891a8b76ee979f1eb6e1c
|
||||
with:
|
||||
packages: poppler-utils tesseract-ocr
|
||||
- name: Independently measure and render the Windows output
|
||||
run: python3 .github/qa/verify-queue-paper-windows.py gridcraft-windows-paper-output
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
|
||||
if: always()
|
||||
with:
|
||||
name: gridcraft-windows-paper-verified
|
||||
path: gridcraft-windows-paper-output/
|
||||
if-no-files-found: error
|
||||
Generated
+1
@@ -2876,6 +2876,7 @@ dependencies = [
|
||||
"craft-update",
|
||||
"eframe",
|
||||
"egui",
|
||||
"egui_kittest",
|
||||
"fmv-macos-events",
|
||||
"getrandom 0.4.3",
|
||||
"gridcraft-engine",
|
||||
|
||||
@@ -21,6 +21,9 @@ log = { workspace = true }
|
||||
image = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
egui_kittest = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
# Icon + VERSIONINFO for gridcraft.exe; build.rs only uses it when the target is Windows.
|
||||
winresource = "0.1"
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
//! Desktop spooler adapter. Discovery and submission never run on the UI thread.
|
||||
use gridcraft_ui_egui::printing::{Destination, Discover, DiscoverPapers, Duplex, Paper, Printer, Settings, Submit};
|
||||
|
||||
#[cfg(all(test, windows))]
|
||||
mod windows_paper_qa;
|
||||
|
||||
/// Returns a printer-discovery closure that enumerates `craft_print::printers()` on a named background thread and sends the mapped list through a channel.
|
||||
pub fn discover() -> Discover {
|
||||
Box::new(|| {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
//! QA-only native File > Print check using a synthetic workbook and two disposable file queues.
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::{Harness, kittest::Queryable as _};
|
||||
use gridcraft_engine::Session;
|
||||
use gridcraft_ui_egui::{Services, SheetApp};
|
||||
use serde_json::{Value, json};
|
||||
use std::thread::sleep;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
fn until(harness: &mut Harness<'_, SheetApp>, ready: impl Fn(&Value) -> bool) -> Value {
|
||||
let deadline = Instant::now() + Duration::from_secs(60);
|
||||
loop {
|
||||
harness.run_steps(1);
|
||||
let settings = harness.state_mut().run("ui.printSettings", json!({})).unwrap();
|
||||
if ready(&settings) {
|
||||
return settings;
|
||||
}
|
||||
assert!(Instant::now() < deadline, "Print did not reach the expected state: {settings}");
|
||||
sleep(Duration::from_millis(40));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_print_switches_windows_stock_and_only_prints_the_visible_worksheet_selection() {
|
||||
let Ok(tag) = std::env::var("GRIDCRAFT_WINDOWS_PRINT_TEST") else {
|
||||
return;
|
||||
};
|
||||
assert_eq!(tag.len(), 32);
|
||||
assert!(tag.bytes().all(|byte| byte.is_ascii_hexdigit()));
|
||||
let mut session = Session::new();
|
||||
session.new_workbook();
|
||||
let mut app = SheetApp::new(
|
||||
session,
|
||||
Services {
|
||||
printers: Some(super::discover()),
|
||||
printer_papers: Some(super::discover_papers()),
|
||||
print_native: Some(super::submit()),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
for (cell, text) in [("A1", "AUTUMN LANTERN"), ("D4", "WINTER ANCHOR"), ("H20", "EXCLUDED ORCHARD")] {
|
||||
app.run("cell.set", json!({"cell": cell, "input": text})).unwrap();
|
||||
}
|
||||
// Keep each marker inside its own cell. A print selection clips text at its range boundary.
|
||||
for column in ["A:A", "D:D", "H:H"] {
|
||||
app.run("home.columnWidth", json!({"cols":column,"width":200})).unwrap();
|
||||
}
|
||||
app.run("pageLayout.pageSetup", json!({"paper":"Letter","printArea":"F10:H20"})).unwrap();
|
||||
app.run("ui.backstage", json!({"page":"print"})).unwrap();
|
||||
app.run("ui.printSettings", json!({"refresh":true})).unwrap();
|
||||
|
||||
let mut harness = Harness::builder().with_size(egui::vec2(1280.0, 960.0)).build_ui_state(
|
||||
|ui, app: &mut SheetApp| {
|
||||
app.logic(ui.ctx());
|
||||
app.ui(ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
harness.run_steps(4);
|
||||
assert!(harness.query_by_label("Sheet1 · F10:H20").is_some());
|
||||
harness.query_by_label("Print What").or_else(|| harness.query_by_label("Print Active Sheets")).expect("print scope dropdown").click();
|
||||
harness.run_steps(3);
|
||||
harness.get_by_label("Print Selection").click();
|
||||
harness.run_steps(4);
|
||||
|
||||
for (case, width, height, range) in [("a4", 595.28, 841.89, "A1:B2"), ("legal", 612.0, 1008.0, "D4:E5")] {
|
||||
let queue = format!("GridCraft QA {tag} {case}");
|
||||
until(&mut harness, |settings| settings["printers"].as_array().unwrap().iter().any(|printer| printer["name"] == queue));
|
||||
let reset = harness.state_mut().run("ui.printSettings", json!({"printer":queue})).unwrap();
|
||||
assert!(reset["paper"].is_null(), "switching queues resets the previous paper: {reset}");
|
||||
let catalog = until(&mut harness, |settings| settings["papersLoading"] == false && !settings["papers"].as_array().unwrap().is_empty());
|
||||
let paper = catalog["papers"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|paper| (paper["width"].as_f64().unwrap() - width).abs() < 1.0 && (paper["height"].as_f64().unwrap() - height).abs() < 1.0)
|
||||
.expect("the private queue must advertise the stock in real PrintCapabilities");
|
||||
let picked = harness.state_mut().run("ui.printSettings", json!({"paper":paper["id"]})).unwrap();
|
||||
assert_eq!(picked["paper"], paper["id"]);
|
||||
harness.state_mut().run("selection.set", json!({"range":range})).unwrap();
|
||||
harness.run_steps(4);
|
||||
assert!(harness.query_by_label(format!("Sheet1 · {range}").as_str()).is_some());
|
||||
assert!(harness.query_by_label("Sheet1 · F10:H20").is_none());
|
||||
harness.get_all_by_role_and_label(Role::Button, "Print").last().expect("File > Print button").click();
|
||||
let result = until(&mut harness, |settings| matches!(settings["status"].as_str(), Some("submitted" | "failed" | "workerStopped")));
|
||||
assert_eq!(result["status"], "submitted", "{case}: {result}");
|
||||
assert_eq!(result["detail"], "spooled 1 sheet(s)", "{case}: {result}");
|
||||
println!("WINDOWS_GRIDCRAFT_RECEIPT {case} {paper} {}", result["detail"].as_str().unwrap());
|
||||
}
|
||||
let preview = harness.state_mut().run("file.printPreview", json!({})).unwrap();
|
||||
assert_eq!(preview["pageList"][0]["height"], 792.0, "the print overrides left the workbook's saved Letter stock intact");
|
||||
}
|
||||
Reference in New Issue
Block a user