test(artifacts): restore publishing permission regression tests

#41012 and #41007 removed the tests that guard #40948 (new profiles allow
artifact publishing, profiles saved before the setting stay off, web clients
fail closed until the host grant is mirrored) and #40982 (moving a project
between profiles must not grant publishing to an older profile). Restore them
against current paths. Each fails when the code it guards is reverted.
This commit is contained in:
Jinjing
2026-11-11 20:00:35 -08:00
parent 3f84308ec1
commit 42bcfa338a
3 changed files with 124 additions and 0 deletions
@@ -66,6 +66,15 @@ async function loadTransferModule() {
return import('./profile-project-transfer')
}
function transferMove(
transfer: Awaited<ReturnType<typeof loadTransferModule>>['transferOrcaProfileProject']
) {
return transfer(
{ sourceProfileId: 'personal', targetProfileId: 'work', repoId: 'repo-1', mode: 'move' },
testState.dir
)
}
function profile(id: string, name: string): OrcaProfileIndex['profiles'][number] {
return {
id,
@@ -135,6 +144,22 @@ function makeState(overrides: Partial<PersistedState> = {}): PersistedState {
}
}
// A profile saved before artifactSharingEnabled existed carries no defaults for it.
function writeOlderProfileStateDatabase(
profileId: string,
settings: Record<string, unknown>,
repos: Repo[] = []
): void {
const databasePath = profileDatabasePath(profileId)
mkdirSync(join(databasePath, '..'), { recursive: true })
const opened = openProfileStateDatabase(databasePath, profileId)
try {
importProfileStateJson(opened.db, JSON.stringify({ settings, repos }))
} finally {
opened.db.close()
}
}
describe('profile project transfer', () => {
beforeEach(() => {
testState.dir = mkdtempSync(join(tmpdir(), 'orca-profile-transfer-'))
@@ -200,4 +225,26 @@ describe('profile project transfer', () => {
expect(readProfileStateDatabase('personal').repos).toHaveLength(1)
expect(existsSync(intentPath)).toBe(true)
})
it('moves a project without granting publishing permission to either older profile', async () => {
writeOlderProfileStateDatabase('personal', {}, [makeRepo()])
writeOlderProfileStateDatabase('work', {})
const { transferOrcaProfileProject } = await loadTransferModule()
expect(transferMove(transferOrcaProfileProject)).toMatchObject({ status: 'transferred' })
expect(readProfileStateDatabase('personal').settings).not.toHaveProperty(
'artifactSharingEnabled'
)
expect(readProfileStateDatabase('work').settings).not.toHaveProperty('artifactSharingEnabled')
})
it('keeps explicit publishing choices when moving a project', async () => {
writeOlderProfileStateDatabase('personal', { artifactSharingEnabled: true }, [makeRepo()])
writeOlderProfileStateDatabase('work', { artifactSharingEnabled: false })
const { transferOrcaProfileProject } = await loadTransferModule()
expect(transferMove(transferOrcaProfileProject)).toMatchObject({ status: 'transferred' })
expect(readProfileStateDatabase('personal').settings.artifactSharingEnabled).toBe(true)
expect(readProfileStateDatabase('work').settings.artifactSharingEnabled).toBe(false)
})
})
@@ -0,0 +1,59 @@
import { closeTestStores, testState, createStore, writeDataFile } from '../persistence-test-harness'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { rmSync, mkdtempSync } from 'node:fs'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
vi.mock('electron', () => ({
app: { getPath: () => testState.dir },
safeStorage: {
isEncryptionAvailable: () => true,
encryptString: (plaintext: string) => Buffer.from(`encrypted:${plaintext}`, 'utf-8'),
decryptString: (ciphertext: Buffer) => ciphertext.toString('utf-8').slice('encrypted:'.length)
}
}))
vi.mock('../../telemetry/client', () => ({ track: vi.fn() }))
vi.mock('../../telemetry/cohort-classifier', () => ({
getCohortAtEmit: () => ({ nth_repo_added: 2 })
}))
function writeSettings(settings: Record<string, unknown>): void {
writeDataFile({
schemaVersion: 1,
repos: [],
worktreeMeta: {},
settings,
ui: {},
githubCache: { pr: {}, issue: {} },
workspaceSession: {}
})
}
describe('artifact sharing default', () => {
beforeEach(() => {
testState.dir = mkdtempSync(join(tmpdir(), 'orca-test-'))
})
afterEach(async () => {
await closeTestStores()
rmSync(testState.dir, { recursive: true, force: true })
})
it('allows publishing on a new profile and keeps it after a reload', async () => {
const store = createStore()
expect(store.getSettings().artifactSharingEnabled).toBe(true)
store.flush()
await closeTestStores()
expect(createStore().getSettings().artifactSharingEnabled).toBe(true)
})
it('keeps a stored opt-out', () => {
writeSettings({ artifactSharingEnabled: false })
expect(createStore().getSettings().artifactSharingEnabled).toBe(false)
})
it('keeps publishing off for a stored profile saved before the setting existed', () => {
writeSettings({ showArtifactsButton: false })
expect(createStore().getSettings().artifactSharingEnabled).toBe(false)
})
})
@@ -0,0 +1,18 @@
// @vitest-environment happy-dom
import { beforeEach, expect, it, vi } from 'vitest'
import { getStoredSettings } from './web-preferences-store'
import { SETTINGS_STORAGE_KEY } from './web-storage'
vi.mock('./web-runtime-session', () => ({
webRuntimeState: { activeEnvironment: null },
requireActiveEnvironmentOrNull: () => null
}))
beforeEach(() => localStorage.clear())
it('reports publishing off until the host grant has been mirrored', () => {
expect(getStoredSettings().artifactSharingEnabled).toBe(false)
localStorage.setItem(SETTINGS_STORAGE_KEY, JSON.stringify({ artifactSharingEnabled: true }))
expect(getStoredSettings().artifactSharingEnabled).toBe(true)
})