Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ci-paths.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tests = [
# Release tooling is covered by unit tests; the packaging and publication workflows are manual.
".github/workflows/desktop-candidate.yml", "scripts/desktop_candidate.py",
".github/workflows/desktop-release.yml", "scripts/desktop_publication_manifest.py",
"scripts/publish_desktop_release.py",
"scripts/publish_desktop_release.py", "scripts/prepare_desktop_product.py",
# These evaluator suites still live under the root tests/ directory.
"evaluation/memory/locomo/**", "evaluation/memory/locomo_plus/**", "evaluation/memory/write_gate/**",
"evaluation/performance/input_encoding/**",
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ jobs:
- run: cargo clippy --locked --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings
- run: cargo test --locked --manifest-path src-tauri/Cargo.toml
- run: pnpm ipc:check
- name: Set up Python for product resource bundle regression
if: matrix.runner == 'macos-15'
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
with:
version: '0.13.5'
enable-cache: true
- name: Verify full-size product resources with the real Tauri CLI
if: matrix.runner == 'macos-15'
working-directory: .
env:
POWERCONTEXT_TEST_TAURI_PRODUCT_BUNDLE: '1'
run: |
uv sync --locked --no-dev --group resource-build --python 3.12
uv run --no-sync python -m pytest tests/test_desktop_product.py::test_tauri_cli_bundles_the_complete_helper_inventory -q
- name: Verify native Keychain across processes
run: cargo run --locked --manifest-path src-tauri/Cargo.toml --example credential_probe
- name: Build unsigned macOS app and DMG
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/skill-guidance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ jobs:
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7
with:
python-version: '3.11'
cache: pip
cache-dependency-path: evaluation/skills/skill-up/requirements-dev.txt
- uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
with:
version: "0.10.12"
- name: Install validation dependencies
run: python -m pip install -r evaluation/skills/skill-up/requirements-dev.txt
run: |
uv venv --python "$(command -v python)" "$RUNNER_TEMP/skill-guidance"
uv pip sync --python "$RUNNER_TEMP/skill-guidance/bin/python" evaluation/skills/skill-up/requirements-dev.txt
echo "$RUNNER_TEMP/skill-guidance/bin" >> "$GITHUB_PATH"
- name: Install checksum-pinned skill-up
shell: bash
run: |
Expand Down
79 changes: 77 additions & 2 deletions desktop/src-tauri/src/ops_bridge/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,81 @@ fn bundle_and_packaged_pins_reject_tampering_and_extra_files() {
Some(OpsBridgeError::IntegrityFailure)
);
}

#[test]
fn packaged_ops_runs_without_a_user_provisioned_bundle_and_rejects_damage() {
let f = Fixture::new();
fs::rename(f.support.join("bundle"), f.resources.join("ops")).unwrap();
let host = f.host();
assert_eq!(host.inspect().outcome, OpsOutcome::Succeeded);
assert!(!f.support.join("bundle").exists());
fs::write(f.resources.join("ops/entry.py"), b"corrupt").unwrap();
assert_eq!(
host.inspect().bridge_error,
Some(OpsBridgeError::IntegrityFailure)
);
}

#[test]
fn damaged_packaged_ops_never_falls_back_to_a_user_bundle() {
let f = Fixture::new();
fs::create_dir(f.resources.join("ops")).unwrap();
assert!(f.host().inspect().bridge_error.is_some());
fs::remove_dir(f.resources.join("ops")).unwrap();
assert_eq!(f.host().inspect().outcome, OpsOutcome::Succeeded);
}

#[test]
fn packaged_ops_repairs_only_its_cache_and_preserves_it_when_app_resources_are_removed() {
let f = Fixture::new();
let original = fs::read(f.support.join("bundle/entry.py")).unwrap();
fs::rename(f.support.join("bundle"), f.resources.join("ops")).unwrap();
let provision: serde_json::Value =
serde_json::from_slice(&fs::read(f.resources.join("ops-provision.json")).unwrap()).unwrap();
let cache = f
.support
.join("bundles")
.join(provision["bundle_manifest_sha256"].as_str().unwrap());
assert_eq!(f.host().inspect().outcome, OpsOutcome::Succeeded);
assert_eq!(fs::read(cache.join("entry.py")).unwrap(), original);
let journal = f.support.join("operator-journal");
fs::write(&journal, b"preserve").unwrap();
fs::write(cache.join("entry.py"), b"damaged").unwrap();
assert_eq!(f.host().inspect().outcome, OpsOutcome::Succeeded);
assert_eq!(fs::read(cache.join("entry.py")).unwrap(), original);
let damaged = fs::read_dir(f.support.join("bundles"))
.unwrap()
.map(|entry| entry.unwrap().path())
.find(|path| {
path.file_name()
.unwrap()
.to_string_lossy()
.starts_with("damaged-")
})
.unwrap();
assert_eq!(fs::read(damaged.join("entry.py")).unwrap(), b"damaged");
fs::remove_dir_all(&f.resources).unwrap();
assert_eq!(fs::read(cache.join("entry.py")).unwrap(), original);
assert_eq!(fs::read(journal).unwrap(), b"preserve");
}

