[Duplicate Code] assertGithubCapabilityLifetime duplicated across host-enclave modules

Open Beginner friendly
#11,797 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend, security

Research direction

Read src/cloud-hypervisor/host-enclave-executor-policy.ts and src/cloud-hypervisor/host-enclave-workload-profile.ts, then inspect the existing tests for assertGithubCapabilityLifetime. Consolidate the duplicated validation into one implementation while preserving any needed exports; run the relevant tests. Done when both modules use the shared check and the existing lifetime tests pass.

Written by the indexing model from the issue text.

Description

code-quality refactoring

Duplicate Code Opportunity

Summary
  • Pattern: assertGithubCapabilityLifetime(policy, timeoutMs) (GitHub credential/capability lifetime validation for host enclave executors) is defined in two files with identical signature and leading logic (if (!policy) return; const hasCredentials = policy.githubAgentId !== undefined || policy.githubBearer !== undefined;).
  • Locations: see below. jscpd reports a 58-line clone.
  • Impact: ~58 duplicated lines removed. This is a security-critical credential-lifetime check, so the two copies can drift. One copy could then enforce a weaker bound than the other.
Evidence
  • src/cloud-hypervisor/host-enclave-executor-policy.ts: lines 29-86
  • src/cloud-hypervisor/host-enclave-workload-profile.ts: lines 20-77

Both contain:

export function assertGithubCapabilityLifetime(
  policy: HostExecutorAgentPolicy | undefined,
  timeoutMs: number,
): void {
  if (!policy) return;
  const hasCredentials = policy.githubAgentId !== undefined || policy.githubBearer !== undefined;
  ...
Suggested Refactoring

Keep a single exported assertGithubCapabilityLifetime in host-enclave-executor-policy.ts, or in a small shared module such as host-enclave-github-lifetime.ts. Have host-enclave-workload-profile.ts import it, and re-export it if needed to preserve the public API. Keep the existing tests pointed at the single implementation.

Affected Files
  • src/cloud-hypervisor/host-enclave-executor-policy.ts — lines 29-86
  • src/cloud-hypervisor/host-enclave-workload-profile.ts — lines 20-77
Effort Estimate

Low


Detected by Duplicate Code Detector workflow.

Generated by Duplicate Code Detector · copilot · auto (Claude Sonnet 5.5) · ~20 AIC · ⊞ 23.6K · ◷

  • expires on Dec 18, 2026, 9:50 PM UTC
Dominant language
TypeScript
Stars
165
Forks
84
Avg merge
5h 57m
Merged PRs (30d)
390

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/gh-aw-firewall

All issues in github/gh-aw-firewall

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.