Skip to content

workspace: fix test registry pollution, rename to managed-projects.json, slug-based entries - #81

Merged
Allann merged 3 commits into
masterfrom
agents/project-directory-calculation-explained
May 15, 2026
Merged

workspace: fix test registry pollution, rename to managed-projects.json, slug-based entries#81
Allann merged 3 commits into
masterfrom
agents/project-directory-calculation-explained

Conversation

@Allann

@Allann Allann commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Problem

Running tests was polluting the real user registry (%LOCALAPPDATA%\AiDevStudio\registry.json) with stale "Demo Project" entries from temp directories. Every call to WorkspaceService.CreateProjectRegisterPath wrote to the production registry file, so repeated test runs accumulated junk entries visible in the WinUI app.

Changes

Core: registry isolation

  • WorkspaceService — added optional string? registryFilePath parameter and EffectiveRegistryFile property. When non-null, all registry reads/writes use this path instead of the global one. Tests pass a temp path; production DI path is unaffected.
  • CoreServiceExtensions.AddAiDevCore — removed ActiveWorkspaceHolder/WorkspacePaths from the shared DI registration (hosts register those themselves); uses an explicit factory for WorkspaceService to avoid DI constructor ambiguity in .NET 10.

Core: registry refactor

  • FilePathConstants — renamed constant to ManagedProjectsFileName = "managed-projects.json"
  • GlobalPathsManagedProjectsFile property replaces RegistryFile; filename is now managed-projects.json
  • WorkspaceRegistryEntry — added Slug property so each entry stores { path, slug }
  • WorkspaceServiceRegisterPathRegisterEntry(path, slug); stores both fields

Tests: full isolation

All test classes now use a temp registry path — no test will ever write to the real user registry:

File Fix
WorkspaceServiceTests IDisposable, temp _registryPath, passed to constructor
ConsistencyCheckServiceTests same pattern
ProductionReadinessIntegrationTests temp registry; assertion updated from GlobalPaths.RegistryFile → temp path
ConsistencyUiAndDetectionIntegrationTests temp registry
ProjectSettingsViewModelTests temp registry, fixed WorkspacePaths root alignment, AgentExecutorName typed properties
DecisionsViewModelTests IAgentInboxService arg, .Value.ShouldBe() for DecisionId, CS4014 fix

WinUI: csproj hygiene

  • Scoped PublishReadyToRun/PublishTrimmed to publish-only targets to avoid spurious build warnings
  • Updated App.xaml.cs to reference GlobalPaths.ManagedProjectsFile

Result

  • ✅ 0 build warnings/errors
  • ✅ All unit, integration, and WinUI tests pass without touching production data

Allann and others added 3 commits May 15, 2026 13:48
…test paths

- Rename registry.json -> managed-projects.json (FilePathConstants, GlobalPaths)
- Add Slug property to WorkspaceRegistryEntry for direct slug lookup
- Add WorkspacePaths-based WorkspaceService constructor with injectable
  registryFilePath so tests never touch the real global registry
- Add CreateProject(slug, name) short overload deriving codebasePath from paths
- RegisterEntry deduplicates by path (OrdinalIgnoreCase) and stores slug
- App.xaml.cs: update RegistryFile -> ManagedProjectsFile reference
- WorkspaceServiceTests: IDisposable cleanup + temp registry path
- ConsistencyCheckServiceTests: temp registry path
- ProductionReadinessIntegrationTests: temp registry, named params for CreateProject
- ConsistencyUiAndDetectionIntegrationTests: temp registry path
- ProjectSettingsViewModelTests: temp registry + explicit codebasePath overload

Fixes stale temp-dir entries accumulating in the real registry from test runs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
DecisionsViewModelTests:
- Id.Value.ShouldBe() to avoid Shouldly IEnumerable<char> ambiguity on DecisionId
- Add missing IAgentInboxService arg to DecisionChatService constructor
- Fix CS4014: capture ShouldNotBeNull() result before await

ProjectSettingsViewModelTests:
- AgentExecutorName.AnthropicValue (string const) -> AgentExecutorName.Anthropic (typed)
  for all ModelDescriptor constructors and GetModelsForExecutor() calls
- Arg.Any<string>() -> Arg.Any<AgentExecutorName>() for IModelRegistry mock setup
- AgentTemplatesService(_paths) -> AgentTemplatesService(_templatesDir) (add _templatesDir field)
- _paths.Root = _rootPath/.ai-dev so CreateProject(codebasePath:_rootPath) aligns with
  what WorkspacePaths expects (paths must match .ai-dev structure)

ai-dev.ui.winui.csproj:
- Scope PublishReadyToRun and PublishTrimmed to actual publish operations only
  (add ' != ''' condition) so building the test project in Release
  doesn't trigger NETSDK1094/NETSDK1102 ILLink errors

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ix DI ambiguity

WorkspaceService had two constructors after the registry refactor, making the
DI container throw 'ambiguous constructors' when both WorkspacePaths and
ActiveWorkspaceHolder were resolvable (both registered by callers + AddAiDevCore).

Fixes:
- Remove ActiveWorkspaceHolder and WorkspacePaths registrations from AddAiDevCore
  (callers own these registrations, as they did before the refactor)
- Merge WorkspaceService into a single constructor:
  WorkspaceService(WorkspacePaths, AtomicFileWriter, ActiveWorkspaceHolder? = null,
  string? registryFilePath = null, ILogger? = null)
- Register WorkspaceService via explicit factory in AddAiDevCore, using
  GetRequiredService<WorkspacePaths> and GetService<ActiveWorkspaceHolder>
  (null in API context; real holder in WinUI context)

All tests now pass (625 unit + 60 integration + 10 WinUI) and registry.json
is never modified by any test run.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Allann
Allann requested a review from auleewilliams May 15, 2026 07:22
@Allann
Allann merged commit 005a564 into master May 15, 2026
1 check passed
@Allann
Allann deleted the agents/project-directory-calculation-explained branch May 15, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants