Program: 53199
Project: 53199
Buggy source:
@Test public void inputBasedRuleKeyCacheHitAvoidsBuildingLocally() throws Exception {
  FakeProjectFilesystem filesystem=new FakeProjectFilesystem();
  InMemoryArtifactCache cache=new InMemoryArtifactCache();
  BuildContext buildContext=FakeBuildContext.newBuilder(filesystem).setArtifactCache(cache).setJavaPackageFinder(new FakeJavaPackageFinder()).setActionGraph(new ActionGraph(ImmutableList.<BuildRule>of())).build();
  BuildTarget target=BuildTargetFactory.newInstance("String_Node_Str");
  RuleKey inputRuleKey=new RuleKey("String_Node_Str");
  BuildRuleParams params=new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(filesystem).build();
  BuildRuleResolver resolver=new BuildRuleResolver();
  SourcePathResolver pathResolver=new SourcePathResolver(resolver);
  final Path output=Paths.get("String_Node_Str");
  BuildRule rule=new InputRuleKeyBuildRule(params,pathResolver){
    @Override public ImmutableList<Step> getBuildSteps(    BuildContext context,    BuildableContext buildableContext){
      return ImmutableList.<Step>of(new AbstractExecutionStep("String_Node_Str"){
        @Override public int execute(        ExecutionContext context){
          return 1;
        }
      }
);
    }
    @Override public Path getPathToOutput(){
      return output;
    }
  }
;
  File temp=File.createTempFile("String_Node_Str","String_Node_Str");
  writeEntriesToZip(temp,ImmutableMap.of(BuildInfo.getPathToMetadataDirectory(target).resolve(BuildInfo.METADATA_KEY_FOR_RULE_KEY).toString(),new RuleKey("String_Node_Str").toString(),BuildInfo.getPathToMetadataDirectory(target).resolve(BuildInfo.METADATA_KEY_FOR_INPUT_BASED_RULE_KEY).toString(),inputRuleKey.toString(),output.toString(),"String_Node_Str"));
  cache.store(ImmutableSet.of(inputRuleKey),ImmutableMap.<String,String>of(),temp);
  CachingBuildEngine cachingBuildEngine=new CachingBuildEngine(MoreExecutors.newDirectExecutorService(),CachingBuildEngine.BuildMode.SHALLOW,new FixedRuleKeyBuilderFactory(ImmutableMap.of(rule.getBuildTarget(),inputRuleKey)));
  BuildResult result=cachingBuildEngine.build(buildContext,rule).get();
  assertEquals(BuildRuleSuccessType.FETCHED_FROM_CACHE_INPUT_BASED,result.getSuccess());
  OnDiskBuildInfo onDiskBuildInfo=buildContext.createOnDiskBuildInfoFor(target);
  assertThat(onDiskBuildInfo.getRuleKey(BuildInfo.METADATA_KEY_FOR_RULE_KEY),Matchers.equalTo(Optional.of(rule.getRuleKey())));
  assertThat(onDiskBuildInfo.getRuleKey(BuildInfo.METADATA_KEY_FOR_INPUT_BASED_RULE_KEY),Matchers.equalTo(Optional.of(inputRuleKey)));
}

Fixed version (ground truth):
@Test public void inputBasedRuleKeyCacheHitAvoidsBuildingLocally() throws Exception {
  FakeProjectFilesystem filesystem=new FakeProjectFilesystem();
  InMemoryArtifactCache cache=new InMemoryArtifactCache();
  BuildContext buildContext=FakeBuildContext.newBuilder(filesystem).setArtifactCache(cache).setJavaPackageFinder(new FakeJavaPackageFinder()).setActionGraph(new ActionGraph(ImmutableList.<BuildRule>of())).build();
  BuildTarget target=BuildTargetFactory.newInstance("String_Node_Str");
  RuleKey inputRuleKey=new RuleKey("String_Node_Str");
  BuildRuleParams params=new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(filesystem).build();
  BuildRuleResolver resolver=new BuildRuleResolver();
  SourcePathResolver pathResolver=new SourcePathResolver(resolver);
  final Path output=Paths.get("String_Node_Str");
  BuildRule rule=new InputRuleKeyBuildRule(params,pathResolver){
    @Override public ImmutableList<Step> getBuildSteps(    BuildContext context,    BuildableContext buildableContext){
      return ImmutableList.<Step>of(new AbstractExecutionStep("String_Node_Str"){
        @Override public int execute(        ExecutionContext context){
          return 1;
        }
      }
);
    }
    @Override public Path getPathToOutput(){
      return output;
    }
  }
;
  File artifact=tmp.newFile("String_Node_Str");
  writeEntriesToZip(artifact,ImmutableMap.of(output.toString(),"String_Node_Str"));
  cache.store(ImmutableSet.of(inputRuleKey),ImmutableMap.of(BuildInfo.METADATA_KEY_FOR_RULE_KEY,new RuleKey("String_Node_Str").toString(),BuildInfo.METADATA_KEY_FOR_INPUT_BASED_RULE_KEY,inputRuleKey.toString()),artifact);
  CachingBuildEngine cachingBuildEngine=new CachingBuildEngine(MoreExecutors.newDirectExecutorService(),CachingBuildEngine.BuildMode.SHALLOW,new FixedRuleKeyBuilderFactory(ImmutableMap.of(rule.getBuildTarget(),inputRuleKey)));
  BuildResult result=cachingBuildEngine.build(buildContext,rule).get();
  assertEquals(BuildRuleSuccessType.FETCHED_FROM_CACHE_INPUT_BASED,result.getSuccess());
  OnDiskBuildInfo onDiskBuildInfo=buildContext.createOnDiskBuildInfoFor(target);
  assertThat(onDiskBuildInfo.getRuleKey(BuildInfo.METADATA_KEY_FOR_RULE_KEY),Matchers.equalTo(Optional.of(rule.getRuleKey())));
  assertThat(onDiskBuildInfo.getRuleKey(BuildInfo.METADATA_KEY_FOR_INPUT_BASED_RULE_KEY),Matchers.equalTo(Optional.of(inputRuleKey)));
  File fetchedArtifact=tmp.newFile("String_Node_Str");
  assertThat(cache.fetch(rule.getRuleKey(),fetchedArtifact).getType(),Matchers.equalTo(CacheResult.Type.HIT));
  assertEquals(new ZipInspector(artifact).getZipFileEntries(),new ZipInspector(fetchedArtifact).getZipFileEntries());
  assertTrue(Files.equal(artifact,fetchedArtifact));
}