# Copyright 2026 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Mock BUILD.gn for testing.

# Template to strip workflow comments from test files and rename them on copy
# to prevent the agent from anchoring on filenames that indicate the flaw.
template("strip_workflow") {
  action(target_name) {
    testonly = true
    script = "strip_workflow_comments.py"
    inputs = [ invoker.source ]
    outputs = [ invoker.output ]
    args = [
      "--input",
      rebase_path(invoker.source, root_build_dir),
      "--output",
      rebase_path(invoker.output, root_build_dir),
    ]
  }
}

# CC Files
strip_workflow("strip_sample_ipc") {
  source = "sample_ipc.cc.workflow.test"
  output = "$target_gen_dir/sample_ipc.cc"
}

strip_workflow("strip_unsafe_threading") {
  source = "unsafe_threading.cc.workflow.test"
  output = "$target_gen_dir/thread_safe_manager.cc"
}

strip_workflow("strip_unsafe_casting") {
  source = "unsafe_casting.cc.workflow.test"
  output = "$target_gen_dir/type_converter.cc"
}

strip_workflow("strip_complex_uaf") {
  source = "complex_uaf.cc.workflow.test"
  output = "$target_gen_dir/bind_post_task_helper.cc"
}

strip_workflow("strip_win_handle_leak") {
  source = "win_handle_leak.cc.workflow.test"
  output = "$target_gen_dir/file_manager_win.cc"
}

strip_workflow("strip_mac_retain_cycle") {
  source = "mac_retain_cycle.mm.workflow.test"
  output = "$target_gen_dir/notification_delegate.mm"
}

strip_workflow("strip_linux_fd_leak") {
  source = "linux_fd_leak.cc.workflow.test"
  output = "$target_gen_dir/socket_handler_linux.cc"
}

strip_workflow("strip_mock_helper_unittest") {
  source = "tautological_assert_test.cc.workflow.test"
  output = "$target_gen_dir/mock_helper_unittest.cc"
}

# H Files
strip_workflow("strip_unsafe_threading_h") {
  source = "unsafe_threading.h.workflow.test"
  output = "$target_gen_dir/thread_safe_manager.h"
}

strip_workflow("strip_unsafe_casting_h") {
  source = "unsafe_casting.h.workflow.test"
  output = "$target_gen_dir/type_converter.h"
}

strip_workflow("strip_complex_uaf_h") {
  source = "complex_uaf.h.workflow.test"
  output = "$target_gen_dir/bind_post_task_helper.h"
}

strip_workflow("strip_win_handle_leak_h") {
  source = "win_handle_leak.h.workflow.test"
  output = "$target_gen_dir/file_manager_win.h"
}

strip_workflow("strip_mac_retain_cycle_h") {
  source = "mac_retain_cycle.h.workflow.test"
  output = "$target_gen_dir/notification_delegate.h"
}

strip_workflow("strip_linux_fd_leak_h") {
  source = "linux_fd_leak.h.workflow.test"
  output = "$target_gen_dir/socket_handler_linux.h"
}

source_set("test_target") {
  testonly = true
  sources = [ "file1.cc" ]

  sources += [
    "$target_gen_dir/bind_post_task_helper.cc",
    "$target_gen_dir/mock_helper_unittest.cc",
    "$target_gen_dir/sample_ipc.cc",
    "$target_gen_dir/thread_safe_manager.cc",
    "$target_gen_dir/type_converter.cc",
  ]

  if (is_win) {
    sources += [ "$target_gen_dir/file_manager_win.cc" ]
  }
  if (is_linux) {
    sources += [ "$target_gen_dir/socket_handler_linux.cc" ]
  }
  if (is_mac) {
    sources += [ "$target_gen_dir/notification_delegate.mm" ]
  }

  deps = [
    ":strip_complex_uaf",
    ":strip_linux_fd_leak",
    ":strip_mac_retain_cycle",
    ":strip_mock_helper_unittest",
    ":strip_sample_ipc",
    ":strip_unsafe_casting",
    ":strip_unsafe_threading",
    ":strip_win_handle_leak",
    "//base",
    "//testing/gtest",
  ]

  public_deps = [
    ":strip_complex_uaf_h",
    ":strip_linux_fd_leak_h",
    ":strip_mac_retain_cycle_h",
    ":strip_unsafe_casting_h",
    ":strip_unsafe_threading_h",
    ":strip_win_handle_leak_h",
  ]
}

executable("mock_app") {
  testonly = true
  sources = [ "mock_app.cc" ]
  deps = [
    ":test_target",
    "//base",
  ]
  include_dirs = [ target_gen_dir ]
}
