Skip to content

Commit db755ca

Browse files
committed
adding deploy
1 parent ba33452 commit db755ca

2 files changed

Lines changed: 78 additions & 5 deletions

File tree

.github/workflows/sf_cli_integration.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ jobs:
166166
exit 1
167167
}
168168
169+
# ── Script: deploy ───────────────────────────────────────────────────────
170+
171+
- name: '[script] deploy — sf data-code-extension script deploy'
172+
run: |
173+
sf data-code-extension script deploy \
174+
--name test-script-deploy \
175+
--package-version 0.0.1 \
176+
--description "Test script deploy" \
177+
--package-dir testScript/payload \
178+
--cpu-size CPU_2XL \
179+
-o dev1 || {
180+
echo "::error::sf data-code-extension script deploy FAILED. Check mock server output above for which endpoint failed. The deploy command flags or API contract may have changed."
181+
exit 1
182+
}
183+
169184
# ── Function: init ────────────────────────────────────────────────────────
170185

171186
- name: '[function] init — sf data-code-extension function init --package-dir testFunction'
@@ -244,3 +259,18 @@ jobs:
244259
echo "::error::sf data-code-extension function run FAILED. Check mock server output above; the --entrypoint flag or SF CLI org auth contract may have changed."
245260
exit 1
246261
}
262+
263+
# ── Function: deploy ─────────────────────────────────────────────────────
264+
265+
- name: '[function] deploy — sf data-code-extension function deploy'
266+
run: |
267+
sf data-code-extension function deploy \
268+
--name test-function-deploy \
269+
--package-version 0.0.1 \
270+
--description "Test function deploy" \
271+
--package-dir testFunction/payload \
272+
--cpu-size CPU_2XL \
273+
-o dev1 || {
274+
echo "::error::sf data-code-extension function deploy FAILED. Check mock server output above for which endpoint failed. The deploy command flags or API contract may have changed."
275+
exit 1
276+
}

scripts/mock_sf_server.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Minimal mock Salesforce server for CI integration tests.
22
3-
Intercepts the HTTP calls made during ``sf data-code-extension script|function run``
4-
so that neither a real Salesforce org nor real Data Cloud data is required.
3+
Intercepts the HTTP calls made during ``sf data-code-extension script|function``
4+
``run`` and ``deploy`` so that neither a real Salesforce org nor real Data Cloud
5+
data is required.
56
67
Endpoints handled
78
-----------------
@@ -17,6 +18,20 @@
1718
Returns fake rows with the columns expected by the default script template
1819
(Account_std__dll: description__c, sfdcorganizationid__c, kq_id__c).
1920
21+
POST /services/data/v63.0/ssot/data-custom-code
22+
Called by deploy_full() → create_deployment().
23+
Returns a fake fileUploadUrl pointing back at this server.
24+
25+
GET /services/data/v63.0/ssot/data-custom-code/*
26+
Called by deploy_full() → wait_for_deployment() → get_deployments().
27+
Returns deploymentStatus=Deployed immediately so the poll loop exits.
28+
29+
PUT /upload/*
30+
The presigned fileUploadUrl target. Accepts the deployment.zip binary.
31+
32+
POST /services/data/v63.0/ssot/data-transforms
33+
Called by deploy_full() → create_data_transform() for script packages.
34+
2035
GET /* (catch-all)
2136
Returns {"status": "ok"} for any other SF API path the CLI may probe.
2237
@@ -72,6 +87,9 @@
7287
],
7388
}
7489

90+
_DATA_CUSTOM_CODE_PATH = "/services/data/v63.0/ssot/data-custom-code"
91+
_DATA_TRANSFORMS_PATH = "/services/data/v63.0/ssot/data-transforms"
92+
7593

7694
class MockSFHandler(BaseHTTPRequestHandler):
7795
def _send_json(self, payload: object, status: int = 200) -> None:
@@ -82,29 +100,54 @@ def _send_json(self, payload: object, status: int = 200) -> None:
82100
self.end_headers()
83101
self.wfile.write(body)
84102

103+
def _send_empty(self, status: int = 200) -> None:
104+
self.send_response(status)
105+
self.send_header("Content-Length", "0")
106+
self.end_headers()
107+
108+
def _drain_body(self) -> bytes:
109+
length = int(self.headers.get("Content-Length", 0))
110+
return self.rfile.read(length) if length else b""
111+
85112
def log_message(self, fmt: str, *args: object) -> None: # type: ignore[override]
86113
print(f"[MOCK SF] {self.command} {self.path}{fmt % args}", flush=True)
87114

88115
def do_GET(self) -> None:
89116
path = self.path.split("?")[0]
90117
if path == "/services/oauth2/userinfo":
91118
self._send_json(_USERINFO)
119+
elif path.startswith(_DATA_CUSTOM_CODE_PATH + "/"):
120+
# Deployment status poll — report Deployed immediately
121+
self._send_json({"deploymentStatus": "Deployed"})
92122
else:
93123
self._send_json({"status": "ok"})
94124

95125
def do_POST(self) -> None:
96126
path = self.path.split("?")[0]
97-
length = int(self.headers.get("Content-Length", 0))
98-
body = self.rfile.read(length) if length else b""
99-
print(f"[MOCK SF] POST body: {body[:200]!r}", flush=True)
127+
body = self._drain_body()
128+
print(f"[MOCK SF] POST body: {body[:300]!r}", flush=True)
100129

101130
if path == "/services/oauth2/token":
102131
self._send_json(_TOKEN_RESPONSE)
103132
elif path.endswith("/ssot/query-sql"):
133+
# Data Cloud query (run command)
104134
self._send_json(_QUERY_RESPONSE)
135+
elif path == _DATA_CUSTOM_CODE_PATH:
136+
# create_deployment() — return a presigned upload URL
137+
self._send_json(
138+
{"fileUploadUrl": f"http://localhost:{PORT}/upload/fake-deployment.zip"}
139+
)
140+
elif path == _DATA_TRANSFORMS_PATH:
141+
# create_data_transform() — script packages only
142+
self._send_json({"id": "fake-dt-id", "name": "fake-data-transform"})
105143
else:
106144
self._send_json({"status": "ok"})
107145

146+
def do_PUT(self) -> None:
147+
# upload_zip() sends the deployment.zip to the presigned URL
148+
self._drain_body()
149+
self._send_empty(200)
150+
108151

109152
if __name__ == "__main__":
110153
server = HTTPServer(("localhost", PORT), MockSFHandler)

0 commit comments

Comments
 (0)