fn debug_config_output_lists_requirement_sources()

in codex-rs/tui/src/debug_config.rs [616:800]


    fn debug_config_output_lists_requirement_sources() {
        let requirements_file = if cfg!(windows) {
            absolute_path("C:\\ProgramData\\OpenAI\\Codex\\requirements.toml")
        } else {
            absolute_path("/etc/codex/requirements.toml")
        };
        let denied_path = if cfg!(windows) {
            absolute_path("C:\\Users\\alice\\.gitconfig")
        } else {
            absolute_path("/home/alice/.gitconfig")
        };

        let requirements = ConfigRequirements {
            approval_policy: ConstrainedWithSource::new(
                Constrained::allow_any(AskForApproval::OnRequest.to_core()),
                Some(RequirementSource::LegacyManagedConfigTomlFromMdm),
            ),
            approvals_reviewer: ConstrainedWithSource::new(
                Constrained::allow_any(ApprovalsReviewer::AutoReview),
                Some(RequirementSource::LegacyManagedConfigTomlFromMdm),
            ),
            permission_profile: ConstrainedWithSource::new(
                Constrained::allow_any(PermissionProfile::read_only()),
                Some(RequirementSource::SystemRequirementsToml {
                    file: requirements_file.clone(),
                }),
            ),
            mcp_servers: Some(Sourced::new(
                BTreeMap::from([(
                    "docs".to_string(),
                    McpServerRequirement {
                        identity: McpServerIdentity::Command {
                            command: "codex-mcp".to_string(),
                        },
                    },
                )]),
                RequirementSource::LegacyManagedConfigTomlFromMdm,
            )),
            enforce_residency: ConstrainedWithSource::new(
                Constrained::allow_any(Some(ResidencyRequirement::Us)),
                Some(RequirementSource::LegacyManagedConfigTomlFromMdm),
            ),
            web_search_mode: ConstrainedWithSource::new(
                Constrained::allow_any(WebSearchMode::Cached),
                Some(RequirementSource::LegacyManagedConfigTomlFromMdm),
            ),
            allow_managed_hooks_only: Some(Sourced::new(
                /*value*/ true,
                RequirementSource::LegacyManagedConfigTomlFromMdm,
            )),
            allow_appshots: Some(Sourced::new(
                /*value*/ false,
                RequirementSource::LegacyManagedConfigTomlFromMdm,
            )),
            feature_requirements: Some(Sourced::new(
                FeatureRequirementsToml {
                    entries: BTreeMap::from([("guardian_approval".to_string(), true)]),
                },
                RequirementSource::LegacyManagedConfigTomlFromMdm,
            )),
            network: Some(Sourced::new(
                NetworkConstraints {
                    enabled: Some(true),
                    domains: Some(NetworkDomainPermissionsToml {
                        entries: BTreeMap::from([(
                            "example.com".to_string(),
                            NetworkDomainPermissionToml::Allow,
                        )]),
                    }),
                    ..Default::default()
                },
                RequirementSource::LegacyManagedConfigTomlFromMdm,
            )),
            filesystem: Some(Sourced::new(
                FilesystemConstraints {
                    deny_read: vec![denied_path.clone().into()],
                },
                RequirementSource::SystemRequirementsToml {
                    file: requirements_file.clone(),
                },
            )),
            guardian_policy_config_source: Some(RequirementSource::LegacyManagedConfigTomlFromMdm),
            ..ConfigRequirements::default()
        };

        let requirements_toml = ConfigRequirementsToml {
            allowed_approval_policies: Some(vec![AskForApproval::OnRequest.to_core()]),
            allowed_approvals_reviewers: Some(vec![ApprovalsReviewer::AutoReview]),
            allowed_sandbox_modes: Some(vec![SandboxModeRequirement::ReadOnly]),
            allowed_permissions: None,
            remote_sandbox_config: None,
            allowed_web_search_modes: Some(vec![WebSearchModeRequirement::Cached]),
            allow_managed_hooks_only: Some(true),
            allow_appshots: Some(false),
            computer_use: None,
            windows: None,
            guardian_policy_config: Some("Use the managed guardian policy.".to_string()),
            feature_requirements: Some(FeatureRequirementsToml {
                entries: BTreeMap::from([("guardian_approval".to_string(), true)]),
            }),
            hooks: None,
            mcp_servers: Some(BTreeMap::from([(
                "docs".to_string(),
                McpServerRequirement {
                    identity: McpServerIdentity::Command {
                        command: "codex-mcp".to_string(),
                    },
                },
            )])),
            plugins: None,
            apps: None,
            rules: None,
            enforce_residency: Some(ResidencyRequirement::Us),
            network: None,
            permissions: None,
        };

        let user_file = if cfg!(windows) {
            absolute_path("C:\\users\\alice\\.codex\\config.toml")
        } else {
            absolute_path("/home/alice/.codex/config.toml")
        };
        let stack = ConfigLayerStack::new(
            vec![ConfigLayerEntry::new(
                ConfigLayerSource::User {
                    file: user_file,
                    profile: None,
                },
                empty_toml_table(),
            )],
            requirements,
            requirements_toml,
        )
        .expect("config layer stack");

        let rendered = render_to_text(&render_debug_config_lines(&stack));
        let requirements_source = (RequirementSource::LegacyManagedConfigTomlFromMdm).to_string();
        assert!(rendered.contains(&format!(
            "allowed_approval_policies: on-request (source: {requirements_source})"
        )));
        assert!(rendered.contains(
            "allowed_approvals_reviewers: guardian_subagent (source: MDM managed_config.toml (legacy))"
        ));
        assert!(
            rendered.contains(
                format!(
                    "allowed_sandbox_modes: read-only (source: {})",
                    requirements_file.as_path().display()
                )
                .as_str(),
            )
        );
        assert!(rendered.contains(&format!(
            "allowed_web_search_modes: cached, disabled (source: {requirements_source})"
        )));
        assert!(rendered.contains(&format!(
            "allow_managed_hooks_only: true (source: {requirements_source})"
        )));
        assert!(rendered.contains(&format!(
            "allow_appshots: false (source: {requirements_source})"
        )));
        assert!(rendered.contains(&format!(
            "guardian_policy_config: configured (source: {requirements_source})"
        )));
        assert!(rendered.contains(&format!(
            "features: guardian_approval=true (source: {requirements_source})"
        )));
        assert!(rendered.contains("mcp_servers: docs (source: MDM managed_config.toml (legacy))"));
        assert!(rendered.contains(&format!(
            "enforce_residency: us (source: {requirements_source})"
        )));
        assert!(rendered.contains(&format!(
            "experimental_network: enabled=true, domains={{example.com=allow}} (source: {requirements_source})"
        )));
        assert!(
            rendered.contains(
                format!(
                    "permissions.filesystem.deny_read: {}",
                    denied_path.as_path().display()
                )
                .as_str()
            )
        );
        assert!(!rendered.contains("  - rules:"));
    }