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
77 changes: 66 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,15 @@ jobs:
if [[ "$RELEASE_PLATFORM" == "mac" && "$RELEASE_ARCH" == "x64" ]]; then
for manifest in release-publish/*-mac.yml; do mv "$manifest" "${manifest%.yml}-x64.yml"; done
fi
printf '{"platform":"%s","arch":"%s","signed":%s}\n' \
"$RELEASE_PLATFORM" "$RELEASE_ARCH" "$signed" \
# A signed Windows build pins this publisher in the installed app's app-update.yml.
publisher=""
if [[ "$RELEASE_PLATFORM" == "win" && "$signed" == "true" ]]; then
publisher="$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"
fi
jq -cn --arg platform "$RELEASE_PLATFORM" --arg arch "$RELEASE_ARCH" \
--argjson signed "$signed" --arg publisher "$publisher" \
'{platform: $platform, arch: $arch, signed: $signed}
+ (if $publisher == "" then {} else {publisherName: $publisher} end)' \
> "release-publish/signing-$RELEASE_PLATFORM-$RELEASE_ARCH.json"
if [[ "$RELEASE_PLATFORM" == "mac" ]]; then
echo "SCIENT_MAC_SIGNING_READY=$signed" >> "$GITHUB_ENV"
Expand Down Expand Up @@ -1007,9 +1014,37 @@ jobs:
run: |
$attestation = Get-Content verify/signing.json -Raw | ConvertFrom-Json
if ($attestation.platform -ne 'win' -or $attestation.arch -ne 'x64') { throw "Invalid signing attestation target" }
# electron-updater checks each later installer against the publisherName list in the
# installed app's app-update.yml, comparing the signer certificate's CN.
$pinned = @()
$inList = $false
$updateConfig = 'verify/win-unpacked/resources/app-update.yml'
$lines = if (Test-Path $updateConfig) { Get-Content $updateConfig } else { @() }
if ($attestation.signed -and $lines.Count -eq 0) { throw "The signed Windows app has no app-update.yml" }
foreach ($line in $lines) {
if ($line -match '^publisherName:\s*(\S.*)?$') {
$inList = $true
if ($Matches[1]) { $pinned += $Matches[1].Trim().Trim("'").Trim('"') }
continue
}
if ($inList -and $line -match '^\s+-\s+(.+)$') { $pinned += $Matches[1].Trim().Trim("'").Trim('"'); continue }
$inList = $false
}
if ($attestation.signed) {
$expected = [string]$attestation.publisherName
if (-not $expected) { throw "The signed Windows attestation names no publisher" }
if ($pinned.Count -ne 1 -or $pinned[0] -cne $expected) {
throw "The installed app would pin publisher '$($pinned -join "', '")', not the configured '$expected'"
}
$signature = Get-AuthenticodeSignature (Resolve-Path verify/installer.exe)
if ($signature.Status -ne "Valid") { throw "Invalid Windows signature: $($signature.Status)" }
$subject = $signature.SignerCertificate.Subject
if ($subject -notmatch '(?:^|,\s*)CN=("(?:[^"]|"")*"|[^,]+)') { throw "The installer's signer has no CN: $subject" }
$signer = $Matches[1].Trim()
if ($signer.StartsWith('"')) { $signer = $signer.Substring(1, $signer.Length - 2).Replace('""', '"') }
if ($signer -cne $expected) { throw "The installer is signed by '$signer', not the configured publisher '$expected'" }
} elseif ($pinned.Count -gt 0) {
throw "An unsigned Windows build must not pin publisher '$($pinned -join "', '")'"
}

# Needs every target's resource monitor and SyncTeX runtime, not their installers.
Expand Down Expand Up @@ -1163,6 +1198,7 @@ jobs:
shell: bash
env:
ALLOW_UNSIGNED_WINDOWS: ${{ needs.preflight.outputs.allow_unsigned_windows }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
for attestation in release-assets/signing-mac-arm64.json release-assets/signing-mac-x64.json; do
Expand All @@ -1171,16 +1207,16 @@ jobs:
exit 1
}
done
if ! jq -e '.signed == true' release-assets/signing-win-x64.json >/dev/null; then
if [[ "$ALLOW_UNSIGNED_WINDOWS" != "true" ]]; then
echo "Windows publication is unsigned; rerun only with explicit allow_unsigned_windows=true." >&2
exit 1
fi
echo "WARNING: publishing an unsigned Windows installer by explicit release approval."
fi
node scripts/windows-publication-signing.ts \
--attestation release-assets/signing-win-x64.json \
--allow-unsigned "$ALLOW_UNSIGNED_WINDOWS" \
--stable-repository "$SCIENT_DESKTOP_CANONICAL_REPOSITORY" \
--beta-repository "$SCIENT_DESKTOP_BETA_REPOSITORY"
- name: Remove internal build attestations
shell: bash
run: |
# The handoff keeps the Windows signing record for the next publication's gate.
cp release-assets/signing-win-x64.json "$RUNNER_TEMP/signing-win-x64.json"
rm -f release-assets/signing-*.json
rm -f release-assets/builder-debug.yml
- name: Verify complete updater and server artifact set
Expand All @@ -1207,6 +1243,7 @@ jobs:
--channel "$RELEASE_CHANNEL" \
--source-sha "$SOURCE_SHA" \
--source-tree "$SOURCE_TREE" \
--windows-signing "$RUNNER_TEMP/signing-win-x64.json" \
--output "release-assets/scient-release-handoff.json"
- id: release_candidate
name: Upload immutable release candidate
Expand Down Expand Up @@ -1258,6 +1295,10 @@ jobs:
runs-on: ubuntu-24.04
timeout-minutes: 10
environment: ${{ needs.preflight.outputs.channel == 'beta' && 'beta' || 'production' }}
# Both channels share installed Windows publisher pins; hold through public promotion.
concurrency:
group: scient-desktop-stable-beta-publication
cancel-in-progress: false
permissions:
# SCIENT-FORK:START — write lets the stable publish dispatch the hosted app's deploy.
actions: write
Expand All @@ -1280,6 +1321,12 @@ jobs:
run: |
set -euo pipefail
[[ -n "$BETA_TOKEN" ]] || { echo "SCIENT_BETA_RELEASE_TOKEN is required for the isolated artifact repository." >&2; exit 1; }
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
ref: ${{ needs.preflight.outputs.source_sha }}
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version-file: package.json
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: scient-release-v${{ needs.preflight.outputs.version }}
Expand Down Expand Up @@ -1341,6 +1388,7 @@ jobs:
shell: bash
env:
GH_TOKEN: ${{ needs.preflight.outputs.channel == 'beta' && secrets.SCIENT_BETA_RELEASE_TOKEN || github.token }}
PIN_READ_TOKEN: ${{ github.token }}
DISTRIBUTION_REPOSITORY: ${{ needs.preflight.outputs.repository }}
RELEASE_TAG: ${{ needs.preflight.outputs.tag }}
RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
Expand All @@ -1359,7 +1407,7 @@ jobs:
release_args=(--draft --latest=false)
if [[ "$RELEASE_CHANNEL" == "beta" ]]; then
[[ "$DISTRIBUTION_REPOSITORY" == "$SCIENT_DESKTOP_BETA_REPOSITORY" ]] || exit 1
stable_latest_before="$(gh api "repos/$SCIENT_DESKTOP_CANONICAL_REPOSITORY/releases/latest" --jq .tag_name)"
stable_latest_before="$(GH_TOKEN="$PIN_READ_TOKEN" gh api "repos/$SCIENT_DESKTOP_CANONICAL_REPOSITORY/releases/latest" --jq .tag_name)"
jq -ne --arg beta "$RELEASE_VERSION" --arg stable "$stable_latest_before" '
($beta | split("-")[0] | split(".") | map(tonumber)) >
($stable | ltrimstr("v") | split(".") | map(tonumber))
Expand All @@ -1382,10 +1430,17 @@ jobs:
(cd published-assets && sha256sum -- * | sort) > "$RUNNER_TEMP/published-release-sha256.txt"
diff -u "$RUNNER_TEMP/expected-release-sha256.txt" "$RUNNER_TEMP/published-release-sha256.txt"

# Read both public channels with the source token, not Beta's repository-only write token.
GH_TOKEN="$PIN_READ_TOKEN" node scripts/windows-publication-signing.ts \
--candidate-handoff release-assets/scient-release-handoff.json \
--allow-unsigned "$ALLOW_UNSIGNED_WINDOWS" \
--stable-repository "$SCIENT_DESKTOP_CANONICAL_REPOSITORY" \
--beta-repository "$SCIENT_DESKTOP_BETA_REPOSITORY"

if [[ "$RELEASE_CHANNEL" == "beta" ]]; then
gh release edit "$RELEASE_TAG" --repo "$DISTRIBUTION_REPOSITORY" --draft=false --prerelease --latest=false
gh release view "$RELEASE_TAG" --repo "$DISTRIBUTION_REPOSITORY" --json isDraft,isPrerelease | jq -e '.isDraft == false and .isPrerelease == true' >/dev/null
stable_latest_after="$(gh api "repos/$SCIENT_DESKTOP_CANONICAL_REPOSITORY/releases/latest" --jq .tag_name)"
stable_latest_after="$(GH_TOKEN="$PIN_READ_TOKEN" gh api "repos/$SCIENT_DESKTOP_CANONICAL_REPOSITORY/releases/latest" --jq .tag_name)"
[[ "$stable_latest_before" == "$stable_latest_after" ]] || {
echo "Stable Latest changed during Beta publication; investigate before accepting the release." >&2
exit 1
Expand Down
5 changes: 5 additions & 0 deletions UPSTREAM.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ call live in `apps/web/src/scient/desktopUpdate/updateReadyNotice.tsx`; callers
callers; do not reintroduce the confirmation during alignment. A managed policy's feed stays the
update source on every channel. Install-on-quit and early native (Squirrel.Mac) preparation stay
off: they need native-readiness tracking and packaged-build tests first.
Update outcomes and summaries (`app.update.*`, see `docs/internals/product-analytics.md`) live in
`apps/desktop/src/scient/updateOutcomes/`; `DesktopUpdates.ts`, `DesktopTelemetryPublisher.ts`,
`DesktopBackendManager.ts`, `main.ts`, the telemetry contract and `DesktopTelemetryReceiver.ts`
carry only marked calls into them. The four-hour poller contains an unexpected failure per
iteration instead of ending; keep that when aligning upstream's poller.
The update pill shows only this app's own update. Other machines' servers and apps, provider CLIs
and Scient-managed runtimes appear in a Scient-owned circle and card
(`apps/web/src/scient/desktopUpdate/SidebarOtherUpdates.tsx`, `useOtherUpdates.ts`), mounted in
Expand Down
4 changes: 3 additions & 1 deletion apps/desktop/src/backend/DesktopBackendManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,9 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (

const program = runBackendProcess({
...config.value,
desktopTelemetryStream: desktopTelemetryPublisher.encoded,
// SCIENT-FORK: this backend's stream carries the update facts offered to it.
desktopTelemetryStream:
desktopTelemetryPublisher.encodedFor?.(spec.id) ?? desktopTelemetryPublisher.encoded,
desktopBrowserStream: desktopBrowserHost.events,
onDesktopBrowserCommand: desktopBrowserHost.handleCommandLine,
onDesktopTelemetryControl: (message) =>
Expand Down
8 changes: 7 additions & 1 deletion apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import * as DesktopVoice from "./app/DesktopVoice.ts";
// SCIENT-FORK:START — keep the computer awake while threads work.
import * as DesktopKeepAwake from "./scient/keepAwake/DesktopKeepAwake.ts";
// SCIENT-FORK:END
// SCIENT-FORK:START — the update facts journal the updater writes and the telemetry pipe delivers.
import * as DesktopUpdateFacts from "./scient/updateOutcomes/DesktopUpdateFacts.ts";
// SCIENT-FORK:END
import * as ElectronApp from "./electron/ElectronApp.ts";
import * as ElectronDialog from "./electron/ElectronDialog.ts";
import * as ElectronMenu from "./electron/ElectronMenu.ts";
Expand Down Expand Up @@ -198,7 +201,8 @@ const layerDesktopPreview = PreviewManager.layer.pipe(
);

const layerDesktopWindow = DesktopWindow.layer.pipe(
Layer.provideMerge(DesktopTelemetryPublisher.layer),
// SCIENT-FORK: the same journal layer as the updater's, so both share one journal.
Layer.provideMerge(DesktopTelemetryPublisher.layer.pipe(Layer.provide(DesktopUpdateFacts.layer))),
Layer.provideMerge(DesktopShellEnvironment.layer),
Layer.provideMerge(layerDesktopServerExposure),
Layer.provideMerge(layerDesktopPreview),
Expand Down Expand Up @@ -246,6 +250,8 @@ const layerDesktopApplication = Layer.mergeAll(
Layer.provideMerge(
DesktopUpdates.layer.pipe(
Layer.provide(DesktopUpdatePolicy.layer),
// SCIENT-FORK: the same journal layer as the telemetry publisher's.
Layer.provide(DesktopUpdateFacts.layer),
// The same layer as the foundation's, so the policy is still read once.
Layer.provide(DesktopManagedPolicy.layer),
),
Expand Down
183 changes: 183 additions & 0 deletions apps/desktop/src/scient/updateOutcomes/DesktopUpdateFacts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// @effect-diagnostics nodeBuiltinImport:off -- a real temporary journal directory.
import * as NodeFS from "node:fs";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";

import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, describe, it } from "@effect/vitest";
import type { DesktopUpdateFact } from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
import type * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";

import * as DesktopConfig from "../../app/DesktopConfig.ts";
import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
import * as DesktopManagedPolicy from "../../app/DesktopManagedPolicy.ts";
import { PRIMARY_INSTANCE_ID } from "../../backend/DesktopBackendPool.ts";
import * as DesktopUpdateFacts from "./DesktopUpdateFacts.ts";

const WSL_SOURCE = "wsl:Ubuntu";

function journalLayer(home: string) {
const config = DesktopConfig.layerTest({ SCIENT_NEXT_HOME: home });
const environment = DesktopEnvironment.layer({
dirname: "/repo/apps/desktop/src",
homeDirectory: home,
platform: "darwin",
processArch: "arm64",
appVersion: "1.2.3",
appPath: "/repo",
isPackaged: true,
resourcesPath: "/missing/resources",
runningUnderArm64Translation: false,
}).pipe(Layer.provide(Layer.mergeAll(NodeServices.layer, config)));
return DesktopUpdateFacts.layer.pipe(
Layer.provide(
Layer.succeed(DesktopManagedPolicy.DesktopManagedPolicy, {
read: Effect.undefined,
}),
),
Layer.provide(environment),
Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
);
}

/** One desktop process: its journal service, with analytics on or off for that launch. */
function inLaunch<A>(
home: string,
analytics: "true" | "false",
program: (
facts: DesktopUpdateFacts.DesktopUpdateFacts["Service"],
) => Effect.Effect<A, never, Scope.Scope>,
) {
return Effect.scoped(
Effect.gen(function* () {
return yield* program(yield* DesktopUpdateFacts.DesktopUpdateFacts);
}),
).pipe(
Effect.provide(journalLayer(home)),
Effect.provideService(HostProcess.Environment, { SCIENT_ANALYTICS_ENABLED: analytics }),
);
}

