mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
Exercise a hard print-helper exit through the Windows VectorCraft executable
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,24 @@
|
||||
use vectorcraft_ui_egui::print::{PrintJob, PrintService};
|
||||
|
||||
pub fn run() -> std::process::ExitCode {
|
||||
match simulate() {
|
||||
Ok(report) => {
|
||||
println!("{report}");
|
||||
std::process::ExitCode::SUCCESS
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!("{error}");
|
||||
std::process::ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn simulate() -> Result<serde_json::Value, String> {
|
||||
let mut args = std::env::args_os().skip(2);
|
||||
let mode = args.next().ok_or("missing test mode")?;
|
||||
let pdf = std::fs::read(args.next().ok_or("missing test PDF path")?).map_err(|error| error.to_string())?;
|
||||
let mut service = super::printing::SystemPrint::default();
|
||||
let job = PrintJob { printer: None, title: "VectorCraft receipt probe", pdf: &pdf, paper: Some("QA.NamedForm"), direct_pdf: false };
|
||||
let result = if mode == "shared" { service.shared_print().ok_or("missing desktop printing closure")?(&job) } else { service.print(&job) };
|
||||
Ok(serde_json::json!({ "parent": std::process::id(), "result": result }))
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
app = pathlib.Path(sys.argv[1]).resolve()
|
||||
root = pathlib.Path(sys.argv[2]).resolve()
|
||||
root.mkdir()
|
||||
contents = b'0.1 0.3 0.9 rg 12 30 100 80 re f\n'
|
||||
objects = [
|
||||
b'<< /Type /Catalog /Pages 2 0 R >>',
|
||||
b'<< /Type /Pages /Count 1 /Kids [3 0 R] >>',
|
||||
b'<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << >> /Contents 4 0 R >>',
|
||||
b'<< /Length %d >>\nstream\n' % len(contents) + contents + b'endstream',
|
||||
]
|
||||
fixture = bytearray(b'%PDF-1.4\n')
|
||||
offsets = []
|
||||
for index, data in enumerate(objects, 1):
|
||||
offsets.append(len(fixture))
|
||||
fixture += f'{index} 0 obj\n'.encode() + data + b'\nendobj\n'
|
||||
xref = len(fixture)
|
||||
fixture += b'xref\n0 5\n0000000000 65535 f \n'
|
||||
for offset in offsets:
|
||||
fixture += f'{offset:010} 00000 n \n'.encode()
|
||||
fixture += f'trailer\n<< /Size 5 /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n'.encode()
|
||||
pdf = root / 'source.pdf'
|
||||
pdf.write_bytes(fixture)
|
||||
|
||||
for mode in ('service', 'shared'):
|
||||
child_report = root / f'{mode}-child.jsonl'
|
||||
env = dict(os.environ, VECTOR_PRINT_OBSERVATION_FIXTURE=str(child_report))
|
||||
complete = subprocess.run([app, '--qa-vector-print-receipt', mode, pdf], env=env, capture_output=True, timeout=60)
|
||||
(root / f'{mode}-parent.json').write_bytes(complete.stdout)
|
||||
(root / f'{mode}-stderr.txt').write_bytes(complete.stderr)
|
||||
assert complete.returncode == 0, (mode, complete.returncode, complete.stderr)
|
||||
response = json.loads(complete.stdout)
|
||||
error = response['result']['Err']
|
||||
assert 'queue job 731' in error and 'process exit 0xc0000005' in error and 'final outcome is unknown' in error, error
|
||||
receipts = [json.loads(line) for line in child_report.read_text(encoding='utf-8').splitlines()]
|
||||
child, = receipts
|
||||
assert child['pid'] != response['parent'], child
|
||||
assert child['options'] == [['media', 'QA.NamedForm']], child
|
||||
assert child['copies'] == 1 and child['collate'] and child['duplexDefault'] and child['exact'], child
|
||||
assert child['pdfBytes'] == len(fixture), child
|
||||
print(f'{mode}: app survived, observed job 731 preserved, native exit 0xc0000005 retained, exactly one helper')
|
||||
@@ -0,0 +1,64 @@
|
||||
name: Verify isolated Windows receipts through the VectorCraft application
|
||||
on:
|
||||
push:
|
||||
branches: [verify/vectorcraft-isolated-receipts-4859]
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
app-receipt:
|
||||
runs-on: windows-2025
|
||||
timeout-minutes: 90
|
||||
env:
|
||||
CARGO_PROFILE_DEV_DEBUG: '0'
|
||||
CARGO_PROFILE_DEV_OPT_LEVEL: '0'
|
||||
CARGO_PROFILE_DEV_DEBUG_ASSERTIONS: 'false'
|
||||
CARGO_INCREMENTAL: '0'
|
||||
CARGO_BUILD_JOBS: '2'
|
||||
SHARED_REV: 77ade517ecb2a6ad86feb2f9983a098ad5738fc6
|
||||
WINPRINT_REV: 8ae097ef941b432b0e7671b1ec3a506800e65e57
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Choose an isolated build directory on Windows
|
||||
shell: pwsh
|
||||
run: |
|
||||
$disk = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Free -gt 0 -and $_.Root -match '^[A-Za-z]:\\$' } | Sort-Object -Descending Free | Select-Object -First 1
|
||||
"CARGO_TARGET_DIR=$(Join-Path $disk.Root "vector-print-receipt-$env:GITHUB_RUN_ID")" >> $env:GITHUB_ENV
|
||||
- name: Apply the staged source to the unchanged dependency revisions
|
||||
shell: python
|
||||
run: |
|
||||
import base64, json, os, pathlib, subprocess
|
||||
host = next(line[6:] for line in subprocess.check_output(['rustc', '-vV'], text=True).splitlines() if line.startswith('host: '))
|
||||
home = pathlib.Path(os.environ['RUNNER_TEMP']) / 'vector-receipt-cargo'
|
||||
os.environ['CARGO_HOME'] = str(home)
|
||||
graph = json.loads(subprocess.check_output(['cargo', 'metadata', '--locked', '--format-version', '1', '--filter-platform', host]))
|
||||
for crate, expected, patch_name in (
|
||||
('craft-print', os.environ['SHARED_REV'], 'receipt-shared'),
|
||||
('winprint', os.environ['WINPRINT_REV'], 'receipt-winprint'),
|
||||
):
|
||||
package, = (p for p in graph['packages'] if p['name'] == crate)
|
||||
package_dir = pathlib.Path(package['manifest_path']).parent
|
||||
repo = pathlib.Path(subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], cwd=package_dir, text=True).strip())
|
||||
head = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo, text=True).strip()
|
||||
assert head == expected, (crate, head, expected)
|
||||
patch = base64.b64decode(pathlib.Path(f'.github/qa/{patch_name}.patch.b64').read_bytes())
|
||||
subprocess.run(['git', 'apply', '--check'], cwd=repo, input=patch, check=True)
|
||||
subprocess.run(['git', 'apply'], cwd=repo, input=patch, check=True)
|
||||
with open(home / 'config.toml', 'a', encoding='utf-8') as config:
|
||||
print('\n[profile.dev.package."*"]\nopt-level = 0', file=config)
|
||||
with open(os.environ['GITHUB_ENV'], 'a', encoding='utf-8') as env:
|
||||
print('CARGO_HOME=' + str(home), file=env)
|
||||
subprocess.run(['git', 'diff', '--exit-code', '--', 'Cargo.toml', 'Cargo.lock', 'apps/vectorcraft/Cargo.toml'], check=True)
|
||||
- name: Build and verify both desktop print call paths
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cargo build --locked -p vectorcraft --bin vectorcraft
|
||||
python .github/qa/verify-vectorcraft-receipt.py "$CARGO_TARGET_DIR/debug/vectorcraft.exe" receipt-evidence
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
|
||||
if: always()
|
||||
with:
|
||||
name: vectorcraft-isolated-receipts
|
||||
path: receipt-evidence/
|
||||
if-no-files-found: warn
|
||||
@@ -577,6 +577,10 @@ fn main() -> std::process::ExitCode {
|
||||
if let Some(code) = craft::print::spool::isolated::helper_main() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
#[cfg(windows)]
|
||||
if std::env::args_os().nth(1).as_deref() == Some(std::ffi::OsStr::new("--qa-vector-print-receipt")) {
|
||||
return receipt_probe::run();
|
||||
}
|
||||
// Interactive launches initialize their profile before the update helper, logging, fonts or
|
||||
// saved state. A nightly uses the Launcher's profile or self-isolates. This also handles `--version`.
|
||||
let Some(arguments) = prepare_launch() else { return std::process::ExitCode::SUCCESS };
|
||||
@@ -1120,5 +1124,10 @@ fn main() -> std::process::ExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
mod receipt_probe {
|
||||
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../.github/qa/vectorcraft-receipt-probe.rs"));
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "wgpu"))]
|
||||
mod tests;
|
||||
|
||||
Reference in New Issue
Block a user