-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip] add: code submission endpoint #9
base: main
Are you sure you want to change the base?
Changes from 2 commits
5d14f73
bcd7cef
6034998
5a07925
b7cdb3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns codes.clj.contest.submission-runner.ports.http-in.submission) | ||
|
||
(defn submit-code-execution! | ||
[{_submission :parameters | ||
_components :components}] | ||
{:status 201 | ||
:body {:id (random-uuid)}}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(ns codes.clj.contest.submission-runner.wire.in.submission) | ||
|
||
(def Submission | ||
[:map | ||
[:code string?] | ||
[:language [:enum :clojure]] | ||
[:test-cases [:map-of :keyword | ||
[:map | ||
[:input :any] | ||
[:output :any]]]]]) | ||
|
||
(comment | ||
(require '[malli.generator :as m]) | ||
(require '[malli.core :as m.core]) | ||
(m/generate Submission) | ||
(m.core/validate | ||
Submission | ||
{:code "(ns runner | ||
(:require [clojure.test :refer [use-fixtures]]) | ||
(defn my-sum [a b] (+ a b)))" | ||
:language :clojure | ||
:test-cases {:case-1 {:input "(my-sum 1 2)" | ||
:output 3} | ||
:case-2 {:input "(my-sum 2 3)" | ||
:output 5}}}) | ||
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rafaeldelboni what do you think of this input? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this way I will have to merge it, so I think is better to receive it already merged, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who is going to send this payload the frontend? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is use this code + test cases to build the code that will run in the pod right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hm, 🤔 idk why I was thinking of having two backends. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep, the idea was to merge it in some way and send to the pod There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :language could be an enum WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice 👍🏽 |
||
|
||
; | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns codes.clj.contest.submission-runner.wire.out.submission) | ||
|
||
(def SubmissionResult | ||
[:map | ||
[:id uuid?]]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns integration.codes.clj.contest.submission-runner.submission-runner-test | ||
(:require [clojure.test :refer [use-fixtures]] | ||
[integration.codes.clj.contest.submission-runner.util :as util] | ||
[matcher-combinators.matchers :as matchers] | ||
[parenthesin.helpers.malli :as helpers.malli] | ||
[parenthesin.helpers.state-flow.server.pedestal :as state-flow.server] | ||
[state-flow.api :refer [defflow]] | ||
[state-flow.assertions.matcher-combinators :refer [match?]] | ||
[state-flow.core :as state-flow :refer [flow]])) | ||
|
||
(use-fixtures :once helpers.malli/with-intrumentation) | ||
|
||
(defflow | ||
flow-integration-wallet-test | ||
{:init util/start-system! | ||
:cleanup util/stop-system! | ||
:fail-fast? true} | ||
|
||
(flow "should receive an submission" | ||
[:let [submission-input {:code "(ns runner | ||
(:require [clojure.test :refer [use-fixtures]]) | ||
(defn my-sum [a b] (+ a b)))" | ||
:language :clojure | ||
:test-cases {:case-1 {:input "(my-sum 1 2)" | ||
:output 3} | ||
:case-2 {:input "(my-sum 2 3)" | ||
:output 5}}}] | ||
return (state-flow.server/request! {:method :post | ||
:uri "/code/submission" | ||
:body submission-input})] | ||
|
||
(match? (matchers/embeds {:status 201 | ||
:body {:id string?}}) | ||
return))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,38 @@ | ||
(ns integration.codes.clj.contest.submission-runner.util | ||
(:require [com.stuartsierra.component :as component] | ||
(:require [codes.clj.contest.submission-runner.routes :as routes] | ||
[com.stuartsierra.component :as component] | ||
[parenthesin.components.config.aero :as components.config] | ||
[parenthesin.components.db.jdbc-hikari :as components.database] | ||
[parenthesin.components.http.clj-http :as components.http] | ||
[parenthesin.components.router.reitit-malli :as components.router] | ||
[parenthesin.components.server.reitit-pedestal-jetty :as components.webserver] | ||
[parenthesin.helpers.logs :as logs] | ||
[parenthesin.helpers.migrations :as migrations] | ||
[pg-embedded-clj.core :as pg-emb])) | ||
|
||
(defn- create-and-start-components! [] | ||
(component/start-system | ||
(component/system-map | ||
:config (components.config/new-config) | ||
:http (components.http/new-http-mock {}) | ||
:router (components.router/new-router routes/routes) | ||
:database (component/using (components.database/new-database) | ||
[:config]) | ||
:webserver (component/using (components.webserver/new-webserver) | ||
[:config :http :router :database])))) | ||
|
||
(defn start-system! | ||
[system-start-fn] | ||
(fn [] | ||
(logs/setup :info :auto) | ||
(pg-emb/init-pg) | ||
(migrations/migrate (migrations/configuration-with-db)) | ||
(system-start-fn))) | ||
([] | ||
((start-system! create-and-start-components!))) | ||
([system-start-fn] | ||
(fn [] | ||
(logs/setup :info :auto) | ||
(pg-emb/init-pg) | ||
(migrations/migrate (migrations/configuration-with-db)) | ||
(system-start-fn)))) | ||
|
||
(defn stop-system! | ||
[system] | ||
(component/stop-system system) | ||
(pg-emb/halt-pg!)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think even we going to receive this by another backend we need to ensure a bearer token is passed, since this will be accessed by only one service, this could be stored in the configuration files