#[test]
fn concurrent_packaged_provisioning_returns_busy_and_can_retry() {
let f = Fixture::new();
fs::rename(f.support.join("bundle"), f.resources.join("ops")).unwrap();
let host = f.host();
assert_eq!(host.inspect().outcome, OpsOutcome::Succeeded);
let lock = fs::OpenOptions::new()
.read(true)
.write(true)
.open(f.support.join("bundles/provision.lock"))
.unwrap();
lock.lock().unwrap();
assert_eq!(host.inspect().bridge_error, Some(OpsBridgeError::Busy));
drop(lock);
assert_eq!(host.inspect().outcome, OpsOutcome::Succeeded);
}

fn child(
script: &str,
deadline: Duration,
Expand Down Expand Up @@ -929,8 +1004,8 @@ fn actual_independent_bundle_runs_through_native_trust_and_read_only_bridge() {
.expect("set externally approved manifest pin");
assert!(trust::is_digest(&pin));
let f = Fixture::new();
let bundle = f.support.join("bundle");
fs::remove_dir_all(&bundle).unwrap();
fs::remove_dir_all(f.support.join("bundle")).unwrap();
let bundle = f.resources.join("ops");
copy(&source, &bundle);
fs::write(
f.resources.join("ops-provision.json"),
Expand Down
65 changes: 64 additions & 1 deletion desktop/src-tauri/src/ops_bridge/trust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,16 @@ impl Trust {
let p = self.provision.as_ref().map_err(|e| *e)?;
let support = self.support.as_ref().ok_or(Error::Unavailable)?;
private_directory(support, true)?;
let root = support.join("bundle");
let packaged = self
.resources
.as_ref()
.ok_or(Error::Unavailable)?
.join("ops");
let root = match fs::symlink_metadata(&packaged) {
Ok(_) => provision_bundle(&packaged, support, &p.bundle_manifest_sha256)?,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => support.join("bundle"),
Err(_) => return Err(Error::Unavailable),
};
let executable = verify_bundle(&root, &p.bundle_manifest_sha256)?;
// Digest-named copies remain immutable across concurrent operations and catalog updates.
let mode = if p.binding_mode == Mode::TargetFile {
Expand Down Expand Up @@ -282,6 +291,60 @@ struct Manifest {
installed_bytes: u64,
files_sha256: BTreeMap<String, String>,
}
// Only the application's pinned helper is copied here; Server installation and
// service mutation remain approved Ops operations. Never overwrite the legacy
// user-provisioned bundle, journals, configuration or Server data.
fn provision_bundle(source: &Path, support: &Path, pin: &str) -> Result<PathBuf, Error> {
verify_bundle(source, pin)?;
let bundles = support.join("bundles");
private_directory(&bundles, true)?;
let lock_path = bundles.join("provision.lock");
no_links(&lock_path)?;
let lock = fs::OpenOptions::new()
.create(true)
.truncate(false)
.read(true)
.write(true)
.open(&lock_path)
.map_err(|_| Error::Storage)?;
security::restrict(&lock_path, false)?;
lock.try_lock().map_err(|error| match error {
std::fs::TryLockError::WouldBlock => Error::Busy,
std::fs::TryLockError::Error(_) => Error::Storage,
})?;
let destination = bundles.join(pin);
if verify_bundle(&destination, pin).is_ok() {
return Ok(destination);
}
let temporary = tempfile::Builder::new()
.prefix("prepare-")
.tempdir_in(&bundles)
.map_err(|_| Error::Storage)?;
security::restrict(temporary.path(), true)?;
let mut files = BTreeSet::new();
inventory(source, source, &mut files)?;
for name in files {
let target = temporary.path().join(relative(&name)?);
if let Some(parent) = target.parent() {
fs::create_dir_all(parent).map_err(|_| Error::Storage)?;
}
fs::copy(source.join(&name), &target).map_err(|_| Error::Storage)?;
}
verify_bundle(temporary.path(), pin)?;
// A broken cache is preserved for diagnosis. A failed copy leaves it intact;
// only a completely verified replacement can move it aside.
if fs::symlink_metadata(&destination).is_ok() {
no_links(&destination)?;
fs::rename(
&destination,
bundles.join(format!("damaged-{}", uuid::Uuid::new_v4())),
)
.map_err(|_| Error::Storage)?;
}
fs::rename(temporary.path(), &destination).map_err(|_| Error::Storage)?;
Ok(destination)
}

fn verify_bundle(root: &Path, pin: &str) -> Result<PathBuf, Error> {
no_links(root)?;
let manifest_bytes = read(&root.join("bundle.json"), MAX_MANIFEST)?;
Expand Down
2 changes: 1 addition & 1 deletion docs/en/development/desktop-candidate-assembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ The checksum binds the exact manifest and asset bytes. Trust still comes from se

CI consumes the real catalog and archive, launches a disposable SQLite Server with bundled Python, and inspects local state with the independent Ops entry. This does not exercise a real HTTP download or register a service. The candidate catalog deliberately uses `candidate.invalid`.

The final platform packagers own signed Windows x64 and signed/notarized macOS arm64/x64 builds and install the approved independent Ops helper at the [fixed current-user location](../docs/operate/local-server-ops.md#provisioning-the-bridge). Desktop removal must preserve the independent helper, service state, and user data. Windows must retain both `pythonw.exe` for the Server service and `python.exe` for console use. The candidate packages embed pins but do not install the independent helper. Provisioning the helper, clean-machine installation and repair, reboot/login and native service lifecycle are part of [#2108](https://github.com/oceanbase/powercontext/issues/2108) and [#2109](https://github.com/oceanbase/powercontext/issues/2109).
Product packagers use [Desktop product resources](desktop-product-resources.md) to embed the independent helper and an approved durable Server catalog. Native code deploys the helper to a private current-user digest directory on first use, preserving it across Desktop removal. The candidate workflow still embeds only pins and requires external provisioning. Windows must retain both `pythonw.exe` for the Server service and `python.exe` for console use. Windows x64 and macOS arm64/x64 signing, clean-machine installation and repair, reboot/login, and native service lifecycle remain acceptance work in [#2108](https://github.com/oceanbase/powercontext/issues/2108) and [#2109](https://github.com/oceanbase/powercontext/issues/2109).

When building the platform release, use the approved immutable resource URL and regenerate any affected inventory, archive, catalog, and provision digest after signing changes nested code. Embed the final pins before signing the outer Desktop package. Preserve the candidate manifest digest and record the separately qualified final package and resource digests; candidate bytes and signed bytes need not be identical. Final acceptance requires the same Desktop/Server combination to demonstrate identity, Scope and Memory, statistics, Runtime observation, and local setup through to the default Scope. Do not substitute a rebuilt wheel or a fixture for [#2101](https://github.com/oceanbase/powercontext/issues/2101) qualification. Publication and re-download verification consume the exact final signed and tested bytes.
52 changes: 52 additions & 0 deletions docs/en/development/desktop-product-resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: Desktop product resources
description: Prepare pinned, redistributable Ops resources and a durable Server download catalog for a product build.
---

# Desktop product resources

The [candidate workflow](desktop-candidate-assembly.md) produces unqualified build artifacts. Product packaging additionally needs an embedded independent Ops runtime and a Server catalog pointing at approved durable downloads. `scripts/prepare_desktop_product.py` prepares these inputs without publishing assets, installing a Server, or claiming platform acceptance.

## Prepare the exact inputs

Use the native target's complete [resource producer output](managed-resource-production.md): `candidate.json`, `server/catalog.json`, `server/server.tar.gz`, and the expanded `ops/` tree. This is the producer's output directory, not the renamed aggregate Desktop artifact. Preserve its provenance and obtain the SHA-256 of `candidate.json` from the trusted producer run. A checksum found beside an untrusted download is not an independent trust source.

Choose a non-`ci-` record already checked into `desktop/src-tauri/src/connections/compatibility.json`. Its Server commit, actual wheel digest, HTTP contract digest, and covered operations must match these resources and the Desktop checkout. If none matches, qualify that exact Server build through [#2101](https://github.com/oceanbase/powercontext/issues/2101) before preparing a product; do not copy a fixture record or relabel an unqualified candidate.

Publish the exact Server archive to an approved immutable HTTPS asset URL before distributed clients use it. Allowlist the initial origin and any approved redirect origins. Temporary signed query URLs, placeholder hosts, Actions artifact downloads, and mutable `latest` routes are unsuitable. The script rejects query URLs and reserved placeholder hosts; release owners still approve the URL's immutability, origin policy, retention, and actual availability. It makes no network request. Ops retains the existing archive size/hash/inventory checks and interrupted-download recovery.

On each native build host, from the repository root:

```sh
uv run --locked --no-dev --group resource-build python scripts/prepare_desktop_product.py \
--resources /absolute/producer-output \
--candidate-sha256 <trusted-producer-candidate-sha256> \
--output /absolute/product-resources \
--version <desktop-X.Y.Z> \
--server-url <approved-immutable-server-archive-https-url> \
--allowed-origin <approved-https-origin> \
--qualification <bundled-product-record-id>
```

Repeat `--allowed-origin` for redirects. Use a fresh output directory each time. The script verifies producer bindings, actual Server archive bytes, the complete Ops tree and executable, target identity, and the exact product qualification. It copies the helper, updates the catalog URL and qualification reference, pins the resulting catalog and Ops manifest, and atomically publishes the staging directory only after verification. Inputs remain unchanged. It emits:

- `ops/`, `server/catalog.json`, and `ops-provision.json` for the application resource directory.
- `tauri.product.conf.json`, with product identity `com.powercontext.desktop`, the selected Desktop version, and a directory mapping that preserves the complete Ops tree, including dotfiles. Keep the staging directory at its original absolute location through the build.
- `product-resources.json`, which records producer/resource bindings and the selected qualification. Signing and installed acceptance are explicitly `not_performed`; this is not a publication manifest.

From `desktop/`, build without `ci-fixtures` or preview features:

```sh
pnpm install --frozen-lockfile
pnpm tauri build --config /absolute/product-resources/tauri.product.conf.json --ci --no-sign -- --locked
```

Tauri automatically applies the checked-in macOS platform configuration. Windows uses the checked-in current-user NSIS configuration. Do not also merge `tauri.ops.conf.json`, which stages only pins for the legacy externally provisioned helper. An unsigned build checks assembly; it does not establish clean-machine installation, service lifecycle, or release qualification. Signing nested code changes hashes: regenerate producer inventories and bindings, stage final resources again, then sign the outer application. [#2108](https://github.com/oceanbase/powercontext/issues/2108) and [#2109](https://github.com/oceanbase/powercontext/issues/2109) own platform acceptance and signing; [#2112](https://github.com/oceanbase/powercontext/issues/2112) owns publication of final tested bytes.

## Runtime deployment and recovery

On first Ops use, native code verifies the application's `ops/` against its packaged manifest pin, then copies it into `PowerContext/Ops/bundles/<manifest-sha256>` under the OS current-user local data directory. It uses a private temporary directory and a cross-process lock, verifies the completed copy, and renames it into place. Concurrent provisioning returns `busy` for retry. The interpreter comes from that verified directory; no globally installed Python or `uv` is needed. Server installation and service changes still require the existing plan/approval flow and installation UI.

A valid matching cache is reused. A damaged cache is moved to `damaged-<uuid>` only after a replacement has passed verification. A damaged packaged resource fails closed, even if an older helper exists: reinstall a trusted Desktop package to repair the source. A package with no `ops/` retains the legacy `PowerContext/Ops/bundle` behavior. An empty or invalid `ops/` never selects that fallback.

Desktop removal must leave the independent helper copies, operation references/journals, Server registration, and user data intact. Old digest directories and damaged copies are retained; this implementation performs no automatic cleanup and does not authorize removal of potentially active versions. This costs one copy per distinct helper version plus any quarantined copies. Every launch reads complete resource inventories, including the packaged source and deployed helper; no startup performance budget or clean-machine qualification is claimed. Existing Ops download, repair, status, cancellation, and resume contracts remain unchanged.
2 changes: 2 additions & 0 deletions docs/en/docs/operate/local-server-ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ validated before exposure. No raw stderr, provider exception, configuration cont

### Provisioning the bridge

Product builds can embed the helper and deploy it automatically to `PowerContext/Ops/bundles/<manifest-sha256>` using [Desktop product resources](../../development/desktop-product-resources.md). The following fixed `bundle` directory is the legacy fallback for packages that omit `ops/`; invalid packaged resources never select it. Both layouts preserve Ops independently of Desktop removal.

A trusted native installer/packager publishes the independent Ops bundle at the fixed current-user location:

- Windows: `%LOCALAPPDATA%\PowerContext\Ops\bundle`.
Expand Down
Loading
Loading