[Duplicate Code] assertGithubCapabilityLifetime duplicated across host-enclave modules

Đang mở Phù hợp với người mới
#11,797 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend, security

Hướng nghiên cứu

Đọc src/cloud-hypervisor/host-enclave-executor-policy.ts và src/cloud-hypervisor/host-enclave-workload-profile.ts, sau đó kiểm tra các bài kiểm thử hiện có cho assertGithubCapabilityLifetime. Gộp phần xác thực bị trùng lặp vào một cách triển khai duy nhất, đồng thời giữ lại các mục xuất cần thiết; chạy các bài kiểm thử liên quan. Công việc hoàn tất khi cả hai mô-đun dùng chung phần kiểm tra và các bài kiểm thử hiện có về thời hạn đều thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
TypeScript
Star
165
Fork
84
Merge trung bình
5 giờ 57 phút
Pull request đã merge (30 ngày)
390

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của github/gh-aw-firewall

Tất cả issue của github/gh-aw-firewall

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.