// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
namespace Foundry.Hosting.IntegrationTests.Fixtures;
///
/// Provisions a hosted agent that runs the test container in IT_SCENARIO=toolbox-oauth-consent
/// mode. The container pre-registers a Foundry toolbox (named by IT_TOOLBOX_NAME) whose tool
/// source is fronted by a per-user OAuth connection. The first request that needs the tool must
/// surface an oauth_consent_request instead of running it.
///
///
/// Prerequisite (out of band, per project): a Foundry toolbox named by must
/// exist in the target project and reference a tool source that returns CONSENT_REQUIRED for an
/// unconsented user (for example a delegated GitHub or Microsoft Graph connection). Override the
/// toolbox name with the IT_TOOLBOX_NAME environment variable. See the project README.
///
public sealed class ToolboxOAuthConsentHostedAgentFixture : HostedAgentFixture
{
private const string ToolboxNameEnvironmentVariable = "IT_TOOLBOX_NAME";
private const string DefaultToolboxName = "auth-paths-oauth-toolbox";
protected override string ScenarioName => "toolbox-oauth-consent";
///
/// The Foundry toolbox the container pre-registers. Resolved from IT_TOOLBOX_NAME, falling
/// back to a default that exists in the reference project.
///
public string ToolboxName { get; } =
Environment.GetEnvironmentVariable(ToolboxNameEnvironmentVariable) ?? DefaultToolboxName;
protected override void ConfigureEnvironment(IDictionary environment)
{
// Pass the toolbox name into the container so Program.cs wires AddFoundryToolboxes(credential, name).
// IT_TOOLBOX_NAME is a non-reserved key (FOUNDRY_*/AGENT_* are forbidden by the platform).
environment[ToolboxNameEnvironmentVariable] = this.ToolboxName;
}
}