// tools/challenge-spec/scenarios-desktop.ts — Desktop auto-update edge case scenarios
// SPEC-014b: interrupted download, permission issues, version regression, update during close.
import { contentMentions } from './scenarios-utils.js';
/**
 * Generate desktop auto-update edge case scenarios.
 * Covers interrupted download, permission issues, version regression, update during close.
 */
export function generateDesktopAutoUpdateChallenges(_spec, specContent, knowledge) {
    const lower = specContent.toLowerCase();
    const isDesktop = knowledge.projectCategory === 'desktop' ||
        contentMentions(lower, ['electron', 'tauri', 'auto-update', 'autoupdate', 'electron-updater']);
    if (!isDesktop) {
        return [];
    }
    const hasUpdateMention = contentMentions(lower, [
        'update',
        'electron-updater',
        'autoUpdater',
        'tauri updater',
    ]);
    if (!hasUpdateMention) {
        return [];
    }
    const scenarios = [];
    scenarios.push({
        scenario: 'User interrupts update download (kills app mid-download)',
        probability: 'medium',
        impact: 'medium',
        currentHandling: contentMentions(lower, ['resume', 'partial', 'checksum'])
            ? 'Partially addressed in spec'
            : 'Not addressed in spec',
        requiredHandling: 'Implement resumable downloads with byte-range HTTP requests. ' +
            'Store partial download with progress marker. ' +
            'Verify checksum before applying. ' +
            'Clean up partial file if user cancels.',
        dataConsistency: 'Trigger: User force-quits during 40% downloaded update. App must launch normally without applying partial update.',
        userExperience: 'On next launch, offer to resume download or start fresh. Show clear progress.',
    });
    scenarios.push({
        scenario: 'Installer lacks write permissions (e.g., system-wide install vs user install)',
        probability: 'medium',
        impact: 'high',
        currentHandling: contentMentions(lower, ['permission', 'admin', 'elevation', 'uac'])
            ? 'Permissions partially addressed'
            : 'Not addressed',
        requiredHandling: 'Detect permission level before installing. ' +
            'Windows: request UAC elevation for system-wide, or use per-user installation path. ' +
            'macOS: install to ~/Applications if /Applications is read-only. ' +
            'Linux: use user-local AppImage fallback.',
        dataConsistency: 'Trigger: App installed in Program Files (requires admin) but updater runs without elevation.',
        userExperience: 'Show clear error: "Update requires administrator permission. Click here to retry with elevated rights."',
    });
    scenarios.push({
        scenario: 'Server version is older than installed version (rollback scenario)',
        probability: 'low',
        impact: 'high',
        currentHandling: contentMentions(lower, ['version check', 'semver', 'downgrade'])
            ? 'Version comparison mentioned'
            : 'Not addressed',
        requiredHandling: 'Compare semver strictly: server.version <= installed.version → skip update. ' +
            'Log and report version mismatch to monitoring. ' +
            'Never downgrade silently. ' +
            'Add configurable allowDowngrade flag for emergency rollbacks.',
        dataConsistency: 'Trigger: Rollback deployment pushes v1.0.0 while users have v1.1.0 installed. ' +
            'Data format may be forward-compatible only.',
        userExperience: 'Do not notify user about "update" when none is available. Silent version check.',
    });
    scenarios.push({
        scenario: 'User closes app while update is being applied (installer running)',
        probability: 'medium',
        impact: 'critical',
        currentHandling: contentMentions(lower, ['pending', 'restart', 'apply on quit'])
            ? 'Restart handling mentioned'
            : 'Not addressed',
        requiredHandling: 'Defer update application to app quit event. ' +
            'Use electron-updater `autoUpdater.on("update-downloaded")` → install on quit. ' +
            'Prevent force-quit during NSIS/MSI installer phase. ' +
            'On next launch, detect interrupted install and prompt clean reinstall.',
        dataConsistency: 'Trigger: NSIS installer replaces DLLs while app is writing to local database. ' +
            'Half-replaced binaries can corrupt user data.',
        userExperience: 'Show progress overlay during critical install phase. ' +
            'Offer "Update and Restart Now" vs "Update on Next Launch".',
    });
    return scenarios;
}
//# sourceMappingURL=scenarios-desktop.js.map