/** Collects the next offer each backend receives once `trigger` runs. */
const nextOffers = Effect.fn("test.nextOffers")(function* (
facts: DesktopUpdateFacts.DesktopUpdateFacts["Service"],
trigger: Effect.Effect<void>,
) {
const watch = (sourceId: string) =>
facts.deliveries(sourceId).pipe(Stream.take(1), Stream.runCollect, Effect.forkScoped);
const primary = yield* watch(PRIMARY_INSTANCE_ID);
const wsl = yield* watch(WSL_SOURCE);
yield* Effect.yieldNow;
yield* trigger;
const offered = (yield* Fiber.join(primary)).flat();
// Two backends have two analytics identities: an offer to both would count each fact twice.
yield* Fiber.interrupt(wsl);
assert.isFalse(Exit.isSuccess(yield* Fiber.await(wsl)));
return offered;
});

const ids = (facts: ReadonlyArray<DesktopUpdateFact>) => facts.map((fact) => fact.id);

function temporaryHome(): string {
return NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "scient-update-facts-"));
}

function journalFile(home: string): string {
return NodePath.join(home, "runtime", DesktopUpdateFacts.DESKTOP_UPDATE_FACTS_FILE);
}

describe("DesktopUpdateFacts", () => {
it.effect(
"offers journaled facts to one backend, with the same ids after a restart, until acknowledged",
() =>
Effect.gen(function* () {
const home = temporaryHome();
const recorded = yield* inLaunch(home, "true", (facts) =>
Effect.gen(function* () {
yield* facts.sourceReady(WSL_SOURCE);
return yield* nextOffers(
facts,
Effect.all([
facts.sourceReady(PRIMARY_INSTANCE_ID),
facts.record("app.update.outcome", {
step: "install",
outcome: "handoff-attempted",
}),
]).pipe(Effect.asVoid),
);
}),
);
assert.lengthOf(recorded, 1);

// The app quit before any backend acknowledged; the next launch offers the same events.
const replayed = yield* inLaunch(home, "true", (facts) =>
Effect.gen(function* () {
const offered = yield* nextOffers(facts, facts.sourceReady(PRIMARY_INSTANCE_ID));
yield* facts.acknowledge(ids(offered));
return offered;
}),
);
assert.deepEqual(ids(replayed), ids(recorded));
const journal = JSON.parse(NodeFS.readFileSync(journalFile(home), "utf8")) as {
readonly facts: ReadonlyArray<unknown>;
};
assert.lengthOf(journal.facts, 0);
}),
);

it.effect("never keeps or replays facts when analytics is switched off", () =>
Effect.gen(function* () {
const home = temporaryHome();
yield* inLaunch(home, "true", (facts) =>
facts.record("app.update.outcome", { step: "apply", outcome: "not-applied" }),
);
assert.isTrue(NodeFS.existsSync(journalFile(home)));

yield* inLaunch(home, "false", (facts) =>
facts.record("app.update.outcome", { step: "install", outcome: "handoff-attempted" }),
);
assert.isFalse(NodeFS.existsSync(journalFile(home)));

const offered = yield* inLaunch(home, "true", (facts) =>
nextOffers(
facts,
facts
.sourceReady(PRIMARY_INSTANCE_ID)
.pipe(
Effect.andThen(
facts.record("app.update.summary", { reason: "launch", status: "idle" }),
),
),
),
);
assert.deepEqual(
offered.map((fact) => fact.name),
["app.update.summary"],
);
}),
);

it.effect("counts facts dropped for room in the next summary", () =>
Effect.gen(function* () {
const home = temporaryHome();
const journal = yield* inLaunch(home, "true", (facts) =>
Effect.gen(function* () {
for (let index = 0; index < 66; index += 1) {
yield* facts.record("app.update.outcome", { step: "check", outcome: "completed" });
}
yield* facts.record("app.update.summary", { reason: "daily", status: "up-to-date" });
return yield* nextOffers(facts, facts.sourceReady(PRIMARY_INSTANCE_ID));
}),
);
assert.lengthOf(journal, 64);
assert.equal(journal.at(-1)?.properties.droppedFactCount, 2);
}),
);
});
Loading
Loading