import json
from http.server import BaseHTTPRequestHandler,HTTPServer
U='http://127.0.0.1:18765/DefaultCollection'
project={'id':'11111111-1111-1111-1111-111111111111','name':'proj','url':U+'/_apis/projects/11111111-1111-1111-1111-111111111111','state':'wellFormed','visibility':'private'}
repo={'id':'22222222-2222-2222-2222-222222222222','name':'repo','project':project,'remoteUrl':U+'/proj/_git/repo','url':U+'/_apis/git/repositories/repo'}
locations=[('603fe2ac-9723-48b9-88ad-09305aa6c6e1','projects','_apis/projects/{projectId}'),('a5d28130-9cd2-40fa-9f08-902e7daa9efb','pullRequests','{project}/_apis/git/pullRequests'),('225f7195-f9c7-4d14-ab28-a83f7ff77e1f','repositories','{project}/_apis/git/repositories/{repositoryId}'),('e81700f7-3be2-46de-8624-2eb35882fcaa','connectionData','_apis/connectionData'),('e81700f7-3be2-46de-8624-2eb35882fcaa','resourceAreas','_apis/resourceAreas/{areaId}')]
class H(BaseHTTPRequestHandler):
 def do_OPTIONS(self): self.reply({'count':len(locations),'value':[{'id':i,'area':'git' if 'git' in r else 'core','resourceName':n,'routeTemplate':r,'resourceVersion':1,'minVersion':'1.0','maxVersion':'7.0','releasedVersion':'7.0'} for i,n,r in locations]})
 def do_GET(self):
  p=self.path.lower()
  if 'connectiondata' in p: data={'deploymentType':'onPremises','instanceId':'33333333-3333-3333-3333-333333333333','authenticatedUser':{'id':'44444444-4444-4444-4444-444444444444','providerDisplayName':'Synthetic user'},'locationServiceData':{'serviceOwner':'00000000-0000-0000-0000-000000000000','accessMappings':[]}}
  elif 'resourceareas' in p: data={'count':2,'value':[{'id':i,'name':n,'locationUrl':U} for i,n in [('79134c72-4a58-4b42-976c-04e7115f32bf','core'),('4e080c62-fa21-4fbc-8f8f-7f0eb7f37f9f','git')]]}
  elif 'pullrequests' in p: data={'count':1,'value':[{'pullRequestId':7,'title':'On-prem stub PR','status':'active','repository':repo,'sourceRefName':'refs/heads/topic','targetRefName':'refs/heads/main','createdBy':{'displayName':'Synthetic user'},'creationDate':'2026-01-01T00:00:00Z'}]}
  elif 'repositories' in p: data={'count':1,'value':[repo]}
  elif 'projects' in p: data={'count':1,'value':[project]}
  else: data={}
  self.reply(data)
 def reply(self,data):
  b=json.dumps(data).encode(); self.send_response(200);self.send_header('Content-Type','application/json');self.send_header('Content-Length',str(len(b)));self.end_headers();self.wfile.write(b)
HTTPServer(('127.0.0.1',18765),H).serve_forever